开发者

Can I generate a ruby on rails database migration file from a MySQL sql file

开发者 https://www.devze.com 2022-12-28 17:25 出处:网络
开发者_运维百科I have a sql script file that upon import creates a table in a MySQL database and fills it with 2800 record. These are all the postal codes for the country Belgium.

开发者_运维百科I have a sql script file that upon import creates a table in a MySQL database and fills it with 2800 record. These are all the postal codes for the country Belgium.

Now I would like to make a Ruby on Rails database migration file from this. Any idea how I can do this?

Maybe there is a way around? Telling in a database migration file to execute a separate sql script?

Thanks, Michael


If your config/database.yml is referencing the MySQL database with the schema, then do

rake db:schema:dump

That will create a db/schema.rb file which is database independent.

Copy schema.rb into db/migrate/001_original_schema.rb:

class OriginalDatabaseMigration < ActiveRecord::Migration
  def self.up
    # schema.rb here
  end

  def self.down
    # drop all the tables
  end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号