You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a case where I want to lock the table the triggers are triggered on because I want to make sure nothing gets inserted, updated or deleted while the triggers are dropped and created.
Initially I started with just a execute('LOCK TABLES table WRITE;') at the start of the up and down methods.
But this changes the definition of the methods and after migrating the following warning is added to the schema.rb. And a generic execute with CREATE TRIGGER statement is used instead of the hair_trigger DSL.
WARNING: generating adapter-specific definition for table_after_insert_row_tr due to a mismatch. either there's a bug in hairtrigger or you've messed up your migrations and/or db :-/
To ensure we are still using the hair_trigger DSL and won't have this waning in our schema I created the following workaround:
moduleWrapUpAndDownWithLocksdefupexecute('LOCK TABLES table WRITE;')superensureexecute('UNLOCK TABLES;')enddefdownexecute('LOCK TABLES table WRITE;')superensureexecute('UNLOCK TABLES;')endendclassCreateTriggersTableInsertOrTableUpdateOrTableDelete < ActiveRecord::Migration[7.0]prependWrapUpAndDownWithLocksdefup# migration generated by hair_triggerenddefdown# migration generated by hair_triggerendend
Its a bit hacky but gets the job done. Not sure if this problem is something that should be solved by the gem itself. But I wanted to share my solution here for anyone else running into this.
The text was updated successfully, but these errors were encountered:
Hi!
There is a case where I want to lock the table the triggers are triggered on because I want to make sure nothing gets inserted, updated or deleted while the triggers are dropped and created.
Initially I started with just a
execute('LOCK TABLES table WRITE;')
at the start of theup
anddown
methods.But this changes the definition of the methods and after migrating the following warning is added to the schema.rb. And a generic
execute
withCREATE TRIGGER
statement is used instead of the hair_trigger DSL.To ensure we are still using the hair_trigger DSL and won't have this waning in our schema I created the following workaround:
Its a bit hacky but gets the job done. Not sure if this problem is something that should be solved by the gem itself. But I wanted to share my solution here for anyone else running into this.
The text was updated successfully, but these errors were encountered: