With Rails Minitest how do I recreate views on db migration for my test database?

293 views Asked by At

I'm using Rails 5 with Minitest 5.9.

I have some views in my application for complex queries.

Everytime I create a new migration my test database removes my views and I have to recreate them.

How do I automate the view recreation?

1

There are 1 answers

1
31piy On

I had a similar problem. We had some triggers on our DB, which could not be created by rails migration.

The solution we followed is using seeds. We defined our triggers in db/seeds.rb, and before running the tests, we ran rake db:reset. This dropped the DB, created it again, loaded the schema, and ran what's in db/seeds.rb.

Hope you can use the same.