2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-12-07 11:34:29 -05:00
|
|
|
require "isolation/abstract_unit"
|
|
|
|
|
|
|
|
module ApplicationTests
|
|
|
|
module RakeTests
|
2012-01-05 20:30:17 -05:00
|
|
|
class RakeMigrationsTest < ActiveSupport::TestCase
|
2011-12-07 11:34:29 -05:00
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
FileUtils.rm_rf("#{app_path}/config/environments")
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
2011-12-09 14:53:55 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "running migrations with given scope" do
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "generate", "model", "user", "username:string", "password:string"
|
2011-12-09 14:53:55 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
app_file "db/migrate/01_a_migration.bukkits.rb", <<-MIGRATION
|
|
|
|
class AMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
2012-03-08 17:32:41 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate", "SCOPE=bukkits")
|
|
|
|
assert_no_match(/create_table\(:users\)/, output)
|
|
|
|
assert_no_match(/CreateUsers/, output)
|
|
|
|
assert_no_match(/add_column\(:users, :email, :string\)/, output)
|
2011-12-09 14:53:55 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/AMigration: migrated/, output)
|
2011-12-09 14:53:55 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate", "SCOPE=bukkits", "VERSION=0")
|
|
|
|
assert_no_match(/drop_table\(:users\)/, output)
|
|
|
|
assert_no_match(/CreateUsers/, output)
|
|
|
|
assert_no_match(/remove_column\(:users, :email\)/, output)
|
2011-12-09 14:53:55 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/AMigration: reverted/, output)
|
2011-12-09 14:53:55 -05:00
|
|
|
end
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-25 17:10:17 -04:00
|
|
|
test "migrate with specified VERSION in different formats" do
|
|
|
|
app_file "db/migrate/01_one_migration.rb", <<-MIGRATION
|
|
|
|
class OneMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
|
|
|
app_file "db/migrate/02_two_migration.rb", <<-MIGRATION
|
|
|
|
class TwoMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
|
|
|
app_file "db/migrate/03_three_migration.rb", <<-MIGRATION
|
|
|
|
class ThreeMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
|
|
|
rails "db:migrate"
|
|
|
|
|
|
|
|
output = rails("db:migrate:status")
|
|
|
|
assert_match(/up\s+001\s+One migration/, output)
|
|
|
|
assert_match(/up\s+002\s+Two migration/, output)
|
|
|
|
assert_match(/up\s+003\s+Three migration/, output)
|
|
|
|
|
|
|
|
rails "db:migrate", "VERSION=01_one_migration.rb"
|
|
|
|
output = rails("db:migrate:status")
|
|
|
|
assert_match(/up\s+001\s+One migration/, output)
|
|
|
|
assert_match(/down\s+002\s+Two migration/, output)
|
|
|
|
assert_match(/down\s+003\s+Three migration/, output)
|
|
|
|
|
|
|
|
rails "db:migrate", "VERSION=3"
|
|
|
|
output = rails("db:migrate:status")
|
|
|
|
assert_match(/up\s+001\s+One migration/, output)
|
|
|
|
assert_match(/up\s+002\s+Two migration/, output)
|
|
|
|
assert_match(/up\s+003\s+Three migration/, output)
|
|
|
|
|
|
|
|
rails "db:migrate", "VERSION=001"
|
|
|
|
output = rails("db:migrate:status")
|
|
|
|
assert_match(/up\s+001\s+One migration/, output)
|
|
|
|
assert_match(/down\s+002\s+Two migration/, output)
|
|
|
|
assert_match(/down\s+003\s+Three migration/, output)
|
|
|
|
end
|
|
|
|
|
2017-03-19 22:39:14 -04:00
|
|
|
test "migration with empty version" do
|
2017-09-25 17:10:17 -04:00
|
|
|
app_file "db/migrate/01_one_migration.rb", <<-MIGRATION
|
|
|
|
class OneMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
|
|
|
app_file "db/migrate/02_two_migration.rb", <<-MIGRATION
|
|
|
|
class TwoMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
|
|
|
rails("db:migrate", "VERSION=")
|
|
|
|
|
|
|
|
output = rails("db:migrate:status")
|
|
|
|
assert_match(/up\s+001\s+One migration/, output)
|
|
|
|
assert_match(/up\s+002\s+Two migration/, output)
|
2017-03-19 22:39:14 -04:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:redo", "VERSION=", allow_failure: true)
|
|
|
|
assert_match(/Empty VERSION provided/, output)
|
2017-03-19 22:39:14 -04:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:up", "VERSION=", allow_failure: true)
|
|
|
|
assert_match(/VERSION is required/, output)
|
2017-03-19 22:39:14 -04:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:up", allow_failure: true)
|
|
|
|
assert_match(/VERSION is required/, output)
|
2017-04-27 13:21:15 -04:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:down", "VERSION=", allow_failure: true)
|
|
|
|
assert_match(/VERSION is required - To go down one migration, use db:rollback/, output)
|
2017-04-27 13:21:15 -04:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:down", allow_failure: true)
|
|
|
|
assert_match(/VERSION is required - To go down one migration, use db:rollback/, output)
|
2017-09-25 17:10:17 -04:00
|
|
|
|
|
|
|
output = rails("db:migrate:status")
|
|
|
|
assert_match(/up\s+001\s+One migration/, output)
|
|
|
|
assert_match(/up\s+002\s+Two migration/, output)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "migration with 0 version" do
|
|
|
|
app_file "db/migrate/01_one_migration.rb", <<-MIGRATION
|
|
|
|
class OneMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
|
|
|
app_file "db/migrate/02_two_migration.rb", <<-MIGRATION
|
|
|
|
class TwoMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
|
|
|
rails "db:migrate"
|
|
|
|
|
|
|
|
output = rails("db:migrate:status")
|
|
|
|
assert_match(/up\s+001\s+One migration/, output)
|
|
|
|
assert_match(/up\s+002\s+Two migration/, output)
|
|
|
|
|
|
|
|
rails "db:migrate", "VERSION=0"
|
|
|
|
|
|
|
|
output = rails("db:migrate:status")
|
|
|
|
assert_match(/down\s+001\s+One migration/, output)
|
|
|
|
assert_match(/down\s+002\s+Two migration/, output)
|
2017-03-19 22:39:14 -04:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "model and migration generator with change syntax" do
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "generate", "model", "user", "username:string", "password:string"
|
|
|
|
rails "generate", "migration", "add_email_to_users", "email:string"
|
|
|
|
|
|
|
|
output = rails("db:migrate")
|
|
|
|
assert_match(/create_table\(:users\)/, output)
|
|
|
|
assert_match(/CreateUsers: migrated/, output)
|
|
|
|
assert_match(/add_column\(:users, :email, :string\)/, output)
|
|
|
|
assert_match(/AddEmailToUsers: migrated/, output)
|
|
|
|
|
|
|
|
output = rails("db:rollback", "STEP=2")
|
|
|
|
assert_match(/drop_table\(:users\)/, output)
|
|
|
|
assert_match(/CreateUsers: reverted/, output)
|
|
|
|
assert_match(/remove_column\(:users, :email, :string\)/, output)
|
|
|
|
assert_match(/AddEmailToUsers: reverted/, output)
|
2011-12-09 15:19:49 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "migration status when schema migrations table is not present" do
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("db:migrate:status", allow_failure: true)
|
2011-12-09 15:19:49 -05:00
|
|
|
assert_equal "Schema migrations table does not exist yet.\n", output
|
|
|
|
end
|
|
|
|
|
2017-04-06 19:40:52 -04:00
|
|
|
test "migration status" do
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "generate", "model", "user", "username:string", "password:string"
|
|
|
|
rails "generate", "migration", "add_email_to_users", "email:string"
|
|
|
|
rails "db:migrate"
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:status")
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{14}\s+Add email to users/, output)
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "db:rollback", "STEP=1"
|
|
|
|
output = rails("db:migrate:status")
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/down\s+\d{14}\s+Add email to users/, output)
|
2011-12-09 15:19:49 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "migration status without timestamps" do
|
|
|
|
add_to_config("config.active_record.timestamped_migrations = false")
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "generate", "model", "user", "username:string", "password:string"
|
|
|
|
rails "generate", "migration", "add_email_to_users", "email:string"
|
|
|
|
rails "db:migrate"
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:status")
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+\d{3,}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{3,}\s+Add email to users/, output)
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "db:rollback", "STEP=1"
|
|
|
|
output = rails("db:migrate:status")
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+\d{3,}\s+Create users/, output)
|
|
|
|
assert_match(/down\s+\d{3,}\s+Add email to users/, output)
|
2012-02-17 10:56:57 -05:00
|
|
|
end
|
|
|
|
|
2017-04-06 19:40:52 -04:00
|
|
|
test "migration status after rollback and redo" do
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "generate", "model", "user", "username:string", "password:string"
|
|
|
|
rails "generate", "migration", "add_email_to_users", "email:string"
|
|
|
|
rails "db:migrate"
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:status")
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{14}\s+Add email to users/, output)
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "db:rollback", "STEP=2"
|
|
|
|
output = rails("db:migrate:status")
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/down\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/down\s+\d{14}\s+Add email to users/, output)
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "db:migrate:redo"
|
|
|
|
output = rails("db:migrate:status")
|
2011-12-09 15:19:49 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{14}\s+Add email to users/, output)
|
2011-12-09 15:19:49 -05:00
|
|
|
end
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-02-25 10:49:32 -05:00
|
|
|
test "migration status after rollback and forward" do
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "generate", "model", "user", "username:string", "password:string"
|
|
|
|
rails "generate", "migration", "add_email_to_users", "email:string"
|
|
|
|
rails "db:migrate"
|
2017-02-25 10:49:32 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:status")
|
2017-02-25 10:49:32 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{14}\s+Add email to users/, output)
|
2017-02-25 10:49:32 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "db:rollback", "STEP=2"
|
|
|
|
output = rails("db:migrate:status")
|
2017-02-25 10:49:32 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/down\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/down\s+\d{14}\s+Add email to users/, output)
|
2017-02-25 10:49:32 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "db:forward", "STEP=2"
|
|
|
|
output = rails("db:migrate:status")
|
2017-02-25 10:49:32 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{14}\s+Add email to users/, output)
|
2017-02-25 10:49:32 -05:00
|
|
|
end
|
|
|
|
|
2017-02-25 12:32:50 -05:00
|
|
|
test "raise error on any move when current migration does not exist" do
|
|
|
|
Dir.chdir(app_path) do
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "model", "user", "username:string", "password:string"
|
|
|
|
rails "generate", "migration", "add_email_to_users", "email:string"
|
|
|
|
rails "db:migrate"
|
|
|
|
`rm db/migrate/*email*.rb`
|
2017-02-25 12:32:50 -05:00
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("db:migrate:status")
|
2017-02-25 12:32:50 -05:00
|
|
|
assert_match(/up\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{14}\s+\** NO FILE \**/, output)
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("db:rollback", allow_failure: true)
|
2017-02-25 12:32:50 -05:00
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/ActiveRecord::UnknownMigrationVersionError:/, output)
|
|
|
|
assert_match(/No migration with version number\s\d{14}\./, output)
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("db:migrate:status")
|
2017-02-25 12:32:50 -05:00
|
|
|
assert_match(/up\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{14}\s+\** NO FILE \**/, output)
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("db:forward", allow_failure: true)
|
2017-02-25 12:32:50 -05:00
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/ActiveRecord::UnknownMigrationVersionError:/, output)
|
|
|
|
assert_match(/No migration with version number\s\d{14}\./, output)
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("db:migrate:status")
|
2017-02-25 12:32:50 -05:00
|
|
|
assert_match(/up\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{14}\s+\** NO FILE \**/, output)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-25 17:10:17 -04:00
|
|
|
test "raise error on any move when target migration does not exist" do
|
|
|
|
app_file "db/migrate/01_one_migration.rb", <<-MIGRATION
|
|
|
|
class OneMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
|
|
|
app_file "db/migrate/02_two_migration.rb", <<-MIGRATION
|
|
|
|
class TwoMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
|
|
|
|
|
|
|
rails "db:migrate"
|
|
|
|
|
|
|
|
output = rails("db:migrate:status")
|
|
|
|
assert_match(/up\s+001\s+One migration/, output)
|
|
|
|
assert_match(/up\s+002\s+Two migration/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate", "VERSION=3", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/ActiveRecord::UnknownMigrationVersionError:/, output)
|
|
|
|
assert_match(/No migration with version number 3/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate:status")
|
|
|
|
assert_match(/up\s+001\s+One migration/, output)
|
|
|
|
assert_match(/up\s+002\s+Two migration/, output)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "raise error on any move when VERSION has invalid format" do
|
|
|
|
output = rails("db:migrate", "VERSION=unknown", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/Invalid format of target version/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate", "VERSION=0.1.11", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/Invalid format of target version/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate", "VERSION=1.1.11", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/Invalid format of target version/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate", "VERSION='0 '", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/Invalid format of target version/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate", "VERSION=1.", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/Invalid format of target version/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate", "VERSION=1_", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/Invalid format of target version/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate", "VERSION=1_name", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/Invalid format of target version/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate:redo", "VERSION=unknown", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/Invalid format of target version/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate:up", "VERSION=unknown", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/Invalid format of target version/, output)
|
|
|
|
|
|
|
|
output = rails("db:migrate:down", "VERSION=unknown", allow_failure: true)
|
|
|
|
assert_match(/rails aborted!/, output)
|
|
|
|
assert_match(/Invalid format of target version/, output)
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "migration status after rollback and redo without timestamps" do
|
|
|
|
add_to_config("config.active_record.timestamped_migrations = false")
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "generate", "model", "user", "username:string", "password:string"
|
|
|
|
rails "generate", "migration", "add_email_to_users", "email:string"
|
|
|
|
rails "db:migrate"
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:status")
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+\d{3,}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{3,}\s+Add email to users/, output)
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "db:rollback", "STEP=2"
|
|
|
|
output = rails("db:migrate:status")
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/down\s+\d{3,}\s+Create users/, output)
|
|
|
|
assert_match(/down\s+\d{3,}\s+Add email to users/, output)
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "db:migrate:redo"
|
|
|
|
output = rails("db:migrate:status")
|
2012-02-17 10:56:57 -05:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+\d{3,}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{3,}\s+Add email to users/, output)
|
2012-02-17 10:56:57 -05:00
|
|
|
end
|
2014-02-05 02:32:38 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "running migrations with not timestamp head migration files" do
|
2017-09-14 04:43:56 -04:00
|
|
|
app_file "db/migrate/1_one_migration.rb", <<-MIGRATION
|
|
|
|
class OneMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
2015-10-01 12:21:37 -04:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
app_file "db/migrate/02_two_migration.rb", <<-MIGRATION
|
|
|
|
class TwoMigration < ActiveRecord::Migration::Current
|
|
|
|
end
|
|
|
|
MIGRATION
|
2015-10-01 12:21:37 -04:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
rails "db:migrate"
|
2015-10-01 12:21:37 -04:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
output = rails("db:migrate:status")
|
2015-10-01 12:21:37 -04:00
|
|
|
|
2017-09-14 04:43:56 -04:00
|
|
|
assert_match(/up\s+001\s+One migration/, output)
|
|
|
|
assert_match(/up\s+002\s+Two migration/, output)
|
2015-10-01 12:21:37 -04:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "schema generation when dump_schema_after_migration is set" do
|
|
|
|
add_to_config("config.active_record.dump_schema_after_migration = false")
|
2014-02-05 02:32:38 -05:00
|
|
|
|
|
|
|
Dir.chdir(app_path) do
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "model", "book", "title:string"
|
|
|
|
output = rails("generate", "model", "author", "name:string")
|
2015-06-30 10:32:59 -04:00
|
|
|
version = output =~ %r{[^/]+db/migrate/(\d+)_create_authors\.rb} && $1
|
2014-02-05 02:32:38 -05:00
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "db:migrate", "db:rollback", "db:forward", "db:migrate:up", "db:migrate:down", "VERSION=#{version}"
|
2015-06-30 10:32:59 -04:00
|
|
|
assert !File.exist?("db/schema.rb"), "should not dump schema when configured not to"
|
2014-02-05 02:32:38 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
add_to_config("config.active_record.dump_schema_after_migration = true")
|
2014-02-05 02:32:38 -05:00
|
|
|
|
|
|
|
Dir.chdir(app_path) do
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "model", "reviews", "book_id:integer"
|
|
|
|
rails "db:migrate"
|
2014-02-05 02:32:38 -05:00
|
|
|
|
|
|
|
structure_dump = File.read("db/schema.rb")
|
2015-06-30 10:32:59 -04:00
|
|
|
assert_match(/create_table "reviews"/, structure_dump)
|
2014-02-05 02:32:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "default schema generation after migration" do
|
2014-02-05 02:32:38 -05:00
|
|
|
Dir.chdir(app_path) do
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "model", "book", "title:string"
|
|
|
|
rails "db:migrate"
|
2014-02-05 02:32:38 -05:00
|
|
|
|
|
|
|
structure_dump = File.read("db/schema.rb")
|
|
|
|
assert_match(/create_table "books"/, structure_dump)
|
|
|
|
end
|
|
|
|
end
|
2014-06-27 11:28:12 -04:00
|
|
|
|
2017-04-06 19:40:52 -04:00
|
|
|
test "migration status migrated file is deleted" do
|
2014-06-27 11:28:12 -04:00
|
|
|
Dir.chdir(app_path) do
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "model", "user", "username:string", "password:string"
|
|
|
|
rails "generate", "migration", "add_email_to_users", "email:string"
|
|
|
|
rails "db:migrate"
|
|
|
|
`rm db/migrate/*email*.rb`
|
2014-06-27 11:28:12 -04:00
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("db:migrate:status")
|
2014-06-27 11:28:12 -04:00
|
|
|
|
|
|
|
assert_match(/up\s+\d{14}\s+Create users/, output)
|
|
|
|
assert_match(/up\s+\d{14}\s+\** NO FILE \**/, output)
|
|
|
|
end
|
|
|
|
end
|
2011-12-07 11:34:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|