Skip to content

Commit 4057b8e

Browse files
skip db creation in init if already exist (Netflix#142)
In some PaaS like Platform.sh, you already start with an existing database and the user doesn't have permission to create new ones. Only to create/delete tables.
1 parent c6dc5f4 commit 4057b8e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/dispatch/cli.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,10 @@ def database_trigger_sync():
489489
@dispatch_database.command("init")
490490
def init_database():
491491
"""Initializes a new database."""
492-
from sqlalchemy_utils import create_database
492+
from sqlalchemy_utils import create_database, database_exists
493493

494-
create_database(str(config.SQLALCHEMY_DATABASE_URI))
494+
if not database_exists(str(config.SQLALCHEMY_DATABASE_URI)):
495+
create_database(str(config.SQLALCHEMY_DATABASE_URI))
495496
Base.metadata.create_all(engine)
496497
alembic_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "alembic.ini")
497498
alembic_cfg = AlembicConfig(alembic_path)

0 commit comments

Comments
 (0)