简体   繁体   English

使用schema.rb快速构建用于测试的旧数据库

[英]Use schema.rb to quickly build legacy database for testing

I'm currently working on a system that is using two different databases. 我目前正在使用两个不同数据库的系统上工作。 One of them is new and that's where most things happen, but I'm using an old database from another rails app somewhere else. 其中之一是新的,并且大多数事情都在这里发生,但是我正在使用其他地方的另一个Rails应用程序中的旧数据库。 Therefore I don't have the migrations for the database in my project. 因此,我的项目中没有数据库的迁移。 However I would like to be able to set up a script on Jenkins which will allow me to set that up so I can do CI. 但是,我希望能够在Jenkins上设置脚本,这将允许我对其进行设置,以便可以进行CI。 My database.yml file basically looks like this: 我的database.yml文件基本上如下所示:

default: &default
  adapter: postgresql
  encoding: unicode
development:
  <<: *default
  database: proj_development
test:
  <<: *default
  database: proj_test
legacy_development:
  <<: *default
  database: legacy_development
legacy_test:
  <<: *default
  database: legacy_test

And I have a schema.rb from the old rails app that looks like this: 我从旧的Rails应用程序中获得了一个schema.rb,如下所示:

ActiveRecord::Schema.define(:version => 20140721152610) do 
  create_table "users", :force => true do |t|
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "password",                 :limit => 60
    t.string   "security_token",           :limit => 32
    t.text     "additional_information"
  end

  create_table "email_addresses", :force => true do |t|
    t.string   "email"
    t.datetime "verified_at"
    t.string   "status"
  end
end

Is there a way that I can run a command to load that schema and set it so that legacy_test gets built with that schema? 有没有一种方法可以运行命令以加载该架构并对其进行设置,以便使用该架构构建legacy_test? Some sort of rake db:schema:load --file=legacy_schema.rb --database=legacy_test 某种形式的rake db:schema:load --file=legacy_schema.rb --database=legacy_test

You can specify a custom schema file to load using SCHEMA . 您可以使用SCHEMA指定要加载的自定义架构文件。 So, to create the database defined in the legacy_development environment and load the custom schema use: 因此,要创建在legacy_development环境中定义的数据库并加载自定义架构,请使用:

rake db:create RAILS_ENV=legacy_development
rake db:schema:load RAILS_ENV=legacy_development SCHEMA=db/legacy_schema.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM