Reputation: 573
Is there a way to run rails server
in sandboxed mode?
I would want all the changes made on the rails app to be rolled back after the server is stopped.
For example, doing the command rails console --sandbox
.
Upvotes: 18
Views: 4195
Reputation: 573
My own answer for this:
When you get the state you want to keep on your database, you should dump only the data to a SQL file and place it as a seeds file:
db/seeds.sql
After that every time you want to back to the initial state you should run:
bundle exec rails db:reset && bundle exec rails server
Upvotes: 1
Reputation: 3048
There's no build in way to do this. You can start rails console in sandbox mode (rails c -s), but not server.
But... If the changes you want to be rolled back, are only changes in your data, you can just write your seeds data and populate database with them every time you run server.
Upvotes: 5