Skip to content

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
@jdavcs jdavcs force-pushed the dev_migrations_fkey branch from f425244 to 6a0b042 Compare May 12, 2023 04:52
@jdavcs jdavcs force-pushed the dev_migrations_fkey branch from 6a0b042 to 40d9427 Compare May 12, 2023 04:55
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
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.

2 participants