Rails test with triggers
I noticed that Rails creates triggers in the development db, but does not test the db as it creates the test db from schema.rb instead of running the migration. I have a trigger (like a migration) and need to check that it is doing everything correctly, how can I do this? I tried adding the trigger manually to the test db, but it didn't work.
source to share
By default rails installs a test database using an independent database schema.rb which doesn't understand things like triggers.
If you change config.active_record_schema_format
to :sql
, then rails will instead dump the raw SQL that represents the development database structure and use that to recreate the test database. This dump is put into development.sql which is then used instead of schema.rb
This dump is done with the command line tools your db provides and will therefore respect features like triggers that the active writer is not aware of
source to share
If you prefer Ruby dumps for SQL dumps, you can try this gem:
https://github.com/jovoto-team/trackless_triggers
It supports load triggers and functions for mysql.
source to share