data_migrate 8.3.0 → 11.3.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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +92 -0
  3. data/README.md +32 -19
  4. data/lib/data_migrate/config.rb +11 -1
  5. data/lib/data_migrate/{data_migrator_five.rb → data_migrator.rb} +15 -35
  6. data/lib/data_migrate/data_schema.rb +8 -8
  7. data/lib/data_migrate/data_schema_migration.rb +24 -7
  8. data/lib/data_migrate/database_configurations_wrapper.rb +11 -0
  9. data/lib/data_migrate/database_tasks.rb +233 -69
  10. data/lib/data_migrate/migration_context.rb +11 -8
  11. data/lib/data_migrate/rails_helper.rb +91 -0
  12. data/lib/data_migrate/schema_dumper.rb +1 -1
  13. data/lib/data_migrate/{schema_migration_six.rb → schema_migration.rb} +7 -4
  14. data/lib/data_migrate/{status_service_five.rb → status_service.rb} +14 -8
  15. data/lib/data_migrate/tasks/data_migrate_tasks.rb +24 -43
  16. data/lib/data_migrate/version.rb +1 -1
  17. data/lib/data_migrate.rb +8 -9
  18. data/lib/generators/data_migrate.rb +15 -2
  19. data/lib/generators/data_migration/data_migration_generator.rb +7 -2
  20. data/tasks/databases.rake +36 -121
  21. metadata +19 -77
  22. data/.github/workflows/gempush.yml +0 -29
  23. data/.gitignore +0 -11
  24. data/.hound.yml +0 -4
  25. data/.overcommit.yml +0 -21
  26. data/.rbenv-gemsets +0 -2
  27. data/.rspec +0 -3
  28. data/.rubocop.yml +0 -2
  29. data/.ruby-style.yml +0 -1061
  30. data/.ruby-version +0 -1
  31. data/.travis.yml +0 -14
  32. data/Appraisals +0 -15
  33. data/Gemfile +0 -4
  34. data/Gemfile.rails5.2 +0 -10
  35. data/Gemfile.rails6.1 +0 -11
  36. data/Rakefile +0 -2
  37. data/data_migrate.gemspec +0 -50
  38. data/gemfiles/rails_5.2.gemfile +0 -8
  39. data/gemfiles/rails_6.0.gemfile +0 -8
  40. data/gemfiles/rails_6.1.gemfile +0 -8
  41. data/gemfiles/rails_7.0.gemfile +0 -8
  42. data/lib/data_migrate/legacy_migrator.rb +0 -22
  43. data/lib/data_migrate/schema_migration_five.rb +0 -31
  44. data/screenshot.png +0 -0
  45. data/spec/data_migrate/config_spec.rb +0 -27
  46. data/spec/data_migrate/data_migrator_spec.rb +0 -101
  47. data/spec/data_migrate/data_schema_migration_spec.rb +0 -16
  48. data/spec/data_migrate/data_spec.rb +0 -85
  49. data/spec/data_migrate/database_tasks_spec.rb +0 -138
  50. data/spec/data_migrate/legacy_migrator_spec.rb +0 -50
  51. data/spec/data_migrate/migration.rb +0 -19
  52. data/spec/data_migrate/migration_context_spec.rb +0 -127
  53. data/spec/data_migrate/schema_dumper_spec.rb +0 -46
  54. data/spec/data_migrate/schema_migration_spec.rb +0 -99
  55. data/spec/data_migrate/status_service_spec.rb +0 -102
  56. data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +0 -164
  57. data/spec/db/6.0/20091231235959_some_name.rb +0 -9
  58. data/spec/db/6.0/20171231235959_super_update.rb +0 -9
  59. data/spec/db/data/20091231235959_some_name.rb +0 -9
  60. data/spec/db/data/20171231235959_super_update.rb +0 -9
  61. data/spec/db/data/20181128000207_excluded_file.rb.other_ext +0 -1
  62. data/spec/db/data/partial_schema/data_schema.rb +0 -1
  63. data/spec/db/data/partial_schema/test_data_schema.rb +0 -1
  64. data/spec/db/data/schema/data_schema.rb +0 -1
  65. data/spec/db/data/schema/test_data_schema.rb +0 -1
  66. data/spec/db/data-6.0/20091231235959_some_name.rb +0 -9
  67. data/spec/db/data-6.0/20171231235959_super_update.rb +0 -9
  68. data/spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext +0 -1
  69. data/spec/db/migrate/5.2/20131111111111_late_migration.rb +0 -9
  70. data/spec/db/migrate/5.2/20202020202011_db_migration.rb +0 -9
  71. data/spec/db/migrate/6.0/20131111111111_late_migration.rb +0 -9
  72. data/spec/db/migrate/6.0/20202020202011_db_migration.rb +0 -9
  73. data/spec/generators/data_migration/data_migration_generator_spec.rb +0 -60
  74. data/spec/spec_helper.rb +0 -34
  75. data/tasks/.gitkeep +0 -0
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.7.5
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.7
4
- - 3.0
5
- script: bundle exec rspec
6
- gemfile:
7
- - gemfiles/rails_5.2.gemfile
8
- - gemfiles/rails_6.0.gemfile
9
- - gemfiles/rails_6.1.gemfile
10
- - gemfiles/rails_7.0.gemfile
11
- jobs:
12
- exclude:
13
- - rvm: 3.0
14
- gemfile: gemfiles/rails_5.2.gemfile
data/Appraisals DELETED
@@ -1,15 +0,0 @@
1
- appraise 'rails-5.2' do
2
- gem 'rails', '~> 5.2.3'
3
- end
4
-
5
- appraise 'rails-6.0' do
6
- gem 'rails', '~> 6.0.0'
7
- end
8
-
9
- appraise 'rails-6.1' do
10
- gem 'rails', '~> 6.1.0'
11
- end
12
-
13
- appraise 'rails-7.0' do
14
- gem 'rails', '~> 7.0'
15
- end
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'sqlite3', "~> 1.4"
4
- gemspec
data/Gemfile.rails5.2 DELETED
@@ -1,10 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in data_migrate.gemspec
4
- gemspec
5
- %w[
6
- activerecord
7
- railties
8
- ].each do |rails_gem|
9
- gem rails_gem, '~> 5.2'
10
- end
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,50 +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, '>= 5.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
-
42
- s.post_install_message = <<-POST_INSTALL_MESSAGE
43
- #{"*" * 80}
44
- data-migrate: IMPORTANT: Breaking change introduced for migrations from v2.
45
-
46
- Failure to run the migration can have serious consequences.
47
- See Readme for more info.
48
- #{"*" * 80}
49
- POST_INSTALL_MESSAGE
50
- end
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "~> 5.2.3"
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.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
@@ -1,31 +0,0 @@
1
- module DataMigrate
2
- # Helper class to getting access to db schema
3
- # to allow data/schema combiation tasks
4
- class SchemaMigration
5
- def self.pending_schema_migrations
6
- all_migrations = DataMigrate::MigrationContext.new(migrations_paths).migrations
7
- sort_migrations(
8
- ActiveRecord::Migrator.new(:up, all_migrations).
9
- pending_migrations.
10
- map {|m| { version: m.version, name: m.name, kind: :schema }}
11
- )
12
- end
13
-
14
- def self.run(direction, migration_paths, version)
15
- ActiveRecord::MigrationContext.new(migration_paths).run(direction, version)
16
- end
17
-
18
- def self.sort_migrations(set1, set2 = nil)
19
- migrations = set1 + (set2 || [])
20
- migrations.sort {|a, b| sort_string(a) <=> sort_string(b)}
21
- end
22
-
23
- def self.migrations_paths
24
- Rails.application.config.paths["db/migrate"].to_a
25
- end
26
-
27
- def self.sort_string(migration)
28
- "#{migration[:version]}_#{migration[:kind] == :data ? 1 : 0}"
29
- end
30
- end
31
- end
data/screenshot.png DELETED
Binary file
@@ -1,27 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DataMigrate::Config do
4
-
5
- it "sets default data_migrations_path path", :no_override do
6
- expect(DataMigrate.config.data_migrations_path).to eq "db/data/"
7
- end
8
-
9
- describe "data migration path configured" do
10
- before do
11
- @before = DataMigrate.config.data_migrations_path
12
- DataMigrate.configure do |config|
13
- config.data_migrations_path = "db/awesome/"
14
- end
15
- end
16
-
17
- after do
18
- DataMigrate.configure do |config|
19
- config.data_migrations_path = @before
20
- end
21
- end
22
-
23
- it do
24
- expect(DataMigrate.config.data_migrations_path).to eq "db/awesome/"
25
- end
26
- end
27
- end
@@ -1,101 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DataMigrate::DataMigrator do
4
- let(:subject) { DataMigrate::DataMigrator }
5
- let(:db_config) do
6
- {
7
- adapter: "sqlite3",
8
- database: "spec/db/test.db"
9
- }
10
- end
11
-
12
- before do
13
- allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
14
- ActiveRecord::Base.establish_connection(db_config)
15
- end
16
-
17
- describe :load_migrated do
18
- before do
19
- allow(subject).to receive(:db_config) { db_config }.at_least(:once)
20
- ActiveRecord::Base.establish_connection(db_config)
21
- ::ActiveRecord::SchemaMigration.create_table
22
- DataMigrate::DataSchemaMigration.create_table
23
- end
24
-
25
- after do
26
- ActiveRecord::Migration.drop_table("data_migrations")
27
- ActiveRecord::Migration.drop_table("schema_migrations")
28
- end
29
-
30
- it do
31
- subject.assure_data_schema_table
32
- DataMigrate::DataSchemaMigration.create(version: 20090000000000)
33
- ::ActiveRecord::SchemaMigration.create(version: 20100000000000)
34
- DataMigrate::DataSchemaMigration.create(version: 20110000000000)
35
- ::ActiveRecord::SchemaMigration.create(version: 20120000000000)
36
- migrated = subject.new(:up, []).load_migrated
37
- expect(migrated.count).to eq 2
38
- expect(migrated).to include 20090000000000
39
- expect(migrated).to include 20110000000000
40
- end
41
- end
42
-
43
- describe :assure_data_schema_table do
44
- before do
45
- allow(subject).to receive(:db_config) { db_config }.at_least(:once)
46
- ActiveRecord::Base.establish_connection(db_config)
47
- end
48
-
49
- after do
50
- ActiveRecord::Migration.drop_table("data_migrations")
51
- end
52
-
53
- it do
54
- ActiveRecord::Migration.drop_table("data_migrations") rescue nil
55
- subject.assure_data_schema_table
56
- expect(
57
- ActiveRecord::Base.connection.table_exists?("data_migrations")
58
- ).to eq true
59
- end
60
- end
61
-
62
- describe "#migrations_status" do
63
- before do
64
- allow(subject).to receive(:db_config) { db_config }.at_least(:once)
65
- ActiveRecord::Base.establish_connection(db_config)
66
- ::ActiveRecord::SchemaMigration.create_table
67
- DataMigrate::DataSchemaMigration.create_table
68
- end
69
-
70
- it "returns all migrations statuses" do
71
- status = subject.migrations_status
72
- expect(status.length).to eq 2
73
- expect(status.first).to eq ["down", "20091231235959", "Some name"]
74
- expect(status.second).to eq ["down", "20171231235959", "Super update"]
75
- end
76
- end
77
-
78
- describe :match do
79
- context "when the file does not match" do
80
- it "returns nil" do
81
- expect(subject.match("not_a_data_migration_file")).to be_nil
82
- end
83
- end
84
-
85
- context "when the file doesn't end in .rb" do
86
- it "returns nil" do
87
- expect(subject.match("20091231235959_some_name.rb.un~")).to be_nil
88
- end
89
- end
90
-
91
- context "when the file matches" do
92
- it "returns a valid MatchData object" do
93
- match_data = subject.match("20091231235959_some_name.rb")
94
-
95
- expect(match_data[0]).to eq "20091231235959_some_name.rb"
96
- expect(match_data[1]).to eq "20091231235959"
97
- expect(match_data[2]).to eq "some_name"
98
- end
99
- end
100
- end
101
- 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,85 +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(:db_config) do
8
- {
9
- adapter: "sqlite3",
10
- database: "spec/db/test.db"
11
- }
12
- end
13
- let(:fixture_file_timestamps) do
14
- %w[20091231235959 20101231235959 20111231235959]
15
- end
16
-
17
- around do |example|
18
- Dir.mktmpdir do |temp_dir|
19
- @temp_dir = temp_dir
20
-
21
- # create the fake data migration files
22
- fixture_file_timestamps.each do |timestamp|
23
- FileUtils.touch File.join(temp_dir, "#{timestamp}_data_migration.rb")
24
- end
25
-
26
- example.run
27
- end
28
- end
29
-
30
- describe :define do
31
- before do
32
- allow(DataMigrate::DataMigrator).
33
- to receive(:db_config) { db_config }
34
- end
35
-
36
- after do
37
- ActiveRecord::Migration.drop_table("data_migrations")
38
- end
39
-
40
- context "when no version is supplied" do
41
- it "returns nil" do
42
- expect(subject.define(version: nil)).to be_nil
43
- end
44
- end
45
-
46
- context "when a version is supplied" do
47
- before do
48
- allow(DataMigrate::DataMigrator).
49
- to receive(:full_migrations_path).and_return(@temp_dir)
50
- end
51
-
52
- it "sets the current version to the supplied version" do
53
- version = fixture_file_timestamps[1]
54
-
55
- expect(DataMigrate::DataMigrator.current_version).not_to eq version.to_i
56
- subject.define(version: version)
57
- expect(DataMigrate::DataMigrator.current_version).to eq version.to_i
58
- end
59
-
60
- it "creates entries for migration versions that come " \
61
- "before the supplied version" do
62
-
63
- version = fixture_file_timestamps[1]
64
-
65
- subject.define(version: version)
66
-
67
- sql_select = <<-SQL
68
- SELECT version
69
- FROM #{DataMigrate::DataSchemaMigration.table_name}
70
- SQL
71
-
72
- db_list_data = ActiveRecord::Base.connection.
73
- select_values(sql_select).map(&:to_i)
74
- expect(db_list_data).to match_array(
75
- [fixture_file_timestamps[0], fixture_file_timestamps[1]].map(&:to_i)
76
- )
77
-
78
- # The last remaining migration (fixture_file_timestamps[2]) was
79
- # not included as part of the supplied version and so should not
80
- # appear in the data_migrations table.
81
- expect(db_list_data).not_to include(fixture_file_timestamps[2])
82
- end
83
- end
84
- end
85
- end
@@ -1,138 +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) {
8
- if Rails::VERSION::MAJOR == 5
9
- "spec/db/migrate/5.2"
10
- else
11
- "spec/db/migrate/6.0"
12
- end
13
- }
14
- let(:data_migrations_path) {
15
- DataMigrate.config.data_migrations_path
16
- }
17
- let(:db_config) do
18
- {
19
- adapter: "sqlite3",
20
- database: "spec/db/test.db"
21
- }
22
- end
23
-
24
- before do
25
- # In a normal Rails installation, db_dir would defer to
26
- # Rails.application.config.paths["db"].first
27
- # @see https://github.com/rails/rails/blob/a7d49ef78c36df2d1ca876451f30915ada1079a5/activerecord/lib/active_record/tasks/database_tasks.rb#L54
28
- allow(subject).to receive(:db_dir).and_return("db")
29
- allow(ActiveRecord::Tasks::DatabaseTasks).to receive(:db_dir).and_return("db")
30
- end
31
-
32
- before do
33
- allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) {
34
- data_migrations_path
35
- }
36
- allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
37
- ActiveRecord::Base.establish_connection(db_config)
38
- if Rails.version >= '6.1'
39
- hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', db_config)
40
- config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
41
- allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
42
- else
43
- ActiveRecord::Base.configurations[:test] = db_config
44
- end
45
- end
46
-
47
- describe :schema_file do
48
- it "returns the correct data schema file path" do
49
- expect(subject.schema_file(nil)).to eq "db/data_schema.rb"
50
- end
51
- end
52
-
53
- context "migrations" do
54
- after do
55
- begin
56
- ActiveRecord::Migration.drop_table("data_migrations")
57
- rescue ActiveRecord::StatementInvalid
58
- end
59
- ActiveRecord::Migration.drop_table("schema_migrations")
60
- end
61
-
62
- before do
63
- ActiveRecord::SchemaMigration.create_table
64
-
65
- allow(DataMigrate::SchemaMigration).to receive(:migrations_paths) {
66
- migration_path
67
- }
68
- allow(DataMigrate::DatabaseTasks).to receive(:data_migrations_path) {
69
- data_migrations_path
70
- }.at_least(:once)
71
- allow(DataMigrate::DatabaseTasks).to receive(:schema_migrations_path) {
72
- migration_path
73
- }.at_least(:once)
74
- end
75
-
76
- describe :past_migrations do
77
- it do
78
- subject.forward
79
- m = subject.past_migrations
80
- expect(m.count).to eq 1
81
- expect(m.first[:version]).to eq 20091231235959
82
- end
83
-
84
- it "shows nothing without any migrations" do
85
- m = subject.past_migrations
86
- expect(m.count).to eq 0
87
- end
88
- end
89
-
90
- describe :load_schema_current do
91
- before do
92
- allow(DataMigrate::DataMigrator).to receive(:full_migrations_path).and_return(migration_path)
93
- end
94
-
95
- it "loads the current schema file" do
96
- if Rails::VERSION::MAJOR < 6
97
- skip("Not implemented for Rails lower than 6")
98
- end
99
- allow(subject).to receive(:schema_location).and_return("spec/db/data/schema/")
100
-
101
- subject.load_schema_current
102
- versions = DataMigrate::DataSchemaMigration.normalized_versions
103
- expect(versions.count).to eq(2)
104
- end
105
-
106
- it "loads schema file that has not been update with latest data migrations" do
107
- if Rails::VERSION::MAJOR < 6
108
- skip("Not implemented for Rails lower than 6")
109
- end
110
-
111
- allow(subject).to receive(:schema_location).and_return("spec/db/data/partial_schema/")
112
-
113
- subject.load_schema_current
114
- versions = DataMigrate::DataSchemaMigration.normalized_versions
115
- expect(versions.count).to eq(1)
116
- end
117
- end
118
-
119
- describe :forward do
120
-
121
- it "run forward default amount of times" do
122
- subject.forward
123
- versions = DataMigrate::DataSchemaMigration.normalized_versions
124
- expect(versions.count).to eq(1)
125
- end
126
-
127
- it "run forward defined number of times" do
128
- subject.forward(2)
129
- versions = DataMigrate::DataSchemaMigration.normalized_versions
130
- expect(versions.count).to eq(1)
131
- expect(versions.first).to eq "20091231235959"
132
- versions = ActiveRecord::SchemaMigration.normalized_versions
133
- expect(versions.count).to eq(1)
134
- expect(versions.first).to eq "20131111111111"
135
- end
136
- end
137
- end
138
- end
@@ -1,50 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DataMigrate::LegacyMigrator do
4
- let(:context) {
5
- DataMigrate::MigrationContext.new("spec/db/data")
6
- }
7
-
8
- after do
9
- begin
10
- ActiveRecord::Migration.drop_table("data_migrations")
11
- ActiveRecord::Migration.drop_table("schema_migrations")
12
- rescue StandardError
13
- nil
14
- end
15
- end
16
-
17
- before do
18
- ActiveRecord::Base.establish_connection(db_config)
19
- ActiveRecord::SchemaMigration.create_table
20
- DataMigrate::DataSchemaMigration.create_table
21
- end
22
-
23
- let(:db_config) do
24
- {
25
- adapter: "sqlite3",
26
- database: "spec/db/test.db"
27
- }
28
- end
29
-
30
- it "migrate legacy migrations to be in correct table" do
31
- DataMigrate::DataSchemaMigration.create_table
32
- # simulate creation of legacy data migration when
33
- # it was recorded in schema table
34
- ActiveRecord::SchemaMigration.create(version: "20091231235959")
35
-
36
- # create one migration in correct place
37
- DataMigrate::DataSchemaMigration.create(version: "20171231235959")
38
-
39
- migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
40
- expect(migrated.count).to eq 1
41
-
42
- DataMigrate::LegacyMigrator.new("spec/db/data").migrate
43
-
44
- # after migacy migrator has been run, we should have records
45
- # of both migrations
46
- migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
47
- expect(migrated.count).to eq 2
48
- end
49
-
50
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if Rails::VERSION::MAJOR >= 5
4
- subject = DataMigrate::MigrationFive
5
- else
6
- subject = DataMigrate::Migration
7
- end
8
-
9
- describe subject do
10
- it "uses correct table name" do
11
- expect(subject.table_name).to eq("data_migrations")
12
- end
13
-
14
- it "uses correct index name" do
15
- expect(subject).to receive(:table_name_prefix) { "" }
16
- expect(subject).to receive(:table_name_suffix) { "" }
17
- expect(subject.primary_key).to eq("version")
18
- end
19
- end