added migration commands

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2023-04-13 17:25:18 +02:00
parent 47e7eeb4fe
commit 052979b5d9
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
3 changed files with 48 additions and 0 deletions

View File

@ -137,6 +137,30 @@ def init_database(connection, dbname):
raise NotImplementedError
@singledispatch
def migrate_up(connection):
"""Migrate database up
Args:
connection (:class:`~planetmint.backend.connection.Connection`): an
existing connection to use to migrate the database.
Creates one if not given.
"""
raise NotImplementedError
@singledispatch
def migrate_down(connection):
"""Migrate database down
Args:
connection (:class:`~planetmint.backend.connection.Connection`): an
existing connection to use to migrate the database.
Creates one if not given.
"""
raise NotImplementedError
def validate_language_key(obj, key):
"""Validate all nested "language" key in `obj`.

View File

@ -35,3 +35,13 @@ def create_database(connection, dbname):
@register_schema(TarantoolDBConnection)
def create_tables(connection, dbname):
connection.connect().call("init")
@register_schema(TarantoolDBConnection)
def migrate_up(connection):
connection.connect().call("migrate_up")
@register_schema(TarantoolDBConnection)
def migrate_down(connection):
connection.connect().call("migrate_down")

View File

@ -258,6 +258,16 @@ def run_init(args):
_run_init()
@configure_planetmint
def run_migrate_up(args):
return
@configure_planetmint
def run_migrate_down(args):
return
@configure_planetmint
def run_drop(args):
"""Drop the database"""
@ -363,6 +373,10 @@ def create_parser():
subparsers.add_parser("drop", help="Drop the database")
subparsers.add_parser("migrate_up", help="Migrate up")
subparsers.add_parser("migrate_down", help="Migrate down")
# parser for starting Planetmint
start_parser = subparsers.add_parser("start", help="Start Planetmint")