Add if_not_exists to create_view and if_exists to drop_view#382
Add if_not_exists to create_view and if_exists to drop_view#382serg-kovalev wants to merge 1 commit intoscenic-views:mainfrom
Conversation
380eccf to
e145024
Compare
There was a problem hiding this comment.
Some files could not be reviewed due to errors:
Warning: unrecognized cop Layout/ParameterAlignment found in .rubocop.yml
Warning: unrecognized cop Layout/ParameterAlignment found in .rubocop.yml Warning: unrecognized cop Layout/AssignmentIndentation found in .rubocop.yml Warning: unrecognized cop Lint/DuplicateHashKey found in .rubocop.yml Error: Unknown Ruby version 2.7 found in `TargetRubyVersion` parameter (in .rubocop.yml). Supported versions: 2.1, 2.2, 2.3, 2.4, 2.5
210d552 to
f4da7c1
Compare
|
@derekprior Hi! Hope you are well. |
6b76770 to
5863bee
Compare
|
Can you say more about this?
Conceptually, one of the ideas of Scenic is that careful management of your schema using Scenic means you have certainty around your database state. |
@derekprior Sure! class CreateSomeView < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
create_view :mv_some_name, materialized: true
safety_assured do
add_index :mv_some_name, :receipt_uuid, unique: true, algorithm: :concurrently
add_index :mv_some_name, :invoice_number, algorithm: :concurrently
end
end
def down
drop_view :mv_some_name, materialized: true
end
endAs it's recommended to update indexes concurrently out of a transaction, those operations may accidentally fail. It happens very rarely, but we faced it several times. As a result, migration will stuck and it will require manual resolution. The change that I made doesn't bring some level of uncertainty, I think. As by default, we do everything like we did before, but if we really need to make it a bit flexible, we now can do that. Please let me know if it makes sense. |
5863bee to
b401623
Compare
|
@derekprior Hey! Hope you are doing well. Have you had a chance to take a look? |
Provide an ability to pass
if_not_existsparam for view creation. It's handy to have it when you disable_ddl_transaction in Rails migration and add indexes concurrently.And similar functionality with
if_existsparam to drop a view.For instance we have a migration like that:
As it's recommended to update indexes concurrently out of a transaction, those operations may accidentally fail. It happens very rarely, but we faced it several times. As a result, migration will stuck and it will require manual resolution.
The change that I made doesn't bring some level of uncertainty, I think. As by default, we do everything like we did before, but if we really need to make it a bit flexible, we now can do that.
Please let me know if it makes sense.
Thank you in advance!