data_migrate 8.5.0 → 10.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +35 -0
  3. data/.github/workflows/gempush.yml +1 -0
  4. data/.travis.yml +2 -2
  5. data/Appraisals +0 -4
  6. data/Changelog.md +13 -0
  7. data/README.md +3 -3
  8. data/data_migrate.gemspec +1 -10
  9. data/lib/data_migrate/config.rb +1 -1
  10. data/lib/data_migrate/{data_migrator_five.rb → data_migrator.rb} +0 -11
  11. data/lib/data_migrate/database_tasks.rb +12 -72
  12. data/lib/data_migrate/{schema_migration_six.rb → schema_migration.rb} +4 -2
  13. data/lib/data_migrate/{status_service_five.rb → status_service.rb} +12 -6
  14. data/lib/data_migrate/tasks/data_migrate_tasks.rb +19 -39
  15. data/lib/data_migrate/version.rb +1 -1
  16. data/lib/data_migrate.rb +3 -8
  17. data/spec/data_migrate/config_spec.rb +13 -10
  18. data/spec/data_migrate/data_migrator_spec.rb +11 -32
  19. data/spec/data_migrate/data_spec.rb +0 -11
  20. data/spec/data_migrate/database_tasks_spec.rb +10 -58
  21. data/spec/data_migrate/legacy_migrator_spec.rb +6 -18
  22. data/spec/data_migrate/migration.rb +11 -13
  23. data/spec/data_migrate/migration_context_spec.rb +11 -37
  24. data/spec/data_migrate/schema_dumper_spec.rb +10 -23
  25. data/spec/data_migrate/schema_migration_spec.rb +40 -42
  26. data/spec/data_migrate/status_service_spec.rb +26 -55
  27. data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +37 -71
  28. data/spec/db/data/20091231235959_some_name.rb +1 -1
  29. data/spec/db/data/20171231235959_super_update.rb +1 -1
  30. data/spec/spec_helper.rb +2 -8
  31. data/tasks/databases.rake +28 -5
  32. metadata +15 -30
  33. data/Gemfile.rails5.2 +0 -10
  34. data/gemfiles/rails_5.2.gemfile +0 -8
  35. data/lib/data_migrate/schema_migration_five.rb +0 -31
  36. data/spec/db/6.0/20091231235959_some_name.rb +0 -9
  37. data/spec/db/6.0/20171231235959_super_update.rb +0 -9
  38. data/spec/db/data-6.0/20091231235959_some_name.rb +0 -9
  39. data/spec/db/data-6.0/20171231235959_super_update.rb +0 -9
  40. data/spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext +0 -1
  41. data/spec/db/migrate/5.2/20131111111111_late_migration.rb +0 -9
  42. data/spec/db/migrate/5.2/20202020202011_db_migration.rb +0 -9
  43. /data/spec/db/migrate/{6.0/20131111111111_late_migration.rb → 20131111111111_late_migration.rb} +0 -0
  44. /data/spec/db/migrate/{6.0/20202020202011_db_migration.rb → 20202020202011_db_migration.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0ed214d2b242e9802276616e52abc79dc40081b413f6c38cdcbc5414d5897e9
4
- data.tar.gz: f4045cba836825fa34a0da775d38999ea472f2fb8624537e8ffc216f01204e85
3
+ metadata.gz: d212f0e6fa0c9b767cbdf17854c7c52d640a9c8611d0b10ed6c0460de68985cd
4
+ data.tar.gz: ac338ef447f1942d64eb5cf6c0fe520f71089968c04fb03fb829a1318534b4eb
5
5
  SHA512:
6
- metadata.gz: c98becc1b27f1afc98a8e45c4c81ea35195a992f2ff7433d8891b542cc05063dde7ffd1655ba521e14e700e477acc23345b15a893e2a900c508fc0b72c69302c
7
- data.tar.gz: 04560cc96cf6696b032b7a9d6892d70b772801b62910899ea2c360d7a17b98e8ab58bcd535e9a1fbdd40aa07c8633e92f5f52db8f9a6340c00788919eb5acf5b
6
+ metadata.gz: 01ae940433e4cd51a2f421297fb3ffb72372503971ee906164129c035c89aedb6c18d5003cd083930c24245f16728c38c93aed94fb8d9b2f7d0288895362a3d4
7
+ data.tar.gz: 9d94ff40ed274256247960c0dd1325645b638ac2198d29b3bce2c3c11f842b4b0a2b381bd73fcb17af308ab366cdca16c7f99c9e2fa778da7ab6103352e50ba1
@@ -0,0 +1,35 @@
1
+ name: CI
2
+
3
+ on:
4
+ - push
5
+ - pull_request
6
+
7
+ jobs:
8
+ test:
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ os: [ "ubuntu-20.04" ]
13
+ ruby:
14
+ - '2.7'
15
+ - '3.0'
16
+ - '3.1'
17
+ - '3.2'
18
+ gemfile:
19
+ - gemfiles/rails_6.0.gemfile
20
+ - gemfiles/rails_6.1.gemfile
21
+ - gemfiles/rails_7.0.gemfile
22
+ runs-on: ubuntu-latest
23
+ env:
24
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
25
+ RAILS_ENV: test
26
+ steps:
27
+ - name: Checkout code
28
+ uses: actions/checkout@v3
29
+ - name: Set up Ruby
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby }}
33
+ bundler-cache: true
34
+ - name: Run tests
35
+ run: bundle exec rspec
@@ -4,6 +4,7 @@ on:
4
4
  push:
5
5
  branches:
6
6
  - main
7
+ - chaunce-multiple_connection_support
7
8
 
8
9
  jobs:
9
10
  build:
data/.travis.yml CHANGED
@@ -2,13 +2,13 @@ language: ruby
2
2
  rvm:
3
3
  - 2.7
4
4
  - 3.0
5
+ - 3.2
5
6
  script: bundle exec rspec
6
7
  gemfile:
7
- - gemfiles/rails_5.2.gemfile
8
8
  - gemfiles/rails_6.0.gemfile
9
9
  - gemfiles/rails_6.1.gemfile
10
10
  - gemfiles/rails_7.0.gemfile
11
11
  jobs:
12
12
  exclude:
13
13
  - rvm: 3.0
14
- gemfile: gemfiles/rails_5.2.gemfile
14
+ - rvm: 3.2
data/Appraisals CHANGED
@@ -1,7 +1,3 @@
1
- appraise 'rails-5.2' do
2
- gem 'rails', '~> 5.2.3'
3
- end
4
-
5
1
  appraise 'rails-6.0' do
6
2
  gem 'rails', '~> 6.0.0'
7
3
  end
data/Changelog.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 10.0.0.rc1
4
+
5
+ - Changes by [chaunce](https//:github.com/chaunce)
6
+ - Multiple databases support
7
+ - Refactor to clean things up
8
+ - Deprecate rails 5.2 support for real
9
+
10
+
11
+ ## 9.0.0
12
+
13
+ Ruby 3.2 support [mehanoid](https://github.com/mehanoid)
14
+ Rails 5.2 is no longer supported
15
+
3
16
  ## 8.5.0
4
17
 
5
18
  Allow custom templates [bazay](https://github.com/bazay)
data/README.md CHANGED
@@ -36,7 +36,7 @@ table to track all migrations.
36
36
 
37
37
  ## Rails Support
38
38
 
39
- Support Rails 5.2 through 7.0
39
+ Support Rails 6.0 through 7.0
40
40
 
41
41
 
42
42
  #### v1
@@ -162,9 +162,9 @@ Run tests for a specific version of Rails
162
162
 
163
163
  ```
164
164
  bundle exec appraisal install
165
- bundle exec appraisal rails-5.1 rspec
166
- bundle exec appraisal rails-5.2 rspec
167
165
  bundle exec appraisal rails-6.0 rspec
166
+ bundle exec appraisal rails-6.1 rspec
167
+ bundle exec appraisal rails-7.0 rspec
168
168
  ```
169
169
 
170
170
  ## Thanks
data/data_migrate.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  activerecord
20
20
  railties
21
21
  ].each do |rails_gem|
22
- s.add_dependency(rails_gem, '>= 5.0')
22
+ s.add_dependency(rails_gem, '>= 6.0')
23
23
  end
24
24
 
25
25
  s.add_development_dependency "appraisal"
@@ -38,13 +38,4 @@ Gem::Specification.new do |s|
38
38
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
39
39
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
40
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
41
  end
@@ -25,7 +25,7 @@ module DataMigrate
25
25
 
26
26
  def data_template_path=(value)
27
27
  @data_template_path = value.tap do |path|
28
- raise ArgumentError, "File not found: '#{path}'" unless path == DEFAULT_DATA_TEMPLATE_PATH || File.exists?(path)
28
+ raise ArgumentError, "File not found: '#{path}'" unless path == DEFAULT_DATA_TEMPLATE_PATH || File.exist?(path)
29
29
  end
30
30
  end
31
31
  end
@@ -10,7 +10,6 @@ module DataMigrate
10
10
  end
11
11
 
12
12
  def self.assure_data_schema_table
13
- ActiveRecord::Base.establish_connection(db_config)
14
13
  DataMigrate::DataSchemaMigration.create_table
15
14
  end
16
15
 
@@ -73,16 +72,6 @@ module DataMigrate
73
72
  def rollback(migrations_path, steps)
74
73
  DataMigrate::MigrationContext.new(migrations_path).rollback(steps)
75
74
  end
76
-
77
- def db_config
78
- env = Rails.env || "development"
79
- ar_config = if (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 6
80
- ActiveRecord::Base.configurations.configs_for(env_name: env).first
81
- else
82
- ActiveRecord::Base.configurations[env]
83
- end
84
- ar_config || ENV["DATABASE_URL"]
85
- end
86
75
  end
87
76
 
88
77
  private
@@ -13,32 +13,14 @@ module DataMigrate
13
13
  "data_schema.rb"
14
14
  end
15
15
 
16
- def dump_filename(namespace, format = ActiveRecord::Base.schema_format)
17
- filename = if namespace == "primary"
16
+ def dump_filename(spec_name, format = ActiveRecord::Base.schema_format)
17
+ filename = if spec_name == "primary"
18
18
  schema_file_type(format)
19
19
  else
20
- "#{namespace}_#{schema_file_type(format)}"
20
+ "#{spec_name}_#{schema_file_type(format)}"
21
21
  end
22
22
 
23
- ENV["DATA_SCHEMA"] || File.join(schema_location, filename)
24
- end
25
-
26
- def schema_dump_path(db_config, format = ActiveRecord.schema_format)
27
- return ENV["DATA_SCHEMA"] if ENV["DATA_SCHEMA"]
28
-
29
- filename = if db_config.primary?
30
- schema_file_type(format)
31
- else
32
- [db_config.name, schema_file_type(format)].join("_")
33
- end
34
-
35
- return unless filename
36
-
37
- File.dirname(filename) == schema_location ? filename : File.join(schema_location, filename)
38
- end
39
-
40
- def schema_location
41
- db_dir
23
+ ENV["DATA_SCHEMA"] || File.join(db_dir, filename)
42
24
  end
43
25
 
44
26
  def check_schema_file(filename)
@@ -55,9 +37,8 @@ module DataMigrate
55
37
  )
56
38
  end
57
39
 
58
- def sort_migrations set_1, set_2=nil
59
- migrations = set_1 + (set_2 || [])
60
- migrations.sort{|a,b| sort_string(a) <=> sort_string(b)}
40
+ def sort_migrations(*migrations)
41
+ migrations.flatten.sort { |a, b| sort_string(a) <=> sort_string(b) }
61
42
  end
62
43
 
63
44
  def sort_string migration
@@ -83,11 +64,6 @@ module DataMigrate
83
64
  end
84
65
  end
85
66
 
86
- # This overrides ActiveRecord::Tasks::DatabaseTasks
87
- def self.schema_file(_format = nil)
88
- File.join(db_dir, "data_schema.rb")
89
- end
90
-
91
67
  def self.forward(step = 1)
92
68
  DataMigrate::DataMigrator.assure_data_schema_table
93
69
  migrations = pending_migrations.reverse.pop(step).reverse
@@ -97,23 +73,11 @@ module DataMigrate
97
73
  DataMigrate::DataMigrator.run(:up, data_migrations_path, pending_migration[:version])
98
74
  elsif pending_migration[:kind] == :schema
99
75
  ActiveRecord::Migration.write("== %s %s" % ["Schema", "=" * 69])
100
- DataMigrate::SchemaMigration.run(:up, schema_migrations_path, pending_migration[:version])
76
+ DataMigrate::SchemaMigration.run(:up, DataMigrate::SchemaMigration.migrations_paths, pending_migration[:version])
101
77
  end
102
78
  end
103
79
  end
104
80
 
105
- def self.data_migrations_path
106
- DataMigrate.config.data_migrations_path
107
- end
108
-
109
- def self.schema_migrations_path
110
- "db/migrate/"
111
- end
112
-
113
- def self.pending_migrations
114
- sort_migrations(pending_schema_migrations, pending_data_migrations)
115
- end
116
-
117
81
  def self.pending_data_migrations
118
82
  data_migrations = DataMigrate::DataMigrator.migrations(data_migrations_path)
119
83
  sort_migrations(DataMigrate::DataMigrator.new(:up, data_migrations ).
@@ -124,36 +88,12 @@ module DataMigrate
124
88
  ::DataMigrate::SchemaMigration.pending_schema_migrations
125
89
  end
126
90
 
127
- def self.sort_migrations(set1, set2 = nil)
128
- migrations = set1 + (set2 || [])
129
- migrations.sort {|a, b| sort_string(a) <=> sort_string(b)}
130
- end
131
-
132
- def self.sort_string(migration)
133
- "#{migration[:version]}_#{migration[:kind] == :data ? 1 : 0}"
134
- end
135
-
136
91
  def self.past_migrations(sort = nil)
137
- sort = sort.downcase if sort
138
- db_list_data =
139
- if DataMigrate::DataSchemaMigration.table_exists?
140
- DataMigrate::DataSchemaMigration.normalized_versions.sort
141
- else
142
- []
143
- end
144
- db_list_schema = ActiveRecord::SchemaMigration.normalized_versions.sort.sort
145
- migrations = db_list_data.map do |d|
146
- {
147
- version: d.to_i, kind: :data
148
- }
149
- end +
150
- db_list_schema.map do |d|
151
- {
152
- version: d.to_i, kind: :schema
153
- }
154
- end
155
-
156
- sort == "asc" ? sort_migrations(migrations) : sort_migrations(migrations).reverse
92
+ data_versions = DataMigrate::DataSchemaMigration.table_exists? ? DataMigrate::DataSchemaMigration.normalized_versions : []
93
+ schema_versions = ActiveRecord::SchemaMigration.normalized_versions
94
+ migrations = data_versions.map { |v| { version: v.to_i, kind: :data } } + schema_versions.map { |v| { version: v.to_i, kind: :schema } }
95
+
96
+ sort&.downcase == "asc" ? sort_migrations(migrations) : sort_migrations(migrations).reverse
157
97
  end
158
98
  end
159
99
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DataMigrate
2
4
  # Helper class to getting access to db schema
3
5
  # to allow data/schema combiation tasks
@@ -22,9 +24,9 @@ module DataMigrate
22
24
 
23
25
  def self.migrations_paths
24
26
  spec_name = DataMigrate.config.spec_name
25
- if spec_name && Rails.version > '6.1'
27
+ if spec_name && Gem::Dependency.new("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
26
28
  ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: spec_name).migrations_paths
27
- elsif spec_name
29
+ elsif spec_name && Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
28
30
  ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: spec_name).migrations_paths
29
31
  else
30
32
  Rails.application.config.paths["db/migrate"].to_a
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DataMigrate
2
4
  class StatusService
3
5
  class << self
@@ -32,12 +34,8 @@ module DataMigrate
32
34
  end
33
35
 
34
36
  # output
35
- if ActiveRecord.version >= Gem::Version.new('7.0')
36
- stream.puts "\ndatabase: #{ActiveRecord::Base.connection_db_config.configuration_hash[:database]}\n\n"
37
- else
38
- stream.puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n"
39
- end
40
- stream.puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
37
+ stream.puts "\ndatabase: #{database_name}\n\n"
38
+ stream.puts "#{"Status".center(8)} #{"Migration ID".ljust(14)} Migration Name"
41
39
  stream.puts "-" * 50
42
40
  db_list.each do |status, version, name|
43
41
  stream.puts "#{status.center(8)} #{version.ljust(14)} #{name}"
@@ -45,6 +43,14 @@ module DataMigrate
45
43
  stream.puts
46
44
  end
47
45
 
46
+ def database_name
47
+ if Gem::Dependency.new("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
48
+ ActiveRecord::Base.connection_db_config.configuration_hash[:database]
49
+ elsif Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
50
+ ActiveRecord::Base.connection_config[:database]
51
+ end
52
+ end
53
+
48
54
  def db_list
49
55
  DataMigrate::DataMigrator.migrations_status
50
56
  end
@@ -1,19 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DataMigrate
2
4
  module Tasks
3
5
  module DataMigrateTasks
4
6
  extend self
5
7
 
6
- def schema_migrations_path
7
- File.join('db', 'migrate')
8
- end
9
-
10
8
  def migrations_paths
11
9
  @migrations_paths ||= DataMigrate.config.data_migrations_path
12
10
  end
13
11
 
14
- def dump
12
+ def dump(db_config)
15
13
  if dump_schema_after_migration?
16
- filename = DataMigrate::DatabaseTasks.schema_file
14
+ filename = DataMigrate::DatabaseTasks.dump_filename(spec_name(db_config), ActiveRecord::Base.schema_format)
17
15
  ActiveRecord::Base.establish_connection(DataMigrate.config.db_configuration) if DataMigrate.config.db_configuration
18
16
  File.open(filename, "w:utf-8") do |file|
19
17
  DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, file)
@@ -30,7 +28,7 @@ module DataMigrate
30
28
 
31
29
  def abort_if_pending_migrations(migrations, message)
32
30
  if migrations.any?
33
- puts "You have #{migrations.size} pending #{migrations.size > 1 ? 'migrations:' : 'migration:'}"
31
+ puts "You have #{migrations.size} pending #{'migration'.pluralize(migrations.size)}:"
34
32
  migrations.each do |pending_migration|
35
33
  puts " %4d %s" % [pending_migration[:version], pending_migration[:name]]
36
34
  end
@@ -46,25 +44,16 @@ module DataMigrate
46
44
  end
47
45
  end
48
46
 
49
- def status
50
- config = connect_to_database
51
- return unless config
52
-
53
- connection = ActiveRecord::Base.connection
54
- puts "\ndatabase: #{config['database']}\n\n"
55
- DataMigrate::StatusService.dump(connection)
47
+ def status(db_config)
48
+ puts "\ndatabase: #{spec_name(db_config)}\n\n"
49
+ DataMigrate::StatusService.dump(ActiveRecord::Base.connection)
56
50
  end
57
51
 
58
- def status_with_schema
59
- config = connect_to_database
60
- return unless config
61
-
52
+ def status_with_schema(db_config)
62
53
  db_list_data = ActiveRecord::Base.connection.select_values(
63
54
  "SELECT version FROM #{DataMigrate::DataSchemaMigration.table_name}"
64
55
  )
65
- db_list_schema = ActiveRecord::Base.connection.select_values(
66
- "SELECT version FROM #{ActiveRecord::SchemaMigration.schema_migrations_table_name}"
67
- )
56
+ db_list_schema = ActiveRecord::SchemaMigration.all.pluck(:version)
68
57
  file_list = []
69
58
 
70
59
  Dir.foreach(File.join(Rails.root, migrations_paths)) do |file|
@@ -75,7 +64,9 @@ module DataMigrate
75
64
  end
76
65
  end
77
66
 
78
- Dir.foreach(File.join(Rails.root, schema_migrations_path)) do |file|
67
+ DataMigrate::SchemaMigration.migrations_paths.map do |path|
68
+ Dir.children(path) if Dir.exist?(path)
69
+ end.flatten.compact.each do |file|
79
70
  # only files matching "20091231235959_some_name.rb" pattern
80
71
  if match_data = /(\d{14})_(.+)\.rb/.match(file)
81
72
  status = db_list_schema.delete(match_data[1]) ? 'up' : 'down'
@@ -86,7 +77,7 @@ module DataMigrate
86
77
  file_list.sort!{|a,b| "#{a[1]}_#{a[3] == 'data' ? 1 : 0}" <=> "#{b[1]}_#{b[3] == 'data' ? 1 : 0}" }
87
78
 
88
79
  # output
89
- puts "\ndatabase: #{config['database']}\n\n"
80
+ puts "\ndatabase: #{spec_name(db_config)}\n\n"
90
81
  puts "#{"Status".center(8)} #{"Type".center(8)} #{"Migration ID".ljust(14)} Migration Name"
91
82
  puts "-" * 60
92
83
  file_list.each do |file|
@@ -103,23 +94,12 @@ module DataMigrate
103
94
 
104
95
  private
105
96
 
106
- def connect_to_database
107
- config = if ActiveRecord.version < Gem::Version.new('6.1')
108
- ActiveRecord::Base.configurations[Rails.env || 'development']
109
- else
110
- ActiveRecord::Base.configurations.find_db_config(Rails.env || 'development').configuration_hash
111
- end
112
- ActiveRecord::Base.establish_connection(config)
113
-
114
- unless DataMigrate::DataSchemaMigration.table_exists?
115
- puts 'Data migrations table does not exist yet.'
116
- config = nil
117
- end
118
- unless ActiveRecord::SchemaMigration.table_exists?
119
- puts 'Schema migrations table does not exist yet.'
120
- config = nil
97
+ def spec_name(db_config)
98
+ if Gem::Dependency.new("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
99
+ db_config.name
100
+ elsif Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
101
+ db_config.spec_name
121
102
  end
122
- config
123
103
  end
124
104
  end
125
105
  end
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "8.5.0".freeze
2
+ VERSION = "10.0.0.rc1".freeze
3
3
  end
data/lib/data_migrate.rb CHANGED
@@ -1,22 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator_five")
3
+ require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator")
4
4
  require File.join(File.dirname(__FILE__), "data_migrate", "data_schema_migration")
5
5
  require File.join(File.dirname(__FILE__), "data_migrate", "data_schema")
6
6
  require File.join(File.dirname(__FILE__), "data_migrate", "database_tasks")
7
7
  require File.join(File.dirname(__FILE__), "data_migrate", "schema_dumper")
8
- require File.join(File.dirname(__FILE__), "data_migrate", "status_service_five")
8
+ require File.join(File.dirname(__FILE__), "data_migrate", "status_service")
9
9
  require File.join(File.dirname(__FILE__), "data_migrate", "migration_context")
10
10
  require File.join(File.dirname(__FILE__), "data_migrate", "railtie")
11
11
  require File.join(File.dirname(__FILE__), "data_migrate", "tasks/data_migrate_tasks")
12
12
  require File.join(File.dirname(__FILE__), "data_migrate", "legacy_migrator")
13
13
  require File.join(File.dirname(__FILE__), "data_migrate", "config")
14
-
15
- if Rails::VERSION::MAJOR == 5
16
- require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_five")
17
- else
18
- require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_six")
19
- end
14
+ require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration")
20
15
 
21
16
  module DataMigrate
22
17
  def self.root
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe DataMigrate::Config do
@@ -11,41 +13,42 @@ describe DataMigrate::Config do
11
13
 
12
14
  describe "data migration path configured" do
13
15
  subject { DataMigrate.config.data_migrations_path }
16
+ let(:data_migrations_path) { "db/awesome/" }
17
+
14
18
  before do
15
- @before = DataMigrate.config.data_migrations_path
19
+ @original_data_migrations_path = DataMigrate.config.data_migrations_path
20
+
16
21
  DataMigrate.configure do |config|
17
- config.data_migrations_path = "db/awesome/"
22
+ config.data_migrations_path = data_migrations_path
18
23
  end
19
24
  end
20
25
 
21
26
  after do
22
27
  DataMigrate.configure do |config|
23
- config.data_migrations_path = @before
28
+ config.data_migrations_path = @original_data_migrations_path
24
29
  end
25
30
  end
26
31
 
27
32
  it "equals the custom data migration path" do
28
- is_expected.to eq "db/awesome/"
33
+ is_expected.to eq(data_migrations_path)
29
34
  end
30
35
  end
31
36
 
32
37
  describe "data template path configured" do
33
38
  subject { DataMigrate.config.data_template_path }
39
+ let(:data_template_path) { File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb") }
34
40
 
35
41
  before do
36
- @before = DataMigrate.config.data_template_path
42
+ @original_data_migrations_path = DataMigrate.config.data_template_path
43
+
37
44
  DataMigrate.configure do |config|
38
45
  config.data_template_path = data_template_path
39
46
  end
40
47
  end
41
48
 
42
- let(:data_template_path) do
43
- File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb")
44
- end
45
-
46
49
  after do
47
50
  DataMigrate.configure do |config|
48
- config.data_template_path = @before
51
+ config.data_template_path = @original_data_migrations_path
49
52
  end
50
53
  end
51
54
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe DataMigrate::DataMigrator do
@@ -10,25 +12,18 @@ describe DataMigrate::DataMigrator do
10
12
  end
11
13
 
12
14
  before do
13
- allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
14
15
  ActiveRecord::Base.establish_connection(db_config)
16
+ ::ActiveRecord::SchemaMigration.create_table
17
+ DataMigrate::DataSchemaMigration.create_table
15
18
  end
16
19
 
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
20
+ after do
21
+ ActiveRecord::Migration.drop_table("data_migrations") rescue nil
22
+ ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
23
+ end
29
24
 
30
- it do
31
- subject.assure_data_schema_table
25
+ describe ".load_migrated" do
26
+ it "loads migrated versions" do
32
27
  DataMigrate::DataSchemaMigration.create(version: 20090000000000)
33
28
  ::ActiveRecord::SchemaMigration.create(version: 20100000000000)
34
29
  DataMigrate::DataSchemaMigration.create(version: 20110000000000)
@@ -41,16 +36,7 @@ describe DataMigrate::DataMigrator do
41
36
  end
42
37
 
43
38
  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
39
+ it "creates the data_migrations table" do
54
40
  ActiveRecord::Migration.drop_table("data_migrations") rescue nil
55
41
  subject.assure_data_schema_table
56
42
  expect(
@@ -60,13 +46,6 @@ describe DataMigrate::DataMigrator do
60
46
  end
61
47
 
62
48
  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
49
  it "returns all migrations statuses" do
71
50
  status = subject.migrations_status
72
51
  expect(status.length).to eq 2
@@ -4,12 +4,6 @@ require "spec_helper"
4
4
 
5
5
  describe DataMigrate::Data do
6
6
  let(:subject) { DataMigrate::Data }
7
- let(:db_config) do
8
- {
9
- adapter: "sqlite3",
10
- database: "spec/db/test.db"
11
- }
12
- end
13
7
  let(:fixture_file_timestamps) do
14
8
  %w[20091231235959 20101231235959 20111231235959]
15
9
  end
@@ -28,11 +22,6 @@ describe DataMigrate::Data do
28
22
  end
29
23
 
30
24
  describe :define do
31
- before do
32
- allow(DataMigrate::DataMigrator).
33
- to receive(:db_config) { db_config }
34
- end
35
-
36
25
  after do
37
26
  ActiveRecord::Migration.drop_table("data_migrations")
38
27
  end