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

Improve schema config migration utils #5475

Merged
merged 4 commits into from
Dec 16, 2024
Merged

Improve schema config migration utils #5475

merged 4 commits into from
Dec 16, 2024

Conversation

sharadsw
Copy link
Contributor

@sharadsw sharadsw commented Dec 13, 2024

Fixes #5469

  • Fields that don't exist in the latest state of the datamodel will be skipped when creating Schema Config entries
  • Changed the util functions to use get_or_create() instead of create() to avoid duplicate Schema Config entries. Ideally, we should no longer need to revert an entry before adding it anymore like here:
    def update_schema_config(apps):
    # Revert before adding to avoid duplicates
    revert_update(apps)
    Discipline = apps.get_model('specify', 'Discipline')
    for discipline in Discipline.objects.all():
    update_table_field_schema_config_with_defaults('AbsoluteAge', discipline.id, 'version', apps)
    update_table_field_schema_config_with_defaults('RelativeAge', discipline.id, 'version', apps)

Checklist

  • Self-review the PR after opening it to make sure the changes look good
    and self-explanatory (or properly documented)
  • Add automated tests
  • Add relevant issue to release milestone

Testing instructions

Dev testing only?

  • Try to apply the 0013 migration manually
  • Verify there are no errors (there will be a warning for adding COG -> parentCog)

Copy link
Contributor

@melton-jason melton-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lot of nice changes here!
I haven't tested the changes yet, but the code looks good.

specifyweb/specify/migration_utils/update_schema_config.py Outdated Show resolved Hide resolved
Copy link
Member

@grantfitzsimmons grantfitzsimmons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with a database that has never been used in development (last used on v7.9.6.2):

specify7-1         |   Applying specify.0002_geo... OK
specify7-1         |   Applying businessrules.0003_catnum_constraint... OK
specify7-1         |   Applying businessrules.0004_catnum_uniquerule... OK
specify7-1         |   Applying businessrules.0005_cojo... OK
specify7-1         |   Applying specify.0003_cotype_picklist... OK
specify7-1         |   Applying specify.0004_stratigraphy_age... OK
specify7-1         |   Applying specify.0005_collectionobjectgroup_parentcojo... OK
specify7-1         |   Applying specify.0006_fix_tectonic_tree_fields... OK
specify7-1         |   Applying specify.0007_schema_config_update... OK
specify7-1         |   Applying specify.0008_ageCitations_fix... OK
specify7-1         |   Applying specify.0009_tectonic_ranks... OK
specify7-1         |   Applying specify.0010_updateDelete_parentcojo... OK
specify7-1         |   Applying specify.0011_cascading_tree_nodes... OK
specify7-1         |   Applying specify.0012_add_cojo_to_schema_config... OK
specify7-1         | [16/Dec/2024 15:42:21] [WARNING] [specifyweb.specify.migration_utils.update_schema_config:164] Field does not exist in latest state of the datamodel, skipping Schema Config entry for: CollectionObjectGroup -> parentCog
specify7-1         |   Applying specify.0013_collectionobjectgroup_parentcog... OK
specify7-1         |   Applying specify.0014_spqueryfield_strict... OK
specify7-1         |   Applying specify.0015_add_version_to_ages... OK
specify7-1         |   Applying specify.0016_collectionobjecttype_catalognumformatname... OK
specify7-1         |   Applying specify.0017_schemaconfig_fixes... OK
specify7-1         |   Applying specify.0018_cot_catnum_schema... OK
specify7-1         |   Applying specify.0019_remove_parentCog... OK
specify7-1         | Watching for file changes with StatReloader

👍

@sharadsw sharadsw merged commit b69dac3 into production Dec 16, 2024
12 checks passed
@sharadsw sharadsw deleted the issue-5469 branch December 16, 2024 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

0013_collectionobjectgroup_parentcog migration always fails
5 participants