generated from TheMrPhantom/react-vorlage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
themrphantom
committed
Apr 26, 2024
1 parent
df3dc1e
commit 6ff0f4f
Showing
3 changed files
with
37 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from flask_sqlalchemy import SQLAlchemy | ||
from database.Models import * | ||
from sqlalchemy.orm import session | ||
from sqlalchemy import text | ||
import util | ||
|
||
|
||
def migrate(db: session): | ||
current_db_version: KeyValue = db.query(KeyValue).filter_by( | ||
key="version").first() | ||
print("Current database version:", current_db_version.value) | ||
|
||
migrations = [ | ||
# Add lists for migrations | ||
# E.g ALTER TABLE drink ADD column price6 float DEFAULT 50 | ||
#["ALTER TABLE drink ADD column price6 float DEFAULT 50"] | ||
] | ||
|
||
if util.CURRENT_VERSION != len(migrations): | ||
print("Error: No migration available") | ||
exit() | ||
|
||
for migration in migrations[int(current_db_version.value):]: | ||
print("Migrating from", current_db_version.value, | ||
"to", int(current_db_version.value)+1) | ||
for statement in migration: | ||
db.execute(text(statement)) | ||
current_db_version.value = int(current_db_version.value)+1 | ||
db.commit() | ||
|
||
print("Migrations complete") |
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