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

Add create_foreign_key migration utility #16077

Merged
merged 1 commit into from May 12, 2023

Conversation

jdavcs
Copy link
Member

@jdavcs jdavcs commented May 12, 2023

Required for #16003 (see discussion in backend channel)

This should be used when altering a table that includes adding a column with a foreign key constraint [ref].

So, this is incorrect:

def upgrade():
    add_column(my-table, my-column-with-foreign-key-passed-as-argument)

This is correct:

def upgrade():
    with transaction():
        add_column(my-table, my-column)
        create_foreign_key(fkey-name, table-name, ref-table-name, [columns], [ref-columns])

How to test the changes?

(Select all options that apply)

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. Add a revision that adds a column to an existing table that is a foreign key.
    2. Try using the incorrect version. Run upgrade, then downgrade. Observe error on SQLite (postgres is fine)
    3. You may have to run downgrade in repair mode to fix your database.
    4. Try using the correct version. Observe no error.

License

  • I agree to license these and all my past contributions to the core galaxy codebase under the MIT license.

@jdavcs jdavcs added kind/enhancement area/database Galaxy's database or data access layer labels May 12, 2023
@jdavcs jdavcs added this to the 23.1 milestone May 12, 2023
@jdavcs jdavcs requested a review from davelopez May 12, 2023 04:20
Copy link
Contributor

@davelopez davelopez left a comment

Choose a reason for hiding this comment

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

Many thanks for taking the time to look into this and for the quick fix! 🍻

@davelopez davelopez merged commit f98794d into galaxyproject:dev May 12, 2023
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/database Galaxy's database or data access layer kind/enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants