diff --git a/changes/7681.misc b/changes/7681.misc new file mode 100644 index 00000000000..4bbaf359916 --- /dev/null +++ b/changes/7681.misc @@ -0,0 +1 @@ +Fix errors when running the `ckan db upgrade` command diff --git a/ckan/config/environment.py b/ckan/config/environment.py index 81de2a01d8f..e137df7ba19 100644 --- a/ckan/config/environment.py +++ b/ckan/config/environment.py @@ -249,6 +249,11 @@ def update_config() -> None: if user_table_exists: try: logic.get_action('get_site_user')({'ignore_auth': True}, {}) + except sqlalchemy.exc.ProgrammingError as e: + if "UndefinedColumn" in repr(e.orig): + log.debug("Old user model detected") + else: + raise except sqlalchemy.exc.IntegrityError: # Race condition, user already exists. log.debug("Site user already exists") diff --git a/ckan/migration/migrate_package_activity.py b/ckan/migration/migrate_package_activity.py index 0cfd026cb9c..2e80c0d6611 100644 --- a/ckan/migration/migrate_package_activity.py +++ b/ckan/migration/migrate_package_activity.py @@ -32,6 +32,7 @@ import argparse from collections import defaultdict from typing import Any +import sys # not importing anything from ckan until after the arg parsing, to fail on bad @@ -274,6 +275,8 @@ def print_errors(errors): args = parser.parse_args() assert args.config, u'You must supply a --config' print(u'Loading config') + + from ckan.plugins import plugin_loaded try: from ckan.cli import load_config from ckan.config.middleware import make_app @@ -291,6 +294,12 @@ class Options(object): cmd._load_config() return load_config(args.config) + + if not plugin_loaded("activity"): + print( + "Please add the `activity` plugin to your `ckan.plugins` setting") + sys.exit(1) + if not args.dataset: migrate_all_datasets() wipe_activity_detail(delete_activity_detail=args.delete) diff --git a/ckan/migration/revision_legacy_code.py b/ckan/migration/revision_legacy_code.py index 2ad600e35f9..25e0fa9cb67 100644 --- a/ckan/migration/revision_legacy_code.py +++ b/ckan/migration/revision_legacy_code.py @@ -26,7 +26,7 @@ # This is based on ckan.lib.dictization.model_dictize:package_dictize # BUT you can ask for a old revision to the package by specifying 'revision_id' # in the context -def package_dictize_with_revisions(pkg, context): +def package_dictize_with_revisions(pkg, context, include_plugin_data=False): ''' Given a Package object, returns an equivalent dictionary. @@ -306,7 +306,8 @@ def copy_table_columns(table): # Copied from vdm def copy_table(table, newtable): for key in table.c.keys(): - copy_column(key, table, newtable) + if key != "plugin_data": + copy_column(key, table, newtable) # Copied from vdm @@ -325,8 +326,7 @@ def make_revision_table(metadata): # Copied from vdm def make_Revision(mapper, revision_table): # noqa - mapper(Revision, revision_table, properties={}, - order_by=revision_table.c.timestamp.desc()) + mapper(Revision, revision_table, properties={}) return Revision