Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ckan db upgrade fixes #7681

Merged
merged 5 commits into from Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/7681.misc
@@ -0,0 +1 @@
Fix errors when running the `ckan db upgrade` command
5 changes: 5 additions & 0 deletions ckan/config/environment.py
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions ckan/migration/migrate_package_activity.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions ckan/migration/revision_legacy_code.py
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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


Expand Down