-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
update.py
37 lines (28 loc) · 1016 Bytes
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gevent.monkey
gevent.monkey.patch_all()
import psycogreen.gevent
psycogreen.gevent.patch_psycopg()
import os
from alembic import command
from alembic.config import Config
from flask.cli import with_appcontext
from model.Media import storage
from shared import app, db
MIGRATION_DIR = "migrations"
EARLIEST_REVISION = "b38b893343b7"
def update_storage():
storage.update()
def update_db():
alembic_config = Config(os.path.join(MIGRATION_DIR, "alembic.ini"))
alembic_config.set_main_option("script_location", MIGRATION_DIR)
with app.app_context():
if not db.engine.dialect.has_table(db.engine, "alembic_version"):
# consider old databases lacking alembic support to have the earliest
# revision
command.stamp(config=alembic_config, revision=EARLIEST_REVISION)
db.session.flush()
command.upgrade(config=alembic_config, revision="head")
db.session.commit()
if __name__ == "__main__":
update_storage()
update_db()