def test_update_force(self): from ptah.migrate import Version, revision, update_versions ptah.register_migration('test', 'ptah.tests:migrations', force=True) self.init_ptah() revision('test', message='Test message') update_versions(self.registry) session = ptah.get_session() versions = dict( (v.package, v.version_num) for v in session.query(Version).all()) self.assertNotIn('test', versions)
def test_update_versions(self): from ptah.migrate import Version, revision, update_versions ptah.register_migration('test', 'ptah.tests:migrations') self.init_ptah() rev = revision('test', message='Test message') update_versions(self.registry) session = ptah.get_session() versions = dict((v.package, v.version_num) for v in session.query(Version).all()) self.assertIn('test', versions) self.assertEqual(versions['test'], rev)
def test_update_version_exists(self): from ptah.migrate import Version, revision, update_versions ptah.register_migration('test', 'ptah.tests:migrations') self.init_ptah() revision('test', message='Test message') session = ptah.get_session() session.add(Version(package='test', version_num='123')) session.flush() update_versions(self.registry) versions = dict( (v.package, v.version_num) for v in session.query(Version).all()) self.assertIn('test', versions) self.assertEqual(versions['test'], '123')
def create_db_schema(registry, update=True): registry.notify(ptah.events.BeforeCreateDbSchema(registry)) skip_tables = ptah.get_settings(ptah.CFG_ID_PTAH)['db_skip_tables'] Base = ptah.get_base() log = logging.getLogger('ptah') tables = [] for name, table in Base.metadata.tables.items(): if name not in skip_tables and not table.exists(): log.info("Creating db table `%s`.", name) tables.append(table) if tables: Base.metadata.create_all(tables=tables) transaction.commit() # update db versions if update: update_versions(registry)