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

前端 未结 1 1619
礼貌的吻别
礼貌的吻别 2021-01-06 14:15

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.

相关标签:
1条回答
  • 2021-01-06 14:43

    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 讨论(0)
提交回复
热议问题