data_migrate 7.0.2 → 8.0.0.rc1

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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +5 -7
  4. data/Appraisals +4 -8
  5. data/Changelog.md +4 -0
  6. data/Gemfile +0 -7
  7. data/gemfiles/{rails_5.1.gemfile → rails_7.0.gemfile} +1 -1
  8. data/lib/data_migrate/database_tasks.rb +14 -0
  9. data/lib/data_migrate/status_service_five.rb +5 -1
  10. data/lib/data_migrate/tasks/data_migrate_tasks.rb +12 -8
  11. data/lib/data_migrate/version.rb +1 -1
  12. data/lib/data_migrate.rb +10 -32
  13. data/lib/generators/data_migration/data_migration_generator.rb +1 -7
  14. data/spec/data_migrate/database_tasks_spec.rb +4 -9
  15. data/spec/data_migrate/migration_context_spec.rb +6 -14
  16. data/spec/data_migrate/schema_migration_spec.rb +21 -22
  17. data/spec/generators/data_migration/data_migration_generator_spec.rb +7 -7
  18. data/spec/spec_helper.rb +3 -13
  19. metadata +6 -22
  20. data/Gemfile.rails5 +0 -10
  21. data/Gemfile.rails5.1 +0 -10
  22. data/gemfiles/rails_4.1.gemfile +0 -7
  23. data/gemfiles/rails_4.2.gemfile +0 -9
  24. data/gemfiles/rails_5.0.gemfile +0 -8
  25. data/lib/data_migrate/data_migrator.rb +0 -101
  26. data/lib/data_migrate/migration.rb +0 -26
  27. data/lib/data_migrate/migration_five.rb +0 -26
  28. data/lib/data_migrate/schema_migration.rb +0 -31
  29. data/lib/data_migrate/status_service.rb +0 -65
  30. data/spec/db/5.0/20091231235959_some_name.rb +0 -9
  31. data/spec/db/5.0/20171231235959_super_update.rb +0 -9
  32. data/spec/db/migrate/4.2/20131111111111_late_migration.rb +0 -9
  33. data/spec/db/migrate/4.2/20202020202011_db_migration.rb +0 -9
  34. data/spec/db/migrate/5.0/20131111111111_late_migration.rb +0 -9
  35. data/spec/db/migrate/5.0/20202020202011_db_migration.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d029ae70dba905ed85200561697e4e44b62b654ab216d6b20b809737e35f3fc1
4
- data.tar.gz: 39f53a2d2f289d8d55730f9657bbaef454abff395593e354fa31ef11b1a38dd3
3
+ metadata.gz: af0b932d1ca71e8bd2218c66a901c7f4075722fc716d4acf2ba20356cec069a7
4
+ data.tar.gz: cd0193ea16bac2ef7f21df588ff0c673e9e7706b99a55ae82452d0843c47b5d7
5
5
  SHA512:
6
- metadata.gz: b0e7f347d47d48acab66cb3e700f72321805ee29fbed1bbb7689bfaafb0f7cff6a0add4a62ec847cb0d49dd18b46f9408b3b8d3a2bf56c0fa1c2a75dcabb3277
7
- data.tar.gz: 63a062d5266920ecddd9d18a781f9105390f9188cc9ed6cc4930a99821ab2ed972dae7cb2687de9202c0a26fcf29040eb77aae78215e43401d234685116a7981
6
+ metadata.gz: 20ddb8b51aa8f5fa817490baf8d016e594d15ed5a5f896fb26205fb629a2de29a5f9630a4992603d695219a8bf7d2b559c70968a6f6df6b0ec2529a9d388b6dd
7
+ data.tar.gz: 5f879b36def5b29a024d01144663887a03cf296f2a09a3b65962ffbdb1851fdd2c383f379ec548607fd1df414fc71b47283694ae86d53c251692fdce0380c76c
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.1
1
+ 2.7.5
data/.travis.yml CHANGED
@@ -1,16 +1,14 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.6
4
3
  - 2.7
4
+ - 3.0
5
5
  script: bundle exec rspec
6
6
  gemfile:
7
- - gemfiles/rails_5.1.gemfile
8
7
  - gemfiles/rails_5.2.gemfile
9
8
  - gemfiles/rails_6.0.gemfile
10
9
  - gemfiles/rails_6.1.gemfile
11
- matrix:
10
+ - gemfiles/rails_7.0.gemfile
11
+ jobs:
12
12
  exclude:
13
- - rvm: 2.4.4
14
- gemfile: gemfiles/rails_6.0.gemfile
15
- - rvm: 2.4.4
16
- gemfile: gemfiles/rails_6.1.gemfile
13
+ - rvm: 3.0
14
+ gemfile: gemfiles/rails_5.2.gemfile
data/Appraisals CHANGED
@@ -1,11 +1,3 @@
1
- appraise 'rails-5.0' do
2
- gem 'rails', '5.0.7.2'
3
- end
4
-
5
- appraise 'rails-5.1' do
6
- gem 'rails', '5.1.7'
7
- end
8
-
9
1
  appraise 'rails-5.2' do
10
2
  gem 'rails', '~> 5.2.3'
11
3
  end
@@ -17,3 +9,7 @@ end
17
9
  appraise 'rails-6.1' do
18
10
  gem 'rails', '~> 6.1.0'
19
11
  end
12
+
13
+ appraise 'rails-7.0' do
14
+ gem 'rails', '~> 7.0'
15
+ end
data/Changelog.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.0.0.rc1
4
+ Add support for Rails 7
5
+ Removed support for Rails versions below 5.2. Now are supported only versions Rails 5.2 and up
6
+
3
7
  ## 7.0.2
4
8
 
5
9
  Remove magic comment in migration files [y-yagi](https://github.com/y-yagi)
data/Gemfile CHANGED
@@ -1,11 +1,4 @@
1
1
  source "http://rubygems.org"
2
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.0.0'
9
- end
10
3
  gem 'sqlite3', "~> 1.4"
11
4
  gemspec
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "5.1.7"
6
5
  gem "sqlite3", "~> 1.4"
6
+ gem "rails", "~> 7.0"
7
7
 
8
8
  gemspec path: "../"
@@ -23,6 +23,20 @@ module DataMigrate
23
23
  ENV["DATA_SCHEMA"] || File.join(schema_location, filename)
24
24
  end
25
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
+
26
40
  def schema_location
27
41
  db_dir
28
42
  end
@@ -32,7 +32,11 @@ module DataMigrate
32
32
  end
33
33
 
34
34
  # output
35
- stream.puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n"
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
36
40
  stream.puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
37
41
  stream.puts "-" * 50
38
42
  db_list.each do |status, version, name|
@@ -7,7 +7,7 @@ module DataMigrate
7
7
  end
8
8
 
9
9
  def dump
10
- if ActiveRecord::Base.dump_schema_after_migration
10
+ if dump_schema_after_migration?
11
11
  filename = DataMigrate::DatabaseTasks.schema_file
12
12
  ActiveRecord::Base.establish_connection(DataMigrate.config.db_configuration) if DataMigrate.config.db_configuration
13
13
  File.open(filename, "w:utf-8") do |file|
@@ -17,14 +17,10 @@ module DataMigrate
17
17
  end
18
18
 
19
19
  def migrate
20
- DataMigrate::DataMigrator.assure_data_schema_table
21
20
  target_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
22
- if (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2) ||
23
- Rails::VERSION::MAJOR == 6
24
- DataMigrate::MigrationContext.new(migrations_paths).migrate(target_version)
25
- else
26
- DataMigrate::DataMigrator.migrate(migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
27
- end
21
+
22
+ DataMigrate::DataMigrator.assure_data_schema_table
23
+ DataMigrate::MigrationContext.new(migrations_paths).migrate(target_version)
28
24
  end
29
25
 
30
26
  def abort_if_pending_migrations(migrations, message)
@@ -36,6 +32,14 @@ module DataMigrate
36
32
  abort message
37
33
  end
38
34
  end
35
+
36
+ def dump_schema_after_migration?
37
+ if ActiveRecord.respond_to?(:dump_schema_after_migration)
38
+ ActiveRecord.dump_schema_after_migration
39
+ else
40
+ ActiveRecord::Base.dump_schema_after_migration
41
+ end
42
+ end
39
43
  end
40
44
  end
41
45
  end
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "7.0.2".freeze
2
+ VERSION = "8.0.0.rc1".freeze
3
3
  end
data/lib/data_migrate.rb CHANGED
@@ -1,44 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if Rails::VERSION::MAJOR == 6
4
- require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator_five")
5
- elsif Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2
6
- require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator_five")
7
- else
8
- require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator")
9
- end
10
- require File.join(File.dirname(__FILE__), "data_migrate",
11
- "data_schema_migration")
3
+ require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator_five")
4
+ require File.join(File.dirname(__FILE__), "data_migrate", "data_schema_migration")
12
5
  require File.join(File.dirname(__FILE__), "data_migrate", "data_schema")
13
6
  require File.join(File.dirname(__FILE__), "data_migrate", "database_tasks")
14
7
  require File.join(File.dirname(__FILE__), "data_migrate", "schema_dumper")
15
- if Rails::VERSION::MAJOR == 6
16
- require File.join(File.dirname(__FILE__), "data_migrate", "status_service_five")
17
- require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_six")
18
- elsif Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2
19
- require File.join(File.dirname(__FILE__), "data_migrate", "status_service_five")
20
- require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_five")
21
- else
22
- require File.join(File.dirname(__FILE__), "data_migrate", "status_service")
23
- require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration")
24
- end
25
-
26
- if Rails::VERSION::MAJOR == 6
27
- require File.join(File.dirname(__FILE__), "data_migrate", "migration_context")
28
- # require File.join(File.dirname(__FILE__), "data_migrate", "migration_five")
29
- elsif Rails::VERSION::MAJOR == 5
30
- if Rails::VERSION::MINOR == 2
31
- require File.join(File.dirname(__FILE__), "data_migrate", "migration_context")
32
- else
33
- require File.join(File.dirname(__FILE__), "data_migrate", "migration_five")
34
- end
35
- else
36
- require File.join(File.dirname(__FILE__), "data_migrate", "migration")
37
- end
8
+ require File.join(File.dirname(__FILE__), "data_migrate", "status_service_five")
9
+ require File.join(File.dirname(__FILE__), "data_migrate", "migration_context")
38
10
  require File.join(File.dirname(__FILE__), "data_migrate", "railtie")
39
11
  require File.join(File.dirname(__FILE__), "data_migrate", "tasks/data_migrate_tasks")
40
12
  require File.join(File.dirname(__FILE__), "data_migrate", "legacy_migrator")
41
13
  require File.join(File.dirname(__FILE__), "data_migrate", "config")
42
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
20
+
43
21
  module DataMigrate
44
22
  end
@@ -27,13 +27,7 @@ module DataMigrate
27
27
  end
28
28
 
29
29
  def migration_base_class_name
30
- if ActiveRecord.version >= Gem::Version.new("5.0")
31
- "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
32
- elsif ActiveRecord.version >= Gem::Version.new("5.2")
33
- "DataMigrate::MigrationContext"
34
- else
35
- "ActiveRecord::Migration"
36
- end
30
+ "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
37
31
  end
38
32
 
39
33
  def data_migrations_file_path
@@ -5,16 +5,10 @@ require "spec_helper"
5
5
  describe DataMigrate::DatabaseTasks do
6
6
  let(:subject) { DataMigrate::DatabaseTasks }
7
7
  let(:migration_path) {
8
- if Rails::VERSION::MAJOR == 6
9
- "spec/db/migrate/6.0"
10
- elsif Rails::VERSION::MAJOR == 5
11
- if Rails::VERSION::MINOR == 2
12
- "spec/db/migrate/5.2"
13
- else
14
- "spec/db/migrate/5.0"
15
- end
8
+ if Rails::VERSION::MAJOR == 5
9
+ "spec/db/migrate/5.2"
16
10
  else
17
- "spec/db/migrate/4.2"
11
+ "spec/db/migrate/6.0"
18
12
  end
19
13
  }
20
14
  let(:data_migrations_path) {
@@ -32,6 +26,7 @@ describe DataMigrate::DatabaseTasks do
32
26
  # Rails.application.config.paths["db"].first
33
27
  # @see https://github.com/rails/rails/blob/a7d49ef78c36df2d1ca876451f30915ada1079a5/activerecord/lib/active_record/tasks/database_tasks.rb#L54
34
28
  allow(subject).to receive(:db_dir).and_return("db")
29
+ allow(ActiveRecord::Tasks::DatabaseTasks).to receive(:db_dir).and_return("db")
35
30
  end
36
31
 
37
32
  before do
@@ -2,28 +2,20 @@ require "spec_helper"
2
2
 
3
3
  describe DataMigrate::DataMigrator do
4
4
  let(:context) {
5
- if (Rails::VERSION::MAJOR == 6)
6
- DataMigrate::MigrationContext.new("spec/db/data-6.0")
7
- else
5
+ if (Rails::VERSION::MAJOR == 5)
8
6
  DataMigrate::MigrationContext.new("spec/db/data")
7
+ else
8
+ DataMigrate::MigrationContext.new("spec/db/data-6.0")
9
9
  end
10
10
  }
11
11
  let(:schema_context) {
12
- if (Rails::VERSION::MAJOR == 6)
13
- ActiveRecord::MigrationContext.new("spec/db/migrate/6.0", ActiveRecord::Base.connection.schema_migration)
14
- else
12
+ if (Rails::VERSION::MAJOR == 5)
15
13
  ActiveRecord::MigrationContext.new("spec/db/migrate/5.2")
14
+ else
15
+ ActiveRecord::MigrationContext.new("spec/db/migrate/6.0", ActiveRecord::Base.connection.schema_migration)
16
16
  end
17
17
  }
18
18
 
19
- before do
20
- unless (Rails::VERSION::MAJOR == 5 and
21
- Rails::VERSION::MINOR == 2) ||
22
- Rails::VERSION::MAJOR == 6
23
- skip("Tests are only applicable for Rails 5.2")
24
- end
25
- end
26
-
27
19
  after do
28
20
  begin
29
21
  ActiveRecord::Migration.drop_table("data_migrations")
@@ -4,16 +4,10 @@ require "spec_helper"
4
4
 
5
5
  describe DataMigrate::SchemaMigration do
6
6
  let(:migration_path) {
7
- if Rails::VERSION::MAJOR == 6
8
- "spec/db/migrate/6.0"
9
- elsif Rails::VERSION::MAJOR == 5
10
- if Rails::VERSION::MINOR == 2
11
- "spec/db/migrate/5.2"
12
- else
13
- "spec/db/migrate/5.0"
14
- end
7
+ if Rails::VERSION::MAJOR == 5
8
+ "spec/db/migrate/5.2"
15
9
  else
16
- "spec/db/migrate/4.2"
10
+ "spec/db/migrate/6.0"
17
11
  end
18
12
  }
19
13
 
@@ -72,22 +66,27 @@ describe DataMigrate::SchemaMigration do
72
66
  if Rails.version > '6'
73
67
  describe :migrations_paths do
74
68
  context 'when a db_name is configured' do
69
+ let(:config) { double(:config) }
75
70
  let(:paths) { ['spec/db/migrate/6.0', 'spec/db/components/migrate/6.0'] }
76
-
77
- if Rails.version > '6.1'
78
- before do
79
- allow(ActiveRecord::Base.configurations.configs_for(env_name: 'test', name: 'primary')).to receive(:migrations_paths).and_return(paths)
80
- DataMigrate.configure do |config|
81
- config.spec_name = 'primary'
82
- end
71
+ let(:config_options) do
72
+ if Rails.version > '6.1'
73
+ { env_name: 'test', name: 'primary' }
74
+ else
75
+ { env_name: 'test', spec_name: 'primary' }
83
76
  end
84
- else
85
- before do
86
- allow(ActiveRecord::Base.configurations.configs_for(env_name: 'test', spec_name: 'primary')).to receive(:migrations_paths).and_return(paths)
87
- DataMigrate.configure do |config|
88
- config.spec_name = 'primary'
89
- end
77
+ end
78
+
79
+ before do
80
+ DataMigrate.configure do |config|
81
+ config.spec_name = 'primary'
90
82
  end
83
+
84
+ allow(ActiveRecord::Base.configurations)
85
+ .to receive(:configs_for)
86
+ .with(config_options)
87
+ .and_return(config)
88
+
89
+ allow(config).to receive(:migrations_paths).and_return(paths)
91
90
  end
92
91
 
93
92
  it 'lists schema migration paths' do
@@ -8,8 +8,12 @@ describe DataMigrate::Generators::DataMigrationGenerator do
8
8
  describe :next_migration_number do
9
9
  it "next migration" do
10
10
  Timecop.freeze("2016-12-03 22:15:26 -0800") do
11
- expect(ActiveRecord::Base).to receive(:timestamped_migrations) { true }
12
- expect(subject.next_migration_number(1)).to eq("20161204061526")
11
+ if ActiveRecord.version >= Gem::Version.new('7.0')
12
+ expect(ActiveRecord).to receive(:timestamped_migrations) { true }
13
+ else
14
+ expect(ActiveRecord::Base).to receive(:timestamped_migrations) { true }
15
+ end
16
+ expect(subject.next_migration_number(1).to_s).to eq("20161204061526")
13
17
  end
14
18
  end
15
19
  end
@@ -17,11 +21,7 @@ describe DataMigrate::Generators::DataMigrationGenerator do
17
21
  describe :migration_base_class_name do
18
22
  let(:subject) { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) }
19
23
  it "returns the correct base class name" do
20
- if ActiveRecord.version >= Gem::Version.new('5.0')
21
- expect(subject.send(:migration_base_class_name)).to eq("ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]")
22
- else
23
- expect(subject.send(:migration_base_class_name)).to eq('ActiveRecord::Migration')
24
- end
24
+ expect(subject.send(:migration_base_class_name)).to eq("ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]")
25
25
  end
26
26
  end
27
27
 
data/spec/spec_helper.rb CHANGED
@@ -20,23 +20,13 @@ RSpec.configure do |config|
20
20
  if example.metadata[:no_override]
21
21
  else
22
22
  @prev_data_migrations_path = DataMigrate.config.data_migrations_path
23
- if Rails::VERSION::MAJOR == 6
23
+ if Rails::VERSION::MAJOR == 5
24
24
  DataMigrate.configure do |config|
25
- config.data_migrations_path = "spec/db/6.0"
26
- end
27
- elsif Rails::VERSION::MAJOR == 5
28
- if Rails::VERSION::MINOR == 2
29
- DataMigrate.configure do |config|
30
- config.data_migrations_path = "spec/db/data"
31
- end
32
- else
33
- DataMigrate.configure do |config|
34
- config.data_migrations_path = "spec/db/5.0"
35
- end
25
+ config.data_migrations_path = "spec/db/data"
36
26
  end
37
27
  else
38
28
  DataMigrate.configure do |config|
39
- config.data_migrations_path = "spec/db/5.0"
29
+ config.data_migrations_path = "spec/db/6.0"
40
30
  end
41
31
  end
42
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.2
4
+ version: 8.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew J Vargo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-07-12 00:00:00.000000000 Z
13
+ date: 2022-01-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -202,40 +202,30 @@ files:
202
202
  - Appraisals
203
203
  - Changelog.md
204
204
  - Gemfile
205
- - Gemfile.rails5
206
- - Gemfile.rails5.1
207
205
  - Gemfile.rails5.2
208
206
  - Gemfile.rails6.1
209
207
  - LICENSE
210
208
  - README.md
211
209
  - Rakefile
212
210
  - data_migrate.gemspec
213
- - gemfiles/rails_4.1.gemfile
214
- - gemfiles/rails_4.2.gemfile
215
- - gemfiles/rails_5.0.gemfile
216
- - gemfiles/rails_5.1.gemfile
217
211
  - gemfiles/rails_5.2.gemfile
218
212
  - gemfiles/rails_6.0.gemfile
219
213
  - gemfiles/rails_6.1.gemfile
214
+ - gemfiles/rails_7.0.gemfile
220
215
  - lib/capistrano/data_migrate.rb
221
216
  - lib/capistrano/data_migrate/migrate.rb
222
217
  - lib/data_migrate.rb
223
218
  - lib/data_migrate/config.rb
224
- - lib/data_migrate/data_migrator.rb
225
219
  - lib/data_migrate/data_migrator_five.rb
226
220
  - lib/data_migrate/data_schema.rb
227
221
  - lib/data_migrate/data_schema_migration.rb
228
222
  - lib/data_migrate/database_tasks.rb
229
223
  - lib/data_migrate/legacy_migrator.rb
230
- - lib/data_migrate/migration.rb
231
224
  - lib/data_migrate/migration_context.rb
232
- - lib/data_migrate/migration_five.rb
233
225
  - lib/data_migrate/railtie.rb
234
226
  - lib/data_migrate/schema_dumper.rb
235
- - lib/data_migrate/schema_migration.rb
236
227
  - lib/data_migrate/schema_migration_five.rb
237
228
  - lib/data_migrate/schema_migration_six.rb
238
- - lib/data_migrate/status_service.rb
239
229
  - lib/data_migrate/status_service_five.rb
240
230
  - lib/data_migrate/tasks/data_migrate_tasks.rb
241
231
  - lib/data_migrate/version.rb
@@ -256,8 +246,6 @@ files:
256
246
  - spec/data_migrate/schema_migration_spec.rb
257
247
  - spec/data_migrate/status_service_spec.rb
258
248
  - spec/data_migrate/tasks/data_migrate_tasks_spec.rb
259
- - spec/db/5.0/20091231235959_some_name.rb
260
- - spec/db/5.0/20171231235959_super_update.rb
261
249
  - spec/db/6.0/20091231235959_some_name.rb
262
250
  - spec/db/6.0/20171231235959_super_update.rb
263
251
  - spec/db/data-6.0/20091231235959_some_name.rb
@@ -270,10 +258,6 @@ files:
270
258
  - spec/db/data/partial_schema/test_data_schema.rb
271
259
  - spec/db/data/schema/data_schema.rb
272
260
  - spec/db/data/schema/test_data_schema.rb
273
- - spec/db/migrate/4.2/20131111111111_late_migration.rb
274
- - spec/db/migrate/4.2/20202020202011_db_migration.rb
275
- - spec/db/migrate/5.0/20131111111111_late_migration.rb
276
- - spec/db/migrate/5.0/20202020202011_db_migration.rb
277
261
  - spec/db/migrate/5.2/20131111111111_late_migration.rb
278
262
  - spec/db/migrate/5.2/20202020202011_db_migration.rb
279
263
  - spec/db/migrate/6.0/20131111111111_late_migration.rb
@@ -303,11 +287,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
303
287
  version: '0'
304
288
  required_rubygems_version: !ruby/object:Gem::Requirement
305
289
  requirements:
306
- - - ">="
290
+ - - ">"
307
291
  - !ruby/object:Gem::Version
308
- version: '0'
292
+ version: 1.3.1
309
293
  requirements: []
310
- rubygems_version: 3.2.15
294
+ rubygems_version: 3.2.32
311
295
  signing_key:
312
296
  specification_version: 4
313
297
  summary: Rake tasks to migrate data alongside schema changes.
data/Gemfile.rails5 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.0.0'
10
- end
data/Gemfile.rails5.1 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.1.7'
10
- end
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "4.1.16"
6
-
7
- gemspec path: "../"
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "4.2.11.1"
6
- gem "nokogiri", "1.6.8.1"
7
- gem "bundler" , "< 2.0"
8
-
9
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "5.0.7.2"
6
- gem "sqlite3", "~> 1.4"
7
-
8
- gemspec path: "../"
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_record"
4
-
5
- module DataMigrate
6
- class DataMigrator < ActiveRecord::Migrator
7
-
8
- def record_version_state_after_migrating(version)
9
- if down?
10
- migrated.delete(version)
11
- DataMigrate::DataSchemaMigration.where(version: version.to_s).delete_all
12
- else
13
- migrated << version
14
- DataMigrate::DataSchemaMigration.create!(version: version.to_s)
15
- end
16
- end
17
-
18
- def load_migrated(connection = ActiveRecord::Base.connection)
19
- self.class.get_all_versions(connection)
20
- end
21
-
22
- class << self
23
- alias_method :migrations_status_orig, :migrations_status
24
-
25
- def migrations_status
26
- migrations_status_orig([DataMigrate.config.data_migrations_path])
27
- end
28
-
29
- def current_version(connection = ActiveRecord::Base.connection)
30
- get_all_versions(connection).max || 0
31
- end
32
-
33
- def get_all_versions(connection = ActiveRecord::Base.connection)
34
- if table_exists?(connection, schema_migrations_table_name)
35
- DataMigrate::DataSchemaMigration.all.map { |x| x.version.to_i }.sort
36
- else
37
- []
38
- end
39
- end
40
-
41
- def schema_migrations_table_name
42
- ActiveRecord::Base.table_name_prefix + "data_migrations" +
43
- ActiveRecord::Base.table_name_suffix
44
- end
45
-
46
- def migrations_path
47
- DataMigrate.config.data_migrations_path
48
- end
49
-
50
- ##
51
- # Provides the full migrations_path filepath
52
- # @return (String)
53
- def full_migrations_path
54
- File.join(Rails.root, *migrations_path.split(File::SEPARATOR))
55
- end
56
-
57
- def assure_data_schema_table
58
- ActiveRecord::Base.establish_connection(db_config)
59
- sm_table = DataMigrate::DataMigrator.schema_migrations_table_name
60
-
61
- unless table_exists?(ActiveRecord::Base.connection, sm_table)
62
- create_table(sm_table)
63
- end
64
- end
65
-
66
- ##
67
- # Compares the given filename with what we expect data migration
68
- # filenames to be, eg the "20091231235959_some_name.rb" pattern
69
- # @param (String) filename
70
- # @return (MatchData)
71
- def match(filename)
72
- /(\d{14})_(.+)\.rb$/.match(filename)
73
- end
74
-
75
- private
76
-
77
- def create_table(sm_table)
78
- ActiveRecord::Base.connection.create_table(sm_table, id: false) do |schema_migrations_table|
79
- schema_migrations_table.string :version, primary_key: true
80
- end
81
- end
82
-
83
- def table_exists?(connection, table_name)
84
- # Avoid the warning that table_exists? prints in Rails 5.0 due a
85
- # change in behavior between Rails 5.0 and Rails 5.1 of this method
86
- # with respect to database views.
87
- if ActiveRecord.version >= Gem::Version.new("5.0") &&
88
- ActiveRecord.version < Gem::Version.new("5.1")
89
- connection.data_source_exists?(table_name)
90
- else
91
- connection.table_exists?(schema_migrations_table_name)
92
- end
93
- end
94
-
95
- def db_config
96
- ActiveRecord::Base.configurations[Rails.env || "development"] ||
97
- ENV["DATABASE_URL"]
98
- end
99
- end
100
- end
101
- end
@@ -1,26 +0,0 @@
1
- module DataMigrate
2
- class Migration < ::ActiveRecord::Migration
3
-
4
- class << self
5
- def check_pending!(connection = ::ActiveRecord::Base.connection)
6
- raise ActiveRecord::PendingMigrationError if DataMigrator::Migrator.needs_migration?(connection)
7
- end
8
-
9
- def migrate(direction)
10
- new.migrate direction
11
- end
12
-
13
- def table_name
14
- ActiveRecord::Base.table_name_prefix + "data_migrations" + ActiveRecord::Base.table_name_suffix
15
- end
16
-
17
- def primary_key
18
- "version"
19
- end
20
- end
21
-
22
- def initialize(name = self.class.name, version = nil)
23
- super(name, version)
24
- end
25
- end
26
- end
@@ -1,26 +0,0 @@
1
- module DataMigrate
2
- class MigrationFive < ::ActiveRecord::Migration[5.0]
3
-
4
- class << self
5
- def check_pending!(connection = ::ActiveRecord::Base.connection)
6
- raise ActiveRecord::PendingMigrationError if DataMigrator::Migrator.needs_migration?(connection)
7
- end
8
-
9
- def migrate(direction)
10
- new.migrate direction
11
- end
12
-
13
- def table_name
14
- ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
15
- end
16
-
17
- def primary_key
18
- "version"
19
- end
20
- end
21
-
22
- def initialize(name = self.class.name, version = nil)
23
- super(name, version)
24
- end
25
- end
26
- 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::DataMigrator.migrations(migrations_paths)
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::Migrator.run(direction, migration_paths, 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
@@ -1,65 +0,0 @@
1
- module DataMigrate
2
- class StatusService
3
- class << self
4
- def dump(connection = ActiveRecord::Base.connection, stream = STDOUT)
5
- new(connection).dump(stream)
6
- stream
7
- end
8
- end
9
-
10
- def initialize(connection)
11
- @connection = connection
12
- end
13
-
14
- def root_folder
15
- Rails.root
16
- end
17
-
18
- def dump(stream)
19
- unless @connection.table_exists?(table_name)
20
- stream.puts "Data migrations table does not exist yet."
21
- return
22
- end
23
- sql = "SELECT version FROM #{DataMigrate::DataMigrator.schema_migrations_table_name}"
24
- db_list = ActiveRecord::Base.connection.select_values(sql)
25
- output(stream, db_list)
26
- end
27
-
28
- private
29
-
30
- def table_name
31
- DataMigrate::DataMigrator.schema_migrations_table_name
32
- end
33
-
34
- def output(stream, db_list)
35
- stream.puts "#{"Status".center(8)} #{"Migration ID".ljust(14)} Migration Name"
36
- stream.puts "-" * 50
37
- list = migration_files(db_list) + migration_list(db_list)
38
- list.sort! {|line1, line2| line1[1] <=> line2[1]}
39
- list.each do |file|
40
- stream.puts "#{file[0].center(8)} #{file[1].ljust(14)} #{file[2]}"
41
- end
42
- stream.puts
43
- end
44
-
45
- def migration_list(db_list)
46
- list = []
47
- db_list.each do |version|
48
- list << ["up", version, "********** NO FILE *************"]
49
- end
50
- list
51
- end
52
-
53
- def migration_files(db_list)
54
- file_list = []
55
- Dir.foreach(File.join(root_folder, DataMigrate.config.data_migrations_path)) do |file|
56
- # only files matching "20091231235959_some_name.rb" pattern
57
- if match_data = DataMigrate::DataMigrator.match(file)
58
- status = db_list.delete(match_data[1]) ? "up" : "down"
59
- file_list << [status, match_data[1], match_data[2].humanize]
60
- end
61
- end
62
- file_list
63
- end
64
- end
65
- end
@@ -1,9 +0,0 @@
1
- class SomeName < ActiveRecord::Migration[5.0]
2
- def up
3
- puts "Doing data migration"
4
- end
5
-
6
- def down
7
- raise ActiveRecord::IrreversibleMigration
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class SuperUpdate < ActiveRecord::Migration[5.0]
2
- def up
3
- puts "Doing data migration"
4
- end
5
-
6
- def down
7
- raise ActiveRecord::IrreversibleMigration
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class LateMigration < ActiveRecord::Migration
2
- def up
3
- puts "Doing schema LateMigration"
4
- end
5
-
6
- def down
7
- puts "Undoing LateMigration"
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class DbMigration < ActiveRecord::Migration
2
- def up
3
- puts "Doing schema migration"
4
- end
5
-
6
- def down
7
- puts "Undoing DbMigration"
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class LateMigration < ActiveRecord::Migration[5.0]
2
- def up
3
- puts "Doing schema LateMigration"
4
- end
5
-
6
- def down
7
- puts "Undoing LateMigration"
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class DbMigration < ActiveRecord::Migration[5.0]
2
- def up
3
- puts "Doing schema migration"
4
- end
5
-
6
- def down
7
- puts "Undoing DbMigration"
8
- end
9
- end