forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
40 lines (28 loc) · 804 Bytes
/
database.py
File metadata and controls
40 lines (28 loc) · 804 Bytes
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
38
39
40
import time
from flask.cli import AppGroup
from flask_migrate import stamp
from sqlalchemy.exc import DatabaseError
manager = AppGroup(help="Manage the database (create/drop tables).")
def _wait_for_db_connection(db):
retried = False
while not retried:
try:
db.engine.execute('SELECT 1;')
return
except DatabaseError:
time.sleep(30)
retried = True
@manager.command()
def create_tables():
"""Create the database tables."""
from redash.models import db
_wait_for_db_connection(db)
db.create_all()
# Need to mark current DB as up to date
stamp()
@manager.command()
def drop_tables():
"""Drop the database tables."""
from redash.models import db
_wait_for_db_connection(db)
db.drop_all()