def _run_schema(conn: Client, schema: Schema) -> None: if not isinstance(schema, TableSchema): return clickhouse_table = schema.get_local_table_name() local_schema = get_local_schema(conn, clickhouse_table) migrations = schema.get_migration_statements()(clickhouse_table, local_schema) for statement in migrations: logger.info(f"Executing migration: {statement}") conn.execute(statement) # Refresh after alters refreshed_schema = get_local_schema(conn, clickhouse_table) # Warn user about any *other* schema diffs differences = schema.get_column_differences(refreshed_schema) for difference in differences: logger.warn(difference)
def test_no_schema_diffs(dataset: Dataset) -> None: from snuba.migrations.parse_schema import get_local_schema writable_storage = dataset.get_writable_storage() if not writable_storage: pytest.skip(f"{dataset!r} has no writable storage") clickhouse = writable_storage.get_cluster().get_query_connection( ClickhouseClientSettings.MIGRATE) table_writer = writable_storage.get_table_writer() dataset_schema = table_writer.get_schema() local_table_name = dataset_schema.get_local_table_name() local_schema = get_local_schema(clickhouse, local_table_name) assert not dataset_schema.get_column_differences(local_schema)
def test_no_schema_differences() -> None: runner = Runner() runner.run_all(force=True) for storage_key in StorageKey: storage = get_storage(storage_key) conn = storage.get_cluster().get_query_connection( ClickhouseClientSettings.MIGRATE) schema = storage.get_schema() if not isinstance(schema, TableSchema): continue table_name = schema.get_local_table_name() local_schema = get_local_schema(conn, table_name) assert (schema.get_column_differences(local_schema) == [] ), f"Schema mismatch: {table_name} does not match schema"
def test_no_schema_differences() -> None: settings.ENABLE_DEV_FEATURES = True importlib.reload(factory) runner = Runner() runner.run_all(force=True) for storage_key in STORAGES: storage = get_storage(storage_key) conn = storage.get_cluster().get_query_connection( ClickhouseClientSettings.MIGRATE) schema = storage.get_schema() if not isinstance(schema, TableSchema): continue table_name = schema.get_local_table_name() local_schema = get_local_schema(conn, table_name) assert (schema.get_column_differences(local_schema) == [] ), f"Schema mismatch: {table_name} does not match schema" importlib.reload(settings) importlib.reload(factory)