mirror of
https://github.com/xlorepdarkhelm/numinar-coding-project.git
synced 2026-09-06 03:28:24 -04:00
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
"""Add seed data from seed.sql with separate prepared statements
|
|
|
|
Revision ID: e6a14f4dae3d
|
|
Revises:
|
|
Create Date: 2025-08-22 23:40:52.885449
|
|
"""
|
|
|
|
from pathlib import Path
|
|
from typing import Sequence
|
|
from typing import Union
|
|
|
|
from alembic import op
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "e6a14f4dae3d"
|
|
down_revision: Union[str, Sequence[str], None] = None
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Upgrade schema by loading and executing seed.sql as separate prepared statements."""
|
|
# Get the parent directory of the current migration script's directory
|
|
migration_dir = Path(__file__).parent.parent.resolve()
|
|
seed_file_path = migration_dir / "seed.sql"
|
|
|
|
# Read the seed.sql file
|
|
with seed_file_path.open("r") as file:
|
|
sql_content = file.read()
|
|
|
|
# Split the SQL content into individual statements
|
|
sql_statements = [stmt.strip() for stmt in sql_content.split(";") if stmt.strip()]
|
|
|
|
# Execute each statement individually
|
|
for stmt in sql_statements:
|
|
op.execute(stmt)
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema by removing data from users and rooms tables."""
|
|
op.execute("DELETE FROM users")
|
|
op.execute("DELETE FROM rooms")
|