+from __future__ import print_function
+
import sys
import traceback
self.url=alchemy.url
self.engine=alchemy.engine
self.repository="/usr/share/sfa/migrations"
- self.meta=MetaData (bind=self.engine)
def current_version (self):
try:
def table_exists (self, tablename):
try:
- table=Table (tablename, self.meta, autoload=True)
+ metadata = MetaData (bind=self.engine)
+ table=Table (tablename, metadata, autoload=True)
return True
except NoSuchTableError:
return False
def drop_table (self, tablename):
if self.table_exists (tablename):
- print >>sys.stderr, "%s: Dropping table %s"%(DBSchema.header,tablename)
+ print("%s: Dropping table %s"%(DBSchema.header,tablename), file=sys.stderr)
self.engine.execute ("drop table %s cascade"%tablename)
else:
- print >>sys.stderr, "%s: no need to drop table %s"%(DBSchema.header,tablename)
+ print("%s: no need to drop table %s"%(DBSchema.header,tablename), file=sys.stderr)
def handle_old_releases (self):
try:
# try to find out which old version this can be
if not self.table_exists ('records'):
- # this likely means we've just created the db, so it's either a fresh install
- # or we come from a 'very old' depl.
+ # this likely means
+ # (.) we've just created the db, so it's either a fresh install, or
+ # (.) we come from a 'very old' depl.
# in either case, an import is required but there's nothing to clean up
- print >> sys.stderr,"%s: make sure to run import"%(DBSchema.header,)
+ print("%s: make sure to run import"%(DBSchema.header,), file=sys.stderr)
elif self.table_exists ('sfa_db_version'):
# we come from an 'old' version
self.drop_table ('records')
# we should be good here
pass
except:
- print >> sys.stderr, "%s: unknown exception"%(DBSchema.header,)
+ print("%s: unknown exception"%(DBSchema.header,), file=sys.stderr)
traceback.print_exc ()
# after this call the db schema and the version as known by migrate should
after="%s"%self.current_version()
if before != after:
logger.info("DBSchema : upgraded version from %s to %s"%(before,after))
+ else:
+ logger.debug("DBSchema : no change needed in db schema (%s==%s)"%(before,after))
# this trashes the db altogether, from the current model in sfa.storage.model
# I hope this won't collide with ongoing migrations and all
def nuke (self):
model.drop_tables(self.engine)
# so in this case it's like we haven't initialized the db at all
- migrate.drop_version_control (self.url, self.repository)
+ try:
+ migrate.drop_version_control (self.url, self.repository)
+ except migrate.exceptions.DatabaseNotControlledError:
+ logger.log_exc("Failed to drop version control")
if __name__ == '__main__':