Update waiting for database.
This commit is contained in:
parent
399fc759e6
commit
07ccdf2c94
30
tasks/db.py
30
tasks/db.py
|
@ -5,33 +5,15 @@ Tasks for working with the database attached to the API.
|
||||||
:license: AGPL v3+
|
:license: AGPL v3+
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import invoke as inv
|
import invoke as inv
|
||||||
|
|
||||||
import rookeries
|
|
||||||
from rookeries import database as rookeries_db
|
from rookeries import database as rookeries_db
|
||||||
|
|
||||||
|
|
||||||
@inv.task
|
@inv.task
|
||||||
def init(ctx):
|
def wait(ctx, timeout=10):
|
||||||
"""
|
db_connection = urlparse(rookeries_db.get_db_connection_from_env())
|
||||||
Initialize the database with sample code.
|
wait_for = f'{db_connection.scheme}://{db_connection.netloc}/'
|
||||||
|
ctx.run(f'dockerize -wait {wait_for}/ -timeout {timeout}s')
|
||||||
Run in order: inv db.init, inv db.upgrade & inv db.create_migration -m 'Migrate me'.
|
|
||||||
|
|
||||||
:param ctx: Context of the invoke task.
|
|
||||||
"""
|
|
||||||
|
|
||||||
app = rookeries.make_rookeries_app(quiet_log=True)
|
|
||||||
rookeries_db.db.init_app(app)
|
|
||||||
rookeries_db.migrations.init_app(app)
|
|
||||||
with app.app_context():
|
|
||||||
rookeries_db.db.create_all()
|
|
||||||
rookeries_db.migrations.stamp()
|
|
||||||
|
|
||||||
|
|
||||||
@inv.task
|
|
||||||
def wait(ctx):
|
|
||||||
db_connection = rookeries_db.get_db_connection_from_env()
|
|
||||||
_, _, connection, _ = db_connection.split('/')
|
|
||||||
_, db_host_port = connection.split('@')
|
|
||||||
inv.run(f'dockerize -wait tcp://{db_host_port}')
|
|
||||||
|
|
Loading…
Reference in New Issue