select and asyncpg
This commit is contained in:
1 parent
d0e2be7d12
commit
e16a193cb7
6 files changed
+95
-123
No files matched your search
+9
-12
@@ -1,16 +1,13 @@
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Engine
|
||||
from alembic.config import Config
|
||||
from alembic import command
|
||||
from dotenv import dotenv_values
|
||||
import asyncio
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine
|
||||
from alembic import command, config
|
||||
|
||||
# Function to perform the database migration
|
||||
def migrate_db(engine: Engine, db_url):
|
||||
# Configure Alembic
|
||||
alembic_cfg = Config()
|
||||
alembic_cfg.set_main_option("script_location", "migrations")
|
||||
alembic_cfg.set_main_option("sqlalchemy.url", db_url)
|
||||
def run_upgrade(connection, cfg):
|
||||
cfg.attributes["connection"] = connection
|
||||
command.upgrade(cfg, "head")
|
||||
|
||||
# Run migrations using Alembic
|
||||
command.upgrade(alembic_cfg, "head")
|
||||
|
||||
print('db up to date')
|
||||
async def migrate_db(async_engine: AsyncEngine):
|
||||
async with async_engine.begin() as conn:
|
||||
await conn.run_sync(run_upgrade, config.Config("alembic.ini"))
|
||||
Reference in new issue
Block a user