Skip to content

Commit

Permalink
Make models dynamicly imported for alembic
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog committed May 13, 2024
1 parent f8d13fe commit 0dd830c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions tad/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@

from alembic import context
from sqlalchemy import engine_from_config, pool
from sqlmodel import SQLModel
from tad.models import * # noqa

config = context.config

if config.config_file_name is not None:
fileConfig(config.config_file_name)

# todo(berry): automaticly import all models
from tad.models.hero import Hero # noqa

target_metadata = [Hero.metadata]
target_metadata = SQLModel.metadata


def get_url():
scheme = os.getenv("SQLALCHEMY_SCHEME", "sqlite")
scheme = os.getenv("APP_DATABASE_SCHEME", "sqlite")

if scheme == "sqlite":
file = os.getenv("SQLITE_FILE", "/database")
file = os.getenv("APP_DATABASE__FILE", "/database")
return f"{scheme}:///{file}"

user = os.getenv("APP_DATABASE_USER", "postgres")
user = os.getenv("APP_DATABASE_USER", "tad")
password = os.getenv("APP_DATABASE_PASSWORD", "")
server = os.getenv("APP_DATABASE_SERVER", "db")
port = os.getenv("APP_DATABASE_PORT", "5432")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Added hero test table
"""a message
Revision ID: a1d47bd833f8
Revision ID: 006c480a1920
Revises:
Create Date: 2024-05-10 14:00:32.948932
Create Date: 2024-05-13 12:36:32.647256
"""

Expand All @@ -13,7 +13,7 @@
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "a1d47bd833f8"
revision: str = "006c480a1920"
down_revision: str | None = None
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
Expand Down

0 comments on commit 0dd830c

Please sign in to comment.