diff --git a/README.md b/README.md index 3a0b6af..cb56685 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,8 @@ Gdrive utilizes a postgres database to write various persistent data points. (ex However, if the user does wish to work on this DB locally, follow steps to [install PostgresDB](https://dev.to/sfpear/install-and-use-postgres-in-wsl-423d#:~:text=To%20install%20Postgres%20and%20run%20it%20in%20WSL%2C,installation%20and%20get%20the%20version%20number%3A%20psql%20--version). -Once installed, a schema needs to be created for IDVA. +> **_NOTE:_** Once installed, a schema needs to be created for IDVA. `env.py` in alembic handles this dynamically, using SqlAlchemy to check if the schema is present and creating if not. This is done before any migrations take place and should be safe to run on a fresh db install. -```sql -create schema if not exists idva; -``` Once the above SQL has been run on postgres, alembic can be used to build the DDL Dependencies. Alembic uses the same connection string and schema as the gdrive module, loading the diff --git a/alembic/env.py b/alembic/env.py index 3ab07c6..8b10251 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -2,6 +2,7 @@ from sqlalchemy import engine_from_config from sqlalchemy import pool +from sqlalchemy import schema from alembic import context import sqlalchemy @@ -77,6 +78,9 @@ def run_migrations_online() -> None: connect_args={"options": "-csearch_path=%s" % (settings.SCHEMA)}, ) + if not connectable.dialect.has_schema(connectable, settings.SCHEMA): + connectable.execute(schema.CreateSchema(settings.SCHEMA)) + with connectable.connect() as connection: context.configure(connection=connection, target_metadata=target_metadata) diff --git a/manifest.yaml b/manifest.yaml index 8f1c765..78145f1 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -8,7 +8,7 @@ applications: buildpacks: - python_buildpack command: | - alembic upgrade head + alembic upgrade head && uvicorn gdrive.main:app --host 0.0.0.0 --port $PORT services: - gdrive