From 8c3905c5d3de183227d9836c753b7fbdf64c261d Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 6 Dec 2018 18:33:39 +0100 Subject: [PATCH] Have a function to initialize migrations --- src/yunohost/tools.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index fce2f1569..ebb9516f1 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -434,7 +434,7 @@ def tools_postinstall(operation_logger, domain, password, ignore_dyndns=False, _install_appslist_fetch_cron() # Init migrations (skip them, no need to run them on a fresh system) - tools_migrations_migrate(skip=True, auto=True) + _skip_all_migrations() os.system('touch /etc/yunohost/installed') @@ -950,7 +950,6 @@ def tools_migrations_migrate(target=None, skip=False, auto=False, accept_disclai write_to_json(MIGRATIONS_STATE_PATH, state) - def tools_migrations_state(): """ Show current migration state @@ -1050,6 +1049,25 @@ def _load_migration(migration_file): raise MoulinetteError(errno.EINVAL, m18n.n('migrations_error_failed_to_load_migration', number=number, name=name)) +def _skip_all_migrations(): + """ + Skip all pending migrations. + This is meant to be used during postinstall to + initialize the migration system. + """ + state = tools_migrations_state() + + # load all migrations + migrations = _get_migrations_list() + migrations = sorted(migrations, key=lambda x: x.number) + last_migration = migrations[-1] + + state["last_run_migration"] = { + "number": last_migration.number, + "name": last_migration.name + } + write_to_json(MIGRATIONS_STATE_PATH, state) + class Migration(object):