async def run(self): """ Prints out the migrations which have and haven't ran. """ print("Listing migrations ...") desc_length = 40 id_length = 26 print(f'{get_fixed_length_string("APP NAME")} | ' f'{get_fixed_length_string("MIGRATION_ID", id_length)} | ' f'{get_fixed_length_string("DESCRIPTION", desc_length)} | RAN') migration_statuses = await self.get_migration_statuses() for migration_status in migration_statuses: fixed_length_app_name = get_fixed_length_string( migration_status.app_name) fixed_length_id = get_fixed_length_string( migration_status.migration_id, length=id_length) fixed_length_description = get_fixed_length_string( migration_status.description, desc_length) has_ran = migration_status.has_ran print(f"{fixed_length_app_name} | " f"{fixed_length_id} | " f"{fixed_length_description} | " f"{has_ran}")
async def run(self): print("Listing migrations ...") # Make sure the migration table exists, otherwise we'll get an error. await self.create_migration_table() print(f'{get_fixed_length_string("APP NAME")} | ' f'{get_fixed_length_string("MIGRATION_ID")} | RAN') app_modules = self.get_app_modules() for app_module in app_modules: app_config = app_module.APP_CONFIG app_name = app_config.app_name if (self.app_name != "all") and (self.app_name != app_name): continue fixed_length_app_name = get_fixed_length_string(app_name) migration_modules = self.get_migration_modules( app_config.migrations_folder_path) ids = self.get_migration_ids(migration_modules) for _id in ids: has_ran = (await Migration.exists().where( (Migration.name == _id) & (Migration.app_name == app_name)).run()) fixed_length_id = get_fixed_length_string(_id) print( f"{fixed_length_app_name} | {fixed_length_id} | {has_ran}")
def test_truncation(self): """ Make sure the string is truncated to the fixed length if it's too long. """ result = get_fixed_length_string( string="this is a very, very long string", length=20) self.assertEqual(result, "this is a very, v...")
async def run(self): """ Prints out the migrations which have and haven't ran. """ print("Listing migrations ...") print(f'{get_fixed_length_string("APP NAME")} | ' f'{get_fixed_length_string("MIGRATION_ID")} | RAN') migration_statuses = await self.get_migration_statuses() for migration_status in migration_statuses: fixed_length_app_name = get_fixed_length_string( migration_status.app_name) fixed_length_id = get_fixed_length_string( migration_status.migration_id) has_ran = migration_status.has_ran print(f"{fixed_length_app_name} | {fixed_length_id} | {has_ran}")
def get_alter_statements(self) -> t.List[AlterStatements]: """ Call to execute the necessary alter commands on the database. """ alter_statements: t.Dict[str, AlterStatements] = { "Created tables": self.create_tables, "Dropped tables": self.drop_tables, "Renamed tables": self.rename_tables, "Created table columns": self.new_table_columns, "Dropped columns": self.drop_columns, "Columns added to existing tables": self.add_columns, "Renamed columns": self.rename_columns, "Altered columns": self.alter_columns, } for message, statements in alter_statements.items(): _message = get_fixed_length_string(message, length=40) count = len(statements.statements) print(f"{_message} {count}") return [i for i in alter_statements.values()]
def test_get_fixed_length_string(self): result = get_fixed_length_string(string="hello", length=10) self.assertEqual(result, "hello ")
def test_extra_padding(self): """ Make sure the additional padding is added. """ result = get_fixed_length_string(string="hello", length=10) self.assertEqual(result, "hello ")