-
Notifications
You must be signed in to change notification settings - Fork 53
fix: Avoid dumping unique_constraint when attisdropped #349
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still doesn't handle the indexes with where clauses, for example:
ActiveRecord::Schema.define do
create_table :payments, force: true do |t|
t.text 'name'
t.timestamp 'deleted_at'
t.index 'lower(name::STRING) ASC', name: 'lower_name_index_on_payments', unique: true
t.index ['name'], name: 'index_payments_on_name', unique: true, where: '(deleted_at IS NULL)'
end
endWill result in a schema dump that lacks deleted_at IS NULL:
ActiveRecord::Schema[7.2].define(version: 0) do
create_table "payments", force: :cascade do |t|
t.text "name"
t.datetime "deleted_at", precision: nil
t.index "lower(name) ASC", name: "lower_name_index_on_payments", unique: true
t.unique_constraint ["name"], name: "index_payments_on_name"
end
end| deferrable: deferrable | ||
| } | ||
|
|
||
| UniqueConstraintDefinition.new(table_name, columns, options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be:
| UniqueConstraintDefinition.new(table_name, columns, options) | |
| ActiveRecord::ConnectionAdapters::PostgreSQL::UniqueConstraintDefinition.new(table_name, columns, options) |
(https://www.cockroachlabs.com/docs/stable/unique) I think we can just consider every The UNIQUE constraint depends on the automatically created index, so dropping the index also drops the UNIQUE constraint. Conversely, dropping the UNIQUE constraint also drops the automatically created index. |
61fdcef to
c223ba1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for this fix!
Fixes #347