Parry
Parry

Reputation: 187

Deleted all Rails Migrations and dropped the database

I have a rails 5 app with PostgreSQL as database, and I for some reason have dropped the database and also deleted all the migration files in db/migrate folder. Is there any way to generate a single migration file based on models and views without generating individual migration files specifying the columns to rebuild the database?

Upvotes: 0

Views: 68

Answers (1)

ocodo
ocodo

Reputation: 30319

If you have the db/schema.rb you can setup the database from there.

rails db:schema:load

Will setup the database from the schema.

It is also relatively simple to convert the schema.rb to an initial setup migration, effectively you copy everything that's inside ActiveRecord::Schema.define(version: timestamp) do block

Then paste it into a new migration inside a def up ... end method.

This is also the exact time to get your project into git version control and avoid nightmare situations like this again.

Upvotes: 6

Related Questions