Buckets:
| from alembic.config import Config | |
| from alembic.runtime.migration import MigrationContext | |
| from alembic import command | |
| from pathlib import Path | |
| from sqlalchemy import inspect | |
| from sqlalchemy.engine import Connection, Engine | |
| def has_tables(connection: Connection) -> bool: | |
| inspector = inspect(connection) | |
| tables = inspector.get_table_names() | |
| return len(tables) > 0 | |
| def has_revision(connection: Connection) -> bool: | |
| context = MigrationContext.configure(connection) | |
| current_rev = context.get_current_revision() | |
| return current_rev is not None | |
| def migrate_db(engine: Engine) -> None: | |
| config_path = Path(__file__).resolve().parent.parent / "alembic.ini" | |
| alembic_cfg = Config(config_path) | |
| with engine.begin() as connection: | |
| # check if database has not been migrated yet with alembic | |
| if has_tables(connection) and not has_revision(connection): | |
| # stamp database with the initial revision id, representing pre-alembic database schema | |
| command.stamp(alembic_cfg, "c54a916ec6c8") | |
| command.upgrade(alembic_cfg, "head") | |
Xet Storage Details
- Size:
- 1.09 kB
- Xet hash:
- bb9dc7c1fb4fea4d76710fc588c8d2f6ce7b97130eef2452b7234c33f641b797
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.