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

create_table force option drops table when if_not_exists option is present #51067

Closed
allisonphillips opened this issue Feb 13, 2024 · 0 comments · Fixed by #51513
Closed

create_table force option drops table when if_not_exists option is present #51067

allisonphillips opened this issue Feb 13, 2024 · 0 comments · Fixed by #51513

Comments

@allisonphillips
Copy link
Contributor

allisonphillips commented Feb 13, 2024

The problem is here:

def create_table(table_name, id: :primary_key, primary_key: nil, force: nil, **options, &block)
validate_create_table_options!(options)
validate_table_length!(table_name) unless options[:_uses_legacy_table_name]
td = build_create_table_definition(table_name, id: id, primary_key: primary_key, force: force, **options, &block)
if force
drop_table(table_name, force: force, if_exists: true)
else

I can't submit this from my work computer, but can somebody put up a PR to make this change to L299:

drop_table(table_name, force: force, if_exists: true) unless td.if_not_exists

Edge case where this occurs:
Adding guarded migrations to make migration schema consistent with schema dump for DB that has migrations applied to it that are not in the schema history.
If you copy the table definition from the schema dump and add the if_not_exists, running the migration will drop the table if it exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants