-
Notifications
You must be signed in to change notification settings - Fork 1
Integrating into an existing project
Plugging DbSchema into an existing project takes a little more time than setting a new project because you need to describe all already existing tables in your database, and currently DbSchema does not have a database dumper.
First you should follow the first 4 steps from the setting up a new project: add the gem to your Gemfile
and create an initializer file. In that file, though, you need to pass the dry_run: true
option to
DbSchema.configure
; that will make DbSchema make no real changes to your database - it will just output
what it would do in a normal mode.
Then you create a schema definition file and begin to describe your tables, fields and indexes. You can track
your progress by running the app occasionally and looking for the DbSchema output. Everything you have in your
database that you didn't yet described in your schema definition will pop out as some kind of DropSomething
operation;
the more you describe your schema the less changes you will see.
You can tell you've finished describing your schema when you see no changes. Or a single
#<DbSchema::Changes::DropTable :schema_migrations>
if you decided to get rid of ActiveRecord migrations altogether.
Now you can remove the dry_run: true
option and commit your changes; from now on you can change your schema definition
and watch the database changes accordingly.