#11978 closed enhancement (fixed)
Add drop_schema method to ConnectionBase class
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.1.5 |
Component: | database backend | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: |
|
||
Internal Changes: |
Description
After adding the method we can refactor the code in EnvironmentStub
to eliminate the SQL query: trunk/trac/test.py@13818:355#L349.
Attachments (1)
Change History (19)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
I like first approach and destroy_db
rather than drop_schema
. init_db
method already exists and only PostgreSQL uses schema.
comment:3 by , 10 years ago
Should we add the destroy_db
method to the DatabaseManager
class (tags/trac-1.1.3/trac/db/api.py@:324#L299) and IDatabaseConnector
interface (tags/trac-1.1.3/trac/db/api.py@:287#L262)? I started working on a patch with those changes and I'll finish it after the 1.1.4 release.
comment:4 by , 10 years ago
Well, I think that it would be good to add the destroy_db
method to those class and interface.
comment:5 by , 10 years ago
comment:7 by , 10 years ago
comment:8 by , 10 years ago
At least, I think use of finally
statement is wrong in [f247fb2d7/rjollos.git].
Traceback (most recent call last): File "./trac/test.py", line 35, in <module> locale_en = Locale.parse('en_US') NameError: name 'Locale' is not defined
-
trac/test.py
diff --git a/trac/test.py b/trac/test.py index 76aa37e..daa3e8f 100755
a b try: 31 31 from babel import Locale 32 32 except ImportError: 33 33 locale_en = None 34 finally:34 else: 35 35 locale_en = Locale.parse('en_US') 36 36 37 37 import trac.db.mysql_backend
by , 10 years ago
Attachment: | t11978-postgres-quote.diff added |
---|
comment:9 by , 10 years ago
Another thing: to_sql
and alter_column_types
methods of PostgresConnector
have the same issue in [d21966f3/rjollos.git]. Proposed changes in attachment:t11978-postgres-quote.diff.
comment:10 by , 10 years ago
Thanks, I made ticket #11998 so we can fix the quoting issues on 1.0-stable.
comment:11 by , 10 years ago
API Changes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Committed to trunk in [13924:13925].
follow-up: 13 comment:12 by , 10 years ago
Removed use of deprecated EnvironmentStub.destroy_db
in [13943].
comment:13 by , 10 years ago
comment:14 by , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Proposed changes in log:rjollos.git:t11978.1, including a few unrelated changes.
follow-up: 16 comment:15 by , 10 years ago
I should commit these changes since tests are still failing on the trunk. I've been debating [792052f2/rjollos.git], whether to just catch Exception
, or to be more specific, as in the patch that catches (TimeoutError, OSError, self.db_exc.DatabaseError)
. Although another option is to have the IDatabaseConnector
implementation catch the database-specific exceptions (e.g. with SQLite
an OSError
can result), and raise a TracError
.
Any thoughts on which approach is best?
comment:16 by , 10 years ago
Replying to rjollos:
I should commit these changes since tests are still failing on the trunk. I've been debating [792052f2/rjollos.git], whether to just catch
Exception
, or to be more specific, as in the patch that catches(TimeoutError, OSError, self.db_exc.DatabaseError)
. Although another option is to have theIDatabaseConnector
implementation catch the database-specific exceptions (e.g. withSQLite
anOSError
can result), and raise aTracError
.Any thoughts on which approach is best?
I consider that we shouldn't raise OSError
from SQLiteConnector.destroy_db
when the file is missing. Instead, we should trap ENOENT
error in the method. So, I think we should catch only the database-specific exceptions and TimeoutError
.
-
trac/db/sqlite_backend.py
diff --git a/trac/db/sqlite_backend.py b/trac/db/sqlite_backend.py index c431f00..e8c8c62 100644
a b 14 14 # 15 15 # Author: Christopher Lenz <cmlenz@gmx.de> 16 16 17 import errno 17 18 import os 18 19 import re 19 20 import weakref … … class SQLiteConnector(Component): 223 224 if path != ':memory:': 224 225 if not os.path.isabs(path): 225 226 path = os.path.join(self.env.path, path) 226 os.remove(path) 227 try: 228 os.remove(path) 229 except OSError as e: 230 if e.errno != errno.ENOENT: 231 raise 227 232 228 233 def to_sql(self, table): 229 234 return _to_sql(table) -
trac/test.py
diff --git a/trac/test.py b/trac/test.py index f06ffa7..48b0f0a 100755
a b class EnvironmentStub(Environment): 335 335 db.rollback() # make sure there's no transaction in progress 336 336 # check the database version 337 337 db_version = dbm.get_database_version() 338 except TimeoutError:338 except (TimeoutError, self.db_exc.DatabaseError): 339 339 pass 340 340 else: 341 341 if db_version == db_default.db_version: … … class EnvironmentStub(Environment): 365 365 """ 366 366 try: 367 367 self.global_databasemanager.destroy_db() 368 except (TimeoutError, OSError,self.db_exc.DatabaseError):368 except (TimeoutError, self.db_exc.DatabaseError): 369 369 pass 370 370 return False 371 371
comment:17 by , 10 years ago
API Changes: | modified (diff) |
---|
Thank you for the refinements. Committed to trunk in [13957:13958].
A frequent mistake that I repeated in [13957] is not having a valid Makefile.cfg
, thinking that I've run the tests successfully with one of the databases, but they've actually only been executed for in-memory SQLite.
comment:18 by , 10 years ago
API Changes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | reopened → closed |
Or we could make the
table
argument ofdrop_table
default toNone
and drop all the tables whentable = None
: trunk/trac/db/api.py@13595:200#L184. Is one of the two approaches more preferable?