data_migrate 9.1.0 → 11.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +40 -0
  3. data/README.md +22 -15
  4. data/lib/data_migrate/data_migrator.rb +15 -23
  5. data/lib/data_migrate/data_schema.rb +7 -7
  6. data/lib/data_migrate/data_schema_migration.rb +24 -7
  7. data/lib/data_migrate/database_configurations_wrapper.rb +11 -0
  8. data/lib/data_migrate/database_tasks.rb +224 -61
  9. data/lib/data_migrate/migration_context.rb +11 -8
  10. data/lib/data_migrate/rails_helper.rb +91 -0
  11. data/lib/data_migrate/schema_dumper.rb +1 -1
  12. data/lib/data_migrate/schema_migration.rb +5 -4
  13. data/lib/data_migrate/status_service.rb +3 -3
  14. data/lib/data_migrate/tasks/data_migrate_tasks.rb +11 -9
  15. data/lib/data_migrate/version.rb +1 -1
  16. data/lib/data_migrate.rb +2 -1
  17. data/lib/generators/data_migration/data_migration_generator.rb +2 -1
  18. data/tasks/databases.rake +9 -46
  19. metadata +13 -54
  20. data/.github/workflows/build.yml +0 -34
  21. data/.github/workflows/gempush.yml +0 -28
  22. data/.gitignore +0 -13
  23. data/.hound.yml +0 -4
  24. data/.overcommit.yml +0 -21
  25. data/.rbenv-gemsets +0 -2
  26. data/.rspec +0 -3
  27. data/.rubocop.yml +0 -2
  28. data/.ruby-style.yml +0 -1061
  29. data/Appraisals +0 -11
  30. data/Gemfile +0 -4
  31. data/Gemfile.rails6.1 +0 -11
  32. data/Rakefile +0 -2
  33. data/data_migrate.gemspec +0 -41
  34. data/gemfiles/rails_6.0.gemfile +0 -8
  35. data/gemfiles/rails_6.1.gemfile +0 -8
  36. data/gemfiles/rails_7.0.gemfile +0 -8
  37. data/lib/data_migrate/legacy_migrator.rb +0 -22
  38. data/screenshot.png +0 -0
  39. data/spec/data_migrate/config_spec.rb +0 -69
  40. data/spec/data_migrate/data_migrator_spec.rb +0 -80
  41. data/spec/data_migrate/data_schema_migration_spec.rb +0 -16
  42. data/spec/data_migrate/data_spec.rb +0 -74
  43. data/spec/data_migrate/database_tasks_spec.rb +0 -90
  44. data/spec/data_migrate/legacy_migrator_spec.rb +0 -38
  45. data/spec/data_migrate/migration.rb +0 -17
  46. data/spec/data_migrate/migration_context_spec.rb +0 -101
  47. data/spec/data_migrate/schema_dumper_spec.rb +0 -33
  48. data/spec/data_migrate/schema_migration_spec.rb +0 -97
  49. data/spec/data_migrate/status_service_spec.rb +0 -73
  50. data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +0 -129
  51. data/spec/db/data/20091231235959_some_name.rb +0 -9
  52. data/spec/db/data/20171231235959_super_update.rb +0 -9
  53. data/spec/db/data/20181128000207_excluded_file.rb.other_ext +0 -1
  54. data/spec/db/data/partial_schema/data_schema.rb +0 -1
  55. data/spec/db/data/partial_schema/test_data_schema.rb +0 -1
  56. data/spec/db/data/schema/data_schema.rb +0 -1
  57. data/spec/db/data/schema/test_data_schema.rb +0 -1
  58. data/spec/db/migrate/20131111111111_late_migration.rb +0 -9
  59. data/spec/db/migrate/20202020202011_db_migration.rb +0 -9
  60. data/spec/generators/data_migration/data_migration_generator_spec.rb +0 -101
  61. data/spec/spec_helper.rb +0 -28
  62. data/tasks/.gitkeep +0 -0
data/Appraisals DELETED
@@ -1,11 +0,0 @@
1
- appraise 'rails-6.0' do
2
- gem 'rails', '~> 6.0.0'
3
- end
4
-
5
- appraise 'rails-6.1' do
6
- gem 'rails', '~> 6.1.0'
7
- end
8
-
9
- appraise 'rails-7.0' do
10
- gem 'rails', '~> 7.0'
11
- end
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'sqlite3', "~> 1.4"
4
- gemspec
data/Gemfile.rails6.1 DELETED
@@ -1,11 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in data_migrate.gemspec
4
- %w[
5
- activerecord
6
- railties
7
- ].each do |rails_gem|
8
- gem rails_gem, '~> 6.1.0'
9
- end
10
- gem 'sqlite3', "~> 1.4"
11
- gemspec
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
data/data_migrate.gemspec DELETED
@@ -1,41 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "data_migrate/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "data_migrate"
7
- s.version = DataMigrate::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Andrew J Vargo", "Ilya Katz", "Deborah Enomah"]
10
- s.email = ["ajvargo@computer.org", "ilyakatz@gmail.com", "enomaomorogieva@gmail.com"]
11
- s.homepage = "https://github.com/ilyakatz/data-migrate"
12
- s.summary = %q{Rake tasks to migrate data alongside schema changes.}
13
- s.description = %q{Rake tasks to migrate data alongside schema changes.}
14
- s.license = "MIT"
15
-
16
- s.rubyforge_project = "data_migrate"
17
-
18
- %w[
19
- activerecord
20
- railties
21
- ].each do |rails_gem|
22
- s.add_dependency(rails_gem, '>= 6.0')
23
- end
24
-
25
- s.add_development_dependency "appraisal"
26
- s.add_development_dependency "rake"
27
- s.add_development_dependency "rspec"
28
- s.add_development_dependency "rspec-core"
29
- s.add_development_dependency "pry"
30
- s.add_development_dependency "rb-readline"
31
- s.add_development_dependency "sqlite3", "~> 1.3.6"
32
- s.add_development_dependency "timecop"
33
- s.add_development_dependency "rubocop"
34
- s.add_development_dependency "overcommit"
35
-
36
-
37
- s.files = `git ls-files`.split("\n")
38
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
39
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
40
- s.require_paths = ["lib"]
41
- end
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "~> 6.0.0"
6
- gem "sqlite3", "~> 1.4"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "~> 6.1.0"
6
- gem "sqlite3", "~> 1.4"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "sqlite3", "~> 1.4"
6
- gem "rails", "~> 7.0"
7
-
8
- gemspec path: "../"
@@ -1,22 +0,0 @@
1
- module DataMigrate
2
- class LegacyMigrator
3
- def initialize(migrations_paths = "db/data")
4
- @migrations_paths = migrations_paths || "db/data"
5
- end
6
-
7
- def migrate
8
- dates =
9
- DataMigrate::DataMigrator.migrations(@migrations_paths).collect(&:version)
10
- legacy = ActiveRecord::SchemaMigration.where(version: dates)
11
- legacy.each do |v|
12
- begin
13
- version = v.version
14
- puts "Creating #{version} in data schema"
15
- DataMigrate::DataSchemaMigration.create(version: version)
16
- rescue ActiveRecord::RecordNotUnique
17
- nil
18
- end
19
- end
20
- end
21
- end
22
- end
data/screenshot.png DELETED
Binary file
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe DataMigrate::Config do
6
- it "sets default data_migrations_path path", :no_override do
7
- expect(DataMigrate.config.data_migrations_path).to eq "db/data/"
8
- end
9
-
10
- it "sets default data_template_path path", :no_override do
11
- expect(DataMigrate.config.data_template_path).to eq DataMigrate::Config::DEFAULT_DATA_TEMPLATE_PATH
12
- end
13
-
14
- describe "data migration path configured" do
15
- subject { DataMigrate.config.data_migrations_path }
16
- let(:data_migrations_path) { "db/awesome/" }
17
-
18
- before do
19
- @original_data_migrations_path = DataMigrate.config.data_migrations_path
20
-
21
- DataMigrate.configure do |config|
22
- config.data_migrations_path = data_migrations_path
23
- end
24
- end
25
-
26
- after do
27
- DataMigrate.configure do |config|
28
- config.data_migrations_path = @original_data_migrations_path
29
- end
30
- end
31
-
32
- it "equals the custom data migration path" do
33
- is_expected.to eq(data_migrations_path)
34
- end
35
- end
36
-
37
- describe "data template path configured" do
38
- subject { DataMigrate.config.data_template_path }
39
- let(:data_template_path) { File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb") }
40
-
41
- before do
42
- @original_data_migrations_path = DataMigrate.config.data_template_path
43
-
44
- DataMigrate.configure do |config|
45
- config.data_template_path = data_template_path
46
- end
47
- end
48
-
49
- after do
50
- DataMigrate.configure do |config|
51
- config.data_template_path = @original_data_migrations_path
52
- end
53
- end
54
-
55
- it "equals the custom data template path" do
56
- is_expected.to eq data_template_path
57
- end
58
-
59
- context "when path does not exist" do
60
- subject { DataMigrate.config.data_template_path = invalid_path }
61
-
62
- let(:invalid_path) { "lib/awesome/templates/data_migration.rb" }
63
-
64
- it "checks that file exists on setting config var" do
65
- expect { subject }.to raise_error { ArgumentError.new("File not found: '#{data_template_path}'") }
66
- end
67
- end
68
- end
69
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe DataMigrate::DataMigrator do
6
- let(:subject) { DataMigrate::DataMigrator }
7
- let(:db_config) do
8
- {
9
- adapter: "sqlite3",
10
- database: "spec/db/test.db"
11
- }
12
- end
13
-
14
- before do
15
- ActiveRecord::Base.establish_connection(db_config)
16
- ::ActiveRecord::SchemaMigration.create_table
17
- DataMigrate::DataSchemaMigration.create_table
18
- end
19
-
20
- after do
21
- ActiveRecord::Migration.drop_table("data_migrations") rescue nil
22
- ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
23
- end
24
-
25
- describe ".load_migrated" do
26
- it "loads migrated versions" do
27
- DataMigrate::DataSchemaMigration.create(version: 20090000000000)
28
- ::ActiveRecord::SchemaMigration.create(version: 20100000000000)
29
- DataMigrate::DataSchemaMigration.create(version: 20110000000000)
30
- ::ActiveRecord::SchemaMigration.create(version: 20120000000000)
31
- migrated = subject.new(:up, []).load_migrated
32
- expect(migrated.count).to eq 2
33
- expect(migrated).to include 20090000000000
34
- expect(migrated).to include 20110000000000
35
- end
36
- end
37
-
38
- describe :create_data_schema_table do
39
- it "creates the data_migrations table" do
40
- ActiveRecord::Migration.drop_table("data_migrations") rescue nil
41
- subject.create_data_schema_table
42
- expect(
43
- ActiveRecord::Base.connection.table_exists?("data_migrations")
44
- ).to eq true
45
- end
46
- end
47
-
48
- describe "#migrations_status" do
49
- it "returns all migrations statuses" do
50
- status = subject.migrations_status
51
- expect(status.length).to eq 2
52
- expect(status.first).to eq ["down", "20091231235959", "Some name"]
53
- expect(status.second).to eq ["down", "20171231235959", "Super update"]
54
- end
55
- end
56
-
57
- describe :match do
58
- context "when the file does not match" do
59
- it "returns nil" do
60
- expect(subject.match("not_a_data_migration_file")).to be_nil
61
- end
62
- end
63
-
64
- context "when the file doesn't end in .rb" do
65
- it "returns nil" do
66
- expect(subject.match("20091231235959_some_name.rb.un~")).to be_nil
67
- end
68
- end
69
-
70
- context "when the file matches" do
71
- it "returns a valid MatchData object" do
72
- match_data = subject.match("20091231235959_some_name.rb")
73
-
74
- expect(match_data[0]).to eq "20091231235959_some_name.rb"
75
- expect(match_data[1]).to eq "20091231235959"
76
- expect(match_data[2]).to eq "some_name"
77
- end
78
- end
79
- end
80
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DataMigrate::DataSchemaMigration do
4
- let(:subject) { DataMigrate::DataSchemaMigration }
5
- describe :table_name do
6
- it "returns correct table name" do
7
- expect(subject.table_name).to eq("data_migrations")
8
- end
9
- end
10
-
11
- describe :index_name do
12
- it "returns correct primary key name" do
13
- expect(subject.primary_key).to eq("version")
14
- end
15
- end
16
- end
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe DataMigrate::Data do
6
- let(:subject) { DataMigrate::Data }
7
- let(:fixture_file_timestamps) do
8
- %w[20091231235959 20101231235959 20111231235959]
9
- end
10
-
11
- around do |example|
12
- Dir.mktmpdir do |temp_dir|
13
- @temp_dir = temp_dir
14
-
15
- # create the fake data migration files
16
- fixture_file_timestamps.each do |timestamp|
17
- FileUtils.touch File.join(temp_dir, "#{timestamp}_data_migration.rb")
18
- end
19
-
20
- example.run
21
- end
22
- end
23
-
24
- describe :define do
25
- after do
26
- ActiveRecord::Migration.drop_table("data_migrations")
27
- end
28
-
29
- context "when no version is supplied" do
30
- it "returns nil" do
31
- expect(subject.define(version: nil)).to be_nil
32
- end
33
- end
34
-
35
- context "when a version is supplied" do
36
- before do
37
- allow(DataMigrate::DataMigrator).
38
- to receive(:full_migrations_path).and_return(@temp_dir)
39
- end
40
-
41
- it "sets the current version to the supplied version" do
42
- version = fixture_file_timestamps[1]
43
-
44
- expect(DataMigrate::DataMigrator.current_version).not_to eq version.to_i
45
- subject.define(version: version)
46
- expect(DataMigrate::DataMigrator.current_version).to eq version.to_i
47
- end
48
-
49
- it "creates entries for migration versions that come " \
50
- "before the supplied version" do
51
-
52
- version = fixture_file_timestamps[1]
53
-
54
- subject.define(version: version)
55
-
56
- sql_select = <<-SQL
57
- SELECT version
58
- FROM #{DataMigrate::DataSchemaMigration.table_name}
59
- SQL
60
-
61
- db_list_data = ActiveRecord::Base.connection.
62
- select_values(sql_select).map(&:to_i)
63
- expect(db_list_data).to match_array(
64
- [fixture_file_timestamps[0], fixture_file_timestamps[1]].map(&:to_i)
65
- )
66
-
67
- # The last remaining migration (fixture_file_timestamps[2]) was
68
- # not included as part of the supplied version and so should not
69
- # appear in the data_migrations table.
70
- expect(db_list_data).not_to include(fixture_file_timestamps[2])
71
- end
72
- end
73
- end
74
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe DataMigrate::DatabaseTasks do
6
- let(:subject) { DataMigrate::DatabaseTasks }
7
- let(:migration_path) { "spec/db/migrate" }
8
- let(:data_migrations_path) {
9
- DataMigrate.config.data_migrations_path
10
- }
11
- let(:db_config) do
12
- {
13
- adapter: "sqlite3",
14
- database: "spec/db/test.db"
15
- }
16
- end
17
-
18
- before do
19
- # In a normal Rails installation, db_dir would defer to
20
- # Rails.application.config.paths["db"].first
21
- # @see https://github.com/rails/rails/blob/a7d49ef78c36df2d1ca876451f30915ada1079a5/activerecord/lib/active_record/tasks/database_tasks.rb#L54
22
- allow(subject).to receive(:db_dir).and_return("db")
23
- allow(ActiveRecord::Tasks::DatabaseTasks).to receive(:db_dir).and_return("db")
24
- end
25
-
26
- before do
27
- allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) {
28
- data_migrations_path
29
- }
30
- ActiveRecord::Base.establish_connection(db_config)
31
- if Gem::Dependency.new("railties", ">= 6.1").match?("railties", Gem.loaded_specs["railties"].version)
32
- hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', db_config)
33
- config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
34
- allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
35
- else
36
- ActiveRecord::Base.configurations[:test] = db_config
37
- end
38
- end
39
-
40
- context "migrations" do
41
- after do
42
- ActiveRecord::Migration.drop_table("data_migrations") rescue nil
43
- ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
44
- end
45
-
46
- before do
47
- ActiveRecord::SchemaMigration.create_table
48
-
49
- allow(DataMigrate::SchemaMigration).to receive(:migrations_paths) {
50
- migration_path
51
- }
52
- allow(DataMigrate::DatabaseTasks).to receive(:data_migrations_path) {
53
- data_migrations_path
54
- }.at_least(:once)
55
- end
56
-
57
- describe :past_migrations do
58
- it "returns past migration records" do
59
- subject.forward
60
- migrations = subject.past_migrations
61
- expect(migrations.count).to eq 1
62
- expect(migrations.first[:version]).to eq 20091231235959
63
- end
64
-
65
- it "shows nothing without any migrations" do
66
- migrations = subject.past_migrations
67
- expect(migrations.count).to eq 0
68
- end
69
- end
70
-
71
- describe :forward do
72
-
73
- it "run forward default amount of times" do
74
- subject.forward
75
- versions = DataMigrate::DataSchemaMigration.normalized_versions
76
- expect(versions.count).to eq(1)
77
- end
78
-
79
- it "run forward defined number of times" do
80
- subject.forward(2)
81
- versions = DataMigrate::DataSchemaMigration.normalized_versions
82
- expect(versions.count).to eq(1)
83
- expect(versions.first).to eq "20091231235959"
84
- versions = ActiveRecord::SchemaMigration.normalized_versions
85
- expect(versions.count).to eq(1)
86
- expect(versions.first).to eq "20131111111111"
87
- end
88
- end
89
- end
90
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe DataMigrate::LegacyMigrator do
6
- let(:context) {
7
- DataMigrate::MigrationContext.new("spec/db/data")
8
- }
9
-
10
- before do
11
- ActiveRecord::SchemaMigration.create_table
12
- DataMigrate::DataSchemaMigration.create_table
13
- end
14
-
15
- after do
16
- ActiveRecord::Migration.drop_table("data_migrations") rescue nil
17
- ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
18
- end
19
-
20
- it "migrate legacy migrations to be in correct table" do
21
- # simulate creation of legacy data migration when
22
- # it was recorded in schema table
23
- ActiveRecord::SchemaMigration.create(version: "20091231235959")
24
-
25
- # create one migration in correct place
26
- DataMigrate::DataSchemaMigration.create(version: "20171231235959")
27
-
28
- migrated = DataMigrate::DataMigrator.new(:up, []).load_migrated
29
- expect(migrated.count).to eq 1
30
-
31
- DataMigrate::LegacyMigrator.new("spec/db/data").migrate
32
-
33
- # after migacy migrator has been run, we should have records
34
- # of both migrations
35
- migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
36
- expect(migrated.count).to eq 2
37
- end
38
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe DataMigrate::Migration do
6
- describe ".table_name" do
7
- it "returns correct table name" do
8
- expect(subject.table_name).to eq("data_migrations")
9
- end
10
- end
11
-
12
- describe ".index_name" do
13
- it "returns correct primary key name" do
14
- expect(subject.primary_key).to eq("version")
15
- end
16
- end
17
- end
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe DataMigrate::DataMigrator do
6
- let(:context) { DataMigrate::MigrationContext.new("spec/db/data") }
7
- let(:schema_context) { ActiveRecord::MigrationContext.new("spec/db/migrate", ActiveRecord::Base.connection.schema_migration) }
8
-
9
- before do
10
- ActiveRecord::SchemaMigration.create_table
11
- DataMigrate::DataSchemaMigration.create_table
12
- end
13
-
14
- after do
15
- ActiveRecord::Migration.drop_table("data_migrations") rescue nil
16
- ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
17
- end
18
-
19
- describe "migrate" do
20
- it "migrates existing file" do
21
- context.migrate(nil)
22
- context.migrations_status
23
- versions = DataMigrate::DataSchemaMigration.normalized_versions
24
- expect(versions.count).to eq(2)
25
- expect(versions).to include("20091231235959")
26
- expect(versions).to include("20171231235959")
27
- end
28
-
29
- it "undo migration" do
30
- context.migrate(nil)
31
- context.run(:down, 20171231235959)
32
- versions = DataMigrate::DataSchemaMigration.normalized_versions
33
- expect(versions.count).to eq(1)
34
- expect(versions).to include("20091231235959")
35
- end
36
-
37
- it "does not do anything if migration is undone twice" do
38
- context.migrate(nil)
39
- expect {
40
- context.run(:down, 20171231235959)
41
- }.to output(/Undoing SuperUpdate/).to_stdout
42
- expect {
43
- context.run(:down, 20171231235959)
44
- }.not_to output(/Undoing SuperUpdate/).to_stdout
45
- end
46
-
47
- it "runs a specific migration" do
48
- context.run(:up, 20171231235959)
49
- versions = DataMigrate::DataSchemaMigration.normalized_versions
50
- expect(versions.count).to eq(1)
51
- expect(versions).to include("20171231235959")
52
- end
53
-
54
- it "does not do anything if migration is ran twice" do
55
- expect {
56
- context.run(:up, 20171231235959)
57
- }.to output(/Doing SuperUpdate/).to_stdout
58
- expect {
59
- context.run(:down, 20171231235959)
60
- }.not_to output(/Doing SuperUpdate/).to_stdout
61
- end
62
-
63
- it "alerts for an invalid specific migration" do
64
- expect {
65
- context.run(:up, 201712312)
66
- }.to raise_error(
67
- ActiveRecord::UnknownMigrationVersionError,
68
- /No migration with version number 201712312/
69
- )
70
- end
71
-
72
- it "rolls back latest migration" do
73
- context.migrate(nil)
74
- expect {
75
- context.rollback
76
- }.to output(/Undoing SuperUpdate/).to_stdout
77
- versions = DataMigrate::DataSchemaMigration.normalized_versions
78
- expect(versions.count).to eq(1)
79
- expect(versions).to include("20091231235959")
80
- end
81
-
82
- it "rolls back 2 migrations" do
83
- context.migrate(nil)
84
- schema_context.migrate(nil)
85
- expect {
86
- context.rollback(2)
87
- }.to output(/Undoing SomeName/).to_stdout
88
- versions = DataMigrate::DataSchemaMigration.normalized_versions
89
- expect(versions.count).to eq(0)
90
- end
91
-
92
- it "rolls back 2 migrations" do
93
- context.migrate(nil)
94
- expect {
95
- context.rollback(2)
96
- }.to output(/Undoing SomeName/).to_stdout
97
- versions = DataMigrate::DataSchemaMigration.normalized_versions
98
- expect(versions.count).to eq(0)
99
- end
100
- end
101
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe DataMigrate::SchemaDumper do
6
- let(:subject) { DataMigrate::SchemaDumper }
7
- let(:fixture_file_timestamps) do
8
- %w[20091231235959 20101231235959 20111231235959]
9
- end
10
-
11
- before do
12
- ActiveRecord::SchemaMigration.create_table
13
- DataMigrate::DataSchemaMigration.create_table
14
- DataMigrate::DataSchemaMigration.create(fixture_file_timestamps.map { |t| { version: t } })
15
- end
16
-
17
- after do
18
- ActiveRecord::Migration.drop_table("data_migrations") rescue nil
19
- ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
20
- end
21
-
22
- describe ".dump" do
23
- it "writes the define method with the version key to the stream" do
24
- stream = StringIO.new
25
- DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
26
- stream.rewind
27
-
28
- last_version = fixture_file_timestamps.last
29
- expected = "DataMigrate::Data.define(version: #{last_version})"
30
- expect(stream.read).to include expected
31
- end
32
- end
33
- end