From 3a2464dfb46bc2d6cba7cbe3862a694b6cd5258c Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 6 Dec 2018 18:27:18 +0100 Subject: [PATCH 1/5] Skip migrations one at a time --- src/yunohost/tools.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index baa614fa5..add114b99 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -938,6 +938,10 @@ def tools_migrations_migrate(target=None, skip=False, auto=False, accept_disclai operation_logger.success() + # Skip migrations one at a time + if skip: + break + # special case where we want to go back from the start if target == 0: state["last_run_migration"] = None From 3ca8c089e116b0d6a5344ffdec6ff106ec25140c Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 6 Dec 2018 18:33:39 +0100 Subject: [PATCH 2/5] 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 add114b99..f6535d85c 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -432,7 +432,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') @@ -948,7 +948,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 @@ -1048,6 +1047,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): From 791ac440375515b6ca4a1c5d53c2f1529bd9b47d Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 6 Dec 2018 22:10:06 +0100 Subject: [PATCH 3/5] Add success message after running migrations --- locales/en.json | 1 + src/yunohost/tools.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/locales/en.json b/locales/en.json index 6ce22ca80..3bb36ae9d 100644 --- a/locales/en.json +++ b/locales/en.json @@ -305,6 +305,7 @@ "migrations_show_currently_running_migration": "Running migration {number} {name}...", "migrations_show_last_migration": "Last ran migration is {}", "migrations_skip_migration": "Skipping migration {number} {name}...", + "migrations_success": "Successfully ran migration {number} {name}!", "migrations_to_be_ran_manually": "Migration {number} {name} has to be ran manually. Please go to Tools > Migrations on the webadmin, or run `yunohost tools migrations migrate`.", "migrations_need_to_accept_disclaimer": "To run the migration {number} {name}, your must accept the following disclaimer:\n---\n{disclaimer}\n---\nIf you accept to run the migration, please re-run the command with the option --accept-disclaimer.", "monitor_disabled": "The server monitoring has been disabled", diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index f6535d85c..fbadb3b20 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -924,6 +924,9 @@ def tools_migrations_migrate(target=None, skip=False, auto=False, accept_disclai logger.error(msg, exc_info=1) operation_logger.error(msg) break + else: + logger.success(m18n.n('migrations_success', + number=migration.number, name=migration.name)) else: # if skip logger.warn(m18n.n('migrations_skip_migration', From 0fa374db40171f6412b2cc4f10d1bb2dd7ffc014 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 6 Dec 2018 22:11:06 +0100 Subject: [PATCH 4/5] This message should be info --- src/yunohost/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index fbadb3b20..3bffe3606 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -903,7 +903,7 @@ def tools_migrations_migrate(target=None, skip=False, auto=False, accept_disclai if not skip: - logger.warn(m18n.n('migrations_show_currently_running_migration', + logger.info(m18n.n('migrations_show_currently_running_migration', number=migration.number, name=migration.name)) try: From 783ecf8f4158876be6192abf576f9acbef379268 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 6 Dec 2018 18:24:53 +0100 Subject: [PATCH 5/5] Manage migration of auto/manual and disclaimer on a per-migration basis --- src/yunohost/tools.py | 47 +++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 3bffe3606..d8cd53f56 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -872,31 +872,34 @@ def tools_migrations_migrate(target=None, skip=False, auto=False, accept_disclai else: # can't happen, this case is handle before raise Exception() - # If we are migrating in "automatic mode" (i.e. from debian - # configure during an upgrade of the package) but we are asked to run - # migrations is to be ran manually by the user - manual_migrations = [m for m in migrations if m.mode == "manual"] - if not skip and auto and manual_migrations: - for m in manual_migrations: - logger.warn(m18n.n('migrations_to_be_ran_manually', - number=m.number, - name=m.name)) - return - - # If some migrations have disclaimers, require the --accept-disclaimer - # option - migrations_with_disclaimer = [m for m in migrations if m.disclaimer] - if not skip and not accept_disclaimer and migrations_with_disclaimer: - for m in migrations_with_disclaimer: - logger.warn(m18n.n('migrations_need_to_accept_disclaimer', - number=m.number, - name=m.name, - disclaimer=m.disclaimer)) - return - # effectively run selected migrations for migration in migrations: + if not skip: + # If we are migrating in "automatic mode" (i.e. from debian configure + # during an upgrade of the package) but we are asked to run migrations + # to be ran manually by the user, stop there and ask the user to + # run the migration manually. + if auto and migration.mode == "manual": + logger.warn(m18n.n('migrations_to_be_ran_manually', + number=migration.number, + name=migration.name)) + break + + # If some migrations have disclaimers, + if migration.disclaimer: + # require the --accept-disclaimer option. Otherwise, stop everything + # here and display the disclaimer + if not accept_disclaimer: + logger.warn(m18n.n('migrations_need_to_accept_disclaimer', + number=migration.number, + name=migration.name, + disclaimer=migration.disclaimer)) + break + # --accept-disclaimer will only work for the first migration + else: + accept_disclaimer = False + # Start register change on system operation_logger= OperationLogger('tools_migrations_migrate_' + mode) operation_logger.start()