• R/O
  • SSH
  • HTTPS

shibuya-trac: コミット


コミットメタ情報

リビジョン874 (tree)
日時2015-04-30 00:01:58
作者jun66j5

ログメッセージ

MailArchiveExt: fixed AttributeErrors from environment_needs_upgrade() with Trac 1.0

変更サマリ

差分

--- plugins/mailarchiveplugin/branches/mailarchiveext/0.12/mailarchive/env.py (revision 873)
+++ plugins/mailarchiveplugin/branches/mailarchiveext/0.12/mailarchive/env.py (revision 874)
@@ -150,36 +150,17 @@
150150 import traceback
151151 traceback.print_exc(e)
152152 db.rollback()
153-
153+
154154 def is_no_table(self, db):
155155 # check for database table
156- cursor = db.cursor()
157- try:
158- cursor.execute("SELECT id FROM mailarc WHERE id='1'")
159- cursor.execute("SELECT category FROM mailarc_category WHERE category='1'")
160- except Exception, e:
161-# import traceback
162-# traceback.print_exc(e)
163- return True
164- return False
165-
156+ tables = set(self.get_table_names(db))
157+ return 'mailarc' not in tables or 'mailarc_category' not in tables
158+
166159 def is_old_schema(self, db):
167- cursor = db.cursor()
168- try:
169- cursor.execute("INSERT INTO mailarc ("
170- "category, messageid) "
171- "VALUES (%s,%s)", ('testcategory', 'testid'))
172- cursor.execute("SELECT id from mailarc WHERE messageid = 'testid'")
173- id = cursor.fetchone()[0]
174- if id is None:
175- db.rollback()
176- return True
177- except :
178- db.rollback()
179- return True
180-
181- db.rollback()
182- return False
160+ columns = set(self.get_column_names(db, 'mailarc'))
161+ return 'id' not in columns or \
162+ 'category' not in columns or \
163+ 'messageid' not in columns
183164
184165 def create_table(self, db, table):
185166 db_connector, _ = DatabaseManager(self.env)._get_connector()
@@ -194,3 +175,45 @@
194175 cur.execute(sql, params)
195176 except Exception, e:
196177 pass
178+
179+ @property
180+ def connection_uri(self):
181+ return DatabaseManager(self.env).connection_uri
182+
183+ def get_table_names(self, db):
184+ cursor = db.cursor()
185+ scheme = self.connection_uri.split(':')[0]
186+ if scheme == 'sqlite':
187+ cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
188+ return [row[0] for row in cursor]
189+ if scheme == 'postgres':
190+ cursor.execute("""
191+ SELECT table_name FROM information_schema.tables
192+ WHERE table_schema=%s""", (db.schema,))
193+ return [row[0] for row in cursor]
194+ if schema == 'mysql':
195+ cursor.execute("""
196+ SELECT table_name FROM information_schema.tables
197+ WHERE table_schema=%s""", (db.schema,))
198+ return [row[0] for row in cursor]
199+ raise ValueError('Unknown scheme %s' % scheme)
200+
201+ def get_column_names(self, db, table):
202+ cursor = db.cursor()
203+ scheme = self.connection_uri.split(':')[0]
204+ if scheme == 'sqlite':
205+ cursor.execute("PRAGMA table_info(%s)" % db.quote(table))
206+ return [row[1] for row in cursor]
207+ if scheme == 'postgres':
208+ cursor.execute("""
209+ SELECT column_name FROM information_schema.columns
210+ WHERE table_schema=%s AND table_name=%s
211+ """, (db.schema, table))
212+ return [row[0] for row in cursor]
213+ if schema == 'mysql':
214+ cursor.execute("""
215+ SELECT column_name FROM information_schema.columns
216+ WHERE table_schema=%s AND table_name=%s
217+ """, (db.schema, table))
218+ return [row[0] for row in cursor]
219+ raise ValueError('Unknown scheme %s' % scheme)
--- plugins/mailarchiveplugin/branches/mailarchiveext/0.12/setup.py (revision 873)
+++ plugins/mailarchiveplugin/branches/mailarchiveext/0.12/setup.py (revision 874)
@@ -4,7 +4,7 @@
44 name='TracMailArchive',
55 author='wadahiro',
66 author_email='wadahiro@gmail.com',
7- version='0.4.2',
7+ version='0.4.3',
88 license = "New BSD",
99 url='http://sourceforge.jp/projects/shibuya-trac/wiki/plugins%2FMailArchiveExtPlugin',
1010 packages=find_packages(exclude=['*.tests*']),
旧リポジトリブラウザで表示