def migrate(self, migration_direction): """ Migrates migration found in self.module towards to given direction. :param migration_direction: Direction towards which to migrate. Can be forward or backward. :return: """ assert self.module is not None if hasattr(self.module, migration_direction): handler = getattr(self.module, migration_direction) stdout.write('Migrating %s to migration %s in package %s\n' % ( migration_direction, self.py_module_name, self.py_package, )) else: raise IncorrectMigrationFile('Module %s has no %s function' % ( self.module, migration_direction, )) try: handler(database_api) if migration_direction == MigrationHelper.MigrationDirection.FORWARD: self.write_migration_history() else: self.delete_migration_history() database_api.commit() except Exception as e: if not database_api._connection.closed: database_api.rollback() database_api._connection.close() raise e
def tearDown(self): try: database_api.execute(''' DROP TABLE %s; ''' % self.config.history_table_name) database_api.commit() except: pass super(DatabaseTestCase, self).tearDown()
def drop_history_table(): sql = ''' DROP TABLE %s; ''' % rsm_config.history_table_name database_api.execute( sql, params=(rsm_config.history_table_name,), return_result=None ) database_api.commit()
def tearDown(self): try: database_api.execute( ''' DROP TABLE %s; ''' % self.config.history_table_name ) database_api.commit() except: pass super(DatabaseTestCase, self).tearDown()
def create_history_table(): sql = ''' CREATE TABLE %s ( id SERIAL PRIMARY KEY, package VARCHAR(200) NOT NULL, name VARCHAR(200) NOT NULL, processed_at TIMESTAMP default current_timestamp ); ''' % rsm_config.history_table_name database_api.execute( sql, params=(), return_result=None ) database_api.commit()
def test_correct_status_for_multiple_migrations_with_package(self): DatabaseHelper.write_migration_history('0002_do_something', 'test_package') database_api.commit() data = self.api.status(package='test_package') self.assertEqual(len(data.keys()), 1)
def setUp(self): super(StatusTestCase, self).setUp() self.api._create_migration_history_table_if_not_exists() DatabaseHelper.write_migration_history('0001_initial', 'test_package') database_api.commit()