How to create migration for an obsolete database?

I am currently developing a Rails application using a database that was developed before I learned about the existence of Rails.
I have currently created some migrations to add new tables and new columns to existing tables.

I would like to have a migration to recreate the complete database.

What steps should I follow?
Should I create all migrations manually?

EDIT: I'm interested in the database schema not in the contents of the database

+1
source share
3 answers

I think it will require some manual work.

rake db:schema:dump, db/schema.rb . , , db/schema.rb, . , . , RAILS_ENV rake (.. RAILS_ENV=production rake db:schema:dump)

schema.rb , . , , .

+3

, PHP . , , . . rake db: schema: dump db/schema.rb - db/schema_base.rb. . :

class CreateTables < ActiveRecord::Migration
  def self.up
    `cp #{Rails.root}/db/schema_base.rb #{Rails.root}/db/schema.rb`
    Rake::Task['db:schema:load'].invoke
  end

  def self.down
  end
end

, . , Rails. , , , ..
, , .

+7

:

Long answer: it depends on how the database was configured and how different it is from the current one. In addition, since I assume that the identifier is generated dynamically - if you are moving from one table to another, make sure that all your foreign keys are updated correctly.

Write a script that recreates the entire database from the old data. If you posted your database schema and a new database schema, I would be happy to help you :)

+1
source

All Articles