-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'features/119-clean-up-migration-process' into stage
- Loading branch information
Showing
8 changed files
with
119 additions
and
61 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
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 src.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 src.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("./src/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') | ||
|
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