-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change how the backend and database migrations are structured (Fixes #…
…119) - BREAKING: Added `appointment` module folder in `src`. - BREAKING: alembic.ini should now be placed in the backend root folder. You will need to grab a fresh copy as there's been additional changes. - Added a super simple cli interface handled by main.py - Adjusted main.py to bootstrap either a fast api server or a cli interface. - Added a `update-db` command that is installed when pip install this module. - The `update-db` command will initialize a fresh database or run migrations, resolving most of our database woes. - New folder structure more closely matches the deployed folder structure for easier deployments. - Local docker now only mounts the `src` folder - Commented out some non-existent columns/constraints in a recent migration - Added missing trailing slash to the frontend for `schedule/` - Added sentry support to migrations - Adjusted code-referenced folder locations as required
- Loading branch information
1 parent
cb97ad4
commit e7ba925
Showing
45 changed files
with
147 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ dist | |
*.pickle | ||
.env | ||
venv | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
#!/bin/sh | ||
|
||
cd src | ||
echo 'Starting migrations...' | ||
alembic current | ||
alembic upgrade head | ||
echo 'Finished migrations!' | ||
cd ../ | ||
run-command update-db | ||
|
||
uvicorn src.main:app --reload --host 0.0.0.0 --port 8090 | ||
uvicorn --factory src.appointment.main:server --reload --host 0.0.0.0 --port 8090 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
#!/bin/sh | ||
|
||
cd src | ||
echo 'Starting migrations...' | ||
alembic current | ||
alembic upgrade head | ||
echo 'Finished migrations!' | ||
cd ../ | ||
run-command update-db | ||
|
||
uvicorn src.main:app --host 0.0.0.0 --port 5000 | ||
uvicorn --factory src.appointment.main:server --host 0.0.0.0 --port 5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
|
||
from ..database import models | ||
from ..database.database import engine | ||
from alembic.runtime import migration | ||
|
||
|
||
def run(): | ||
print("Checking if we have a fresh database...") | ||
|
||
# then, load the Alembic configuration and generate the | ||
# version table, "stamping" it with the most recent rev: | ||
from alembic import command | ||
from alembic.config import Config | ||
|
||
# TODO: Does this work on stage? | ||
alembic_cfg = Config("./alembic.ini") | ||
|
||
# If we have our database url env variable set, use that instead! | ||
if os.getenv("DATABASE_URL"): | ||
alembic_cfg.set_main_option("sqlalchemy.url", os.getenv("DATABASE_URL")) | ||
|
||
with engine.begin() as connection: | ||
context = migration.MigrationContext.configure(connection) | ||
# Returns a tuple, empty if there's no revisions saved | ||
revisions = context.get_current_heads() | ||
|
||
# If we have no revisions, then fully create the database from the model metadata, | ||
# and set our revision number to the latest revision. Otherwise run any new migrations | ||
if len(revisions) == 0: | ||
print("Initializing database, and setting it to the latest revision") | ||
models.Base.metadata.create_all(bind=engine) | ||
command.stamp(alembic_cfg, "head") | ||
else: | ||
print("Database already initialized, running migrations") | ||
command.upgrade(alembic_cfg, 'head') | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters