Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use standalone migrations to prepare test database

  • Loading branch information...
commit 70695c2719e418a505a7680cbcfc65d60eb3f5ab 1 parent 03c1983
@thbar thbar authored
View
2  .standalone_migrations
@@ -0,0 +1,2 @@
+config:
+ database: test/config/database.yml
View
11 Rakefile
@@ -7,6 +7,12 @@ def system!(cmd)
raise "Command failed!" unless system(cmd)
end
+begin
+ require 'tasks/standalone_migrations'
+rescue LoadError => e
+ puts "gem install standalone_migrations to get db:migrate:* tasks! (Error: #{e})"
+end
+
# experimental tasks to reproduce the Travis behaviour locally
namespace :ci do
@@ -29,7 +35,10 @@ namespace :ci do
task :run_one, :db, :gemfile do |t, args|
ENV['BUNDLE_GEMFILE'] = File.expand_path(args[:gemfile] || (File.dirname(__FILE__) + '/test/config/gemfiles/Gemfile.rails-3.2.x'))
ENV['DB'] = args[:db] || 'mysql2'
- system! "bundle install && bundle exec rake"
+ system! "bundle install"
+ # trick: pass RAILS_ENV to force the db to be created by standalone migrations
+ system! "bundle exec rake db:create RAILS_ENV=#{ENV['DB']}"
+ system! "bundle exec rake db:schema:load RAILS_ENV=#{ENV['DB']}"
end
desc "For current RVM, run the tests for all the combination in travis configuration"
View
37 db/migrate/20120229203554_create_tables.rb
@@ -0,0 +1,37 @@
+class CreateTables < ActiveRecord::Migration
+ def self.up
+ create_table(:people, :force => true) do |t|
+ t.column :first_name, :string
+ t.column :last_name, :string
+ t.column :ssn, :string, :limit => 64
+ end
+
+ create_table(:places, :force => true) do |t|
+ t.column :address, :text
+ t.column :city, :string
+ t.column :state, :string
+ t.column :country, :string, :limit => 2
+ end
+
+ create_table(:person_dimension, :force => true) do |t|
+ t.column :first_name, :string, :limit => 50
+ t.column :last_name, :string, :limit => 50
+ t.column :address, :string, :limit => 100
+ t.column :city, :string, :limit => 50
+ t.column :state, :string, :limit => 50
+ t.column :zip_code, :string, :limit => 20
+
+ t.column :effective_date, :timestamp
+ t.column :end_date, :timestamp
+ t.column :latest_version, :boolean
+ end
+
+ create_table(:truncate_test, :force => true) do |t|
+ t.column :x, :string, :limit => 4
+ end
+ end
+
+ def self.down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
View
45 db/schema.rb
@@ -0,0 +1,45 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120229203554) do
+
+ create_table "people", :force => true do |t|
+ t.string "first_name"
+ t.string "last_name"
+ t.string "ssn", :limit => 64
+ end
+
+ create_table "person_dimension", :force => true do |t|
+ t.string "first_name", :limit => 50
+ t.string "last_name", :limit => 50
+ t.string "address", :limit => 100
+ t.string "city", :limit => 50
+ t.string "state", :limit => 50
+ t.string "zip_code", :limit => 20
+ t.datetime "effective_date"
+ t.datetime "end_date"
+ t.boolean "latest_version"
+ end
+
+ create_table "places", :force => true do |t|
+ t.text "address"
+ t.string "city"
+ t.string "state"
+ t.string "country", :limit => 2
+ end
+
+ create_table "truncate_test", :force => true do |t|
+ t.string "x", :limit => 4
+ end
+
+end
View
2  test/config/gemfiles/common.rb
@@ -26,4 +26,6 @@ def declare_gems(activerecord_version)
gem 'spreadsheet'
gem 'nokogiri'
gem 'fastercsv'
+
+ gem 'standalone_migrations'
end
Please sign in to comment.
Something went wrong with that request. Please try again.