Adopt SQLModel, create models, start using it (#559)

* 🔥 Remove old SQLAlchemy models

*  Add new SQLModel models

* 🔧 Update Alembic configs to work with SQLModel

*  Re-generate initial Alembic migration

* 🔧 Update PostgreSQL driver connection string URL

*  Create new SQLModel engine

* 🔥 Remove old unneeded SQLAlchemy-specific files

* ♻️ Update init_db

* ♻️ Use new SQLModel session

* ♻️ Update conftest with new DB Session

* ♻️ Update pre-start scripts to use SQLModel session

* ♻️ Import new SQLModel models

*  Create new simplified create_user crud util

* ♻️ Update import in CRUDBase class (soon to be removed)

* 🙈 Update .gitignore with Python files
This commit is contained in:
Sebastián Ramírez
2023-11-25 00:08:22 +01:00
committed by GitHub
parent 2d92cd70a4
commit a66a9256dd
26 changed files with 193 additions and 163 deletions

View File

@@ -20,9 +20,9 @@ fileConfig(config.config_file_name)
# target_metadata = mymodel.Base.metadata
# target_metadata = None
from app.db.base import Base # noqa
from app.models import SQLModel # noqa
target_metadata = Base.metadata
target_metadata = SQLModel.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
@@ -35,7 +35,7 @@ def get_url():
password = os.getenv("POSTGRES_PASSWORD", "")
server = os.getenv("POSTGRES_SERVER", "db")
db = os.getenv("POSTGRES_DB", "app")
return f"postgresql://{user}:{password}@{server}/{db}"
return f"postgresql+psycopg://{user}:{password}@{server}/{db}"
def run_migrations_offline():