diff --git a/planetmint/backend/schema.py b/planetmint/backend/schema.py index e3eceef..2af754f 100644 --- a/planetmint/backend/schema.py +++ b/planetmint/backend/schema.py @@ -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`. diff --git a/planetmint/backend/tarantool/sync_io/schema.py b/planetmint/backend/tarantool/sync_io/schema.py index 83cf319..3d86206 100644 --- a/planetmint/backend/tarantool/sync_io/schema.py +++ b/planetmint/backend/tarantool/sync_io/schema.py @@ -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") diff --git a/planetmint/commands/planetmint.py b/planetmint/commands/planetmint.py index 6a9bc35..79c5689 100644 --- a/planetmint/commands/planetmint.py +++ b/planetmint/commands/planetmint.py @@ -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")