[英]Use schema.rb to quickly build legacy database for testing
我目前正在使用兩個不同數據庫的系統上工作。 其中之一是新的,並且大多數事情都在這里發生,但是我正在使用其他地方的另一個Rails應用程序中的舊數據庫。 因此,我的項目中沒有數據庫的遷移。 但是,我希望能夠在Jenkins上設置腳本,這將允許我對其進行設置,以便可以進行CI。 我的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
我從舊的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
有沒有一種方法可以運行命令以加載該架構並對其進行設置,以便使用該架構構建legacy_test? 某種形式的rake db:schema:load --file=legacy_schema.rb --database=legacy_test
您可以使用SCHEMA
指定要加載的自定義架構文件。 因此,要創建在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.