I noticed that Rails creates triggers in the development db but not the test db since it creates the test db from schema.rb instead of running migrations. I have a trigger (as a migration) and need to test that it does the right thing, how can I do that? I tried adding the trigger manually to the test db but that didn’t work.
Share
By default rails sets up the test database using the database independant schema.rb, which doesn’t understand stuff like triggers.
If you change
config.active_record_schema_formatto:sqlthen rails will instead dump the raw SQL that represents the development database’s structure and use that to recreate the test database. This dump is placed in development.sql, which is then used instead of schema.rbThis dump is done using the command line tools that your db provides and so will respect features like triggers that active record isn’t aware of