data_migrate 6.8.0 → 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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +6 -9
  4. data/Appraisals +4 -8
  5. data/Changelog.md +12 -1
  6. data/Gemfile +0 -2
  7. data/Gemfile.rails5.2 +6 -1
  8. data/Gemfile.rails6.1 +6 -1
  9. data/data_migrate.gemspec +7 -1
  10. data/gemfiles/{rails_5.1.gemfile → rails_7.0.gemfile} +1 -1
  11. data/lib/data_migrate/database_tasks.rb +14 -0
  12. data/lib/data_migrate/schema_dumper.rb +0 -4
  13. data/lib/data_migrate/status_service_five.rb +5 -1
  14. data/lib/data_migrate/tasks/data_migrate_tasks.rb +12 -8
  15. data/lib/data_migrate/version.rb +1 -1
  16. data/lib/data_migrate.rb +10 -32
  17. data/lib/generators/data_migration/data_migration_generator.rb +1 -7
  18. data/lib/generators/data_migration/templates/data_migration.rb +2 -0
  19. data/spec/data_migrate/database_tasks_spec.rb +4 -9
  20. data/spec/data_migrate/migration_context_spec.rb +6 -14
  21. data/spec/data_migrate/schema_migration_spec.rb +21 -22
  22. data/spec/db/data/partial_schema/data_schema.rb +0 -1
  23. data/spec/db/data/partial_schema/test_data_schema.rb +0 -1
  24. data/spec/db/data/schema/data_schema.rb +0 -1
  25. data/spec/db/data/schema/test_data_schema.rb +0 -1
  26. data/spec/generators/data_migration/data_migration_generator_spec.rb +7 -7
  27. data/spec/spec_helper.rb +3 -13
  28. data/tasks/databases.rake +18 -32
  29. metadata +21 -23
  30. data/Gemfile.rails5 +0 -5
  31. data/Gemfile.rails5.1 +0 -5
  32. data/gemfiles/rails_4.1.gemfile +0 -7
  33. data/gemfiles/rails_4.2.gemfile +0 -9
  34. data/gemfiles/rails_5.0.gemfile +0 -8
  35. data/lib/data_migrate/data_migrator.rb +0 -101
  36. data/lib/data_migrate/migration.rb +0 -26
  37. data/lib/data_migrate/migration_five.rb +0 -26
  38. data/lib/data_migrate/schema_migration.rb +0 -31
  39. data/lib/data_migrate/status_service.rb +0 -65
  40. data/spec/db/5.0/20091231235959_some_name.rb +0 -9
  41. data/spec/db/5.0/20171231235959_super_update.rb +0 -9
  42. data/spec/db/migrate/4.2/20131111111111_late_migration.rb +0 -9
  43. data/spec/db/migrate/4.2/20202020202011_db_migration.rb +0 -9
  44. data/spec/db/migrate/5.0/20131111111111_late_migration.rb +0 -9
  45. 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: 3f0dd24ff404906327e5bc24b17a503f0f3b83216822d6b30ea23c36f003ac91
4
- data.tar.gz: 53b774e131bc3f0fc4267b4cc1b46df6f9cefed04064f6d32fae6adf17193539
3
+ metadata.gz: af0b932d1ca71e8bd2218c66a901c7f4075722fc716d4acf2ba20356cec069a7
4
+ data.tar.gz: cd0193ea16bac2ef7f21df588ff0c673e9e7706b99a55ae82452d0843c47b5d7
5
5
  SHA512:
6
- metadata.gz: 96d703eb0eb1af977f911200287a7b47c4defc186e346ebeff842c2d79d098c9bf2bb7c99b618b140a1b72a8e9f67ad047ef022eaff7b5e55f9ad54c1beb3662
7
- data.tar.gz: 0c313639ecf58bc5573cdeab9bc3ae2d2c8aa2f443aacf95f03f0951ab708e79247d05bc647c28ae293ee7f9b5eb246bb8e18fd7e5fc5a5c24d700da84524c1b
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,17 +1,14 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4.4
4
- - 2.5.5
5
- - 2.6.2
3
+ - 2.7
4
+ - 3.0
6
5
  script: bundle exec rspec
7
6
  gemfile:
8
- - gemfiles/rails_5.1.gemfile
9
7
  - gemfiles/rails_5.2.gemfile
10
8
  - gemfiles/rails_6.0.gemfile
11
9
  - gemfiles/rails_6.1.gemfile
12
- matrix:
10
+ - gemfiles/rails_7.0.gemfile
11
+ jobs:
13
12
  exclude:
14
- - rvm: 2.4.4
15
- gemfile: gemfiles/rails_6.0.gemfile
16
- - rvm: 2.4.4
17
- 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,9 +1,20 @@
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
+
7
+ ## 7.0.2
8
+
9
+ Remove magic comment in migration files [y-yagi](https://github.com/y-yagi)
10
+ User frozen string [jonnay](https://github.com/jonnay)
11
+ ## 7.0.1
12
+ Use SchemaMigration.migrations_paths in main rake task [lewhit](https://github.com/lewhit)
13
+
3
14
  ## 6.8.0
4
15
 
5
16
  Specify database name for migrations_paths [lewhit](https://github.com/lewhit)
6
- # 6.7.0
17
+ ## 6.7.0
7
18
 
8
19
  Add configuration for which database name is to be used for database migrations [lewhit](https://github.com/lewhit)
9
20
  Add tests for Rails 6.1 [lewhit](https://github.com/lewhit)
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in data_migrate.gemspec
4
- gem 'rails', '~> 6.0.0'
5
3
  gem 'sqlite3', "~> 1.4"
6
4
  gemspec
data/Gemfile.rails5.2 CHANGED
@@ -2,4 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in data_migrate.gemspec
4
4
  gemspec
5
- gem 'rails', '~> 5.2'
5
+ %w[
6
+ activerecord
7
+ railties
8
+ ].each do |rails_gem|
9
+ gem rails_gem, '~> 5.2'
10
+ end
data/Gemfile.rails6.1 CHANGED
@@ -1,6 +1,11 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in data_migrate.gemspec
4
- gem 'rails', '~> 6.1.0'
4
+ %w[
5
+ activerecord
6
+ railties
7
+ ].each do |rails_gem|
8
+ gem rails_gem, '~> 6.1.0'
9
+ end
5
10
  gem 'sqlite3', "~> 1.4"
6
11
  gemspec
data/data_migrate.gemspec CHANGED
@@ -15,7 +15,13 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.rubyforge_project = "data_migrate"
17
17
 
18
- s.add_dependency('rails', '>= 5.0')
18
+ %w[
19
+ activerecord
20
+ railties
21
+ ].each do |rails_gem|
22
+ s.add_dependency(rails_gem, '>= 5.0')
23
+ end
24
+
19
25
  s.add_development_dependency "appraisal"
20
26
  s.add_development_dependency "rake"
21
27
  s.add_development_dependency "rspec"
@@ -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
@@ -17,10 +17,6 @@ module DataMigrate
17
17
  def dump(stream)
18
18
  define_params = @version ? "version: #{@version}" : ""
19
19
 
20
- if stream.respond_to?(:external_encoding) && stream.external_encoding
21
- stream.puts "# encoding: #{stream.external_encoding.name}"
22
- end
23
-
24
20
  stream.puts "DataMigrate::Data.define(#{define_params})"
25
21
 
26
22
  stream
@@ -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 = "6.8.0".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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class <%= migration_class_name %> < <%= migration_base_class_name %>
2
4
  def up
3
5
  end
@@ -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
@@ -1,2 +1 @@
1
- # encoding: UTF-8
2
1
  DataMigrate::Data.define(version: 20091231235959)
@@ -1,2 +1 @@
1
- # encoding: UTF-8
2
1
  DataMigrate::Data.define(version: 20091231235959)
@@ -1,2 +1 @@
1
- # encoding: UTF-8
2
1
  DataMigrate::Data.define(version: 20171231235959)
@@ -1,2 +1 @@
1
- # encoding: UTF-8
2
1
  DataMigrate::Data.define(version: 20171231235959)
@@ -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
data/tasks/databases.rake CHANGED
@@ -46,17 +46,7 @@ namespace :db do
46
46
  end
47
47
 
48
48
  migrations.each do |migration|
49
- if migration[:kind] == :data
50
- ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
51
- DataMigrate::DataMigrator.run(migration[:direction], data_migrations_path, migration[:version])
52
- else
53
- ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
54
- DataMigrate::SchemaMigration.run(
55
- migration[:direction],
56
- Rails.application.config.paths["db/migrate"],
57
- migration[:version]
58
- )
59
- end
49
+ run_migration(migration, migration[:direction])
60
50
  end
61
51
 
62
52
  Rake::Task["db:_dump"].invoke
@@ -91,13 +81,7 @@ namespace :db do
91
81
  end
92
82
 
93
83
  migrations.each do |migration|
94
- if migration[:kind] == :data
95
- ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
96
- DataMigrate::DataMigrator.run(:up, data_migrations_path, migration[:version])
97
- else
98
- ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
99
- DataMigrate::SchemaMigration.run(:up, "db/migrate/", migration[:version])
100
- end
84
+ run_migration(migration, :up)
101
85
  end
102
86
 
103
87
  Rake::Task["db:_dump"].invoke
@@ -119,13 +103,7 @@ namespace :db do
119
103
  end
120
104
 
121
105
  migrations.each do |migration|
122
- if migration[:kind] == :data
123
- ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
124
- DataMigrate::DataMigrator.run(:down, data_migrations_path, migration[:version])
125
- else
126
- ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
127
- DataMigrate::SchemaMigration.run(:down, "db/migrate/", migration[:version])
128
- end
106
+ run_migration(migration, :down)
129
107
  end
130
108
 
131
109
  Rake::Task["db:_dump"].invoke
@@ -189,13 +167,7 @@ namespace :db do
189
167
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
190
168
  assure_data_schema_table
191
169
  past_migrations[0..(step - 1)].each do | past_migration |
192
- if past_migration[:kind] == :data
193
- ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
194
- DataMigrate::DataMigrator.run(:down, data_migrations_path, past_migration[:version])
195
- elsif past_migration[:kind] == :schema
196
- ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
197
- DataMigrate::SchemaMigration.run(:down, "db/migrate/", past_migration[:version])
198
- end
170
+ run_migration(past_migration, :down)
199
171
  end
200
172
 
201
173
  Rake::Task["db:_dump"].invoke
@@ -412,3 +384,17 @@ end
412
384
  def data_migrations_path
413
385
  DataMigrate.config.data_migrations_path
414
386
  end
387
+
388
+ def run_migration(migration, direction)
389
+ if migration[:kind] == :data
390
+ ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
391
+ DataMigrate::DataMigrator.run(direction, data_migrations_path, migration[:version])
392
+ else
393
+ ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
394
+ DataMigrate::SchemaMigration.run(
395
+ direction,
396
+ DataMigrate::SchemaMigration.migrations_paths,
397
+ migration[:version]
398
+ )
399
+ end
400
+ 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: 6.8.0
4
+ version: 8.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew J Vargo
@@ -10,10 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-04-18 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
- name: rails
16
+ name: activerecord
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '5.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '5.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: railties
17
31
  requirement: !ruby/object:Gem::Requirement
18
32
  requirements:
19
33
  - - ">="
@@ -188,40 +202,30 @@ files:
188
202
  - Appraisals
189
203
  - Changelog.md
190
204
  - Gemfile
191
- - Gemfile.rails5
192
- - Gemfile.rails5.1
193
205
  - Gemfile.rails5.2
194
206
  - Gemfile.rails6.1
195
207
  - LICENSE
196
208
  - README.md
197
209
  - Rakefile
198
210
  - data_migrate.gemspec
199
- - gemfiles/rails_4.1.gemfile
200
- - gemfiles/rails_4.2.gemfile
201
- - gemfiles/rails_5.0.gemfile
202
- - gemfiles/rails_5.1.gemfile
203
211
  - gemfiles/rails_5.2.gemfile
204
212
  - gemfiles/rails_6.0.gemfile
205
213
  - gemfiles/rails_6.1.gemfile
214
+ - gemfiles/rails_7.0.gemfile
206
215
  - lib/capistrano/data_migrate.rb
207
216
  - lib/capistrano/data_migrate/migrate.rb
208
217
  - lib/data_migrate.rb
209
218
  - lib/data_migrate/config.rb
210
- - lib/data_migrate/data_migrator.rb
211
219
  - lib/data_migrate/data_migrator_five.rb
212
220
  - lib/data_migrate/data_schema.rb
213
221
  - lib/data_migrate/data_schema_migration.rb
214
222
  - lib/data_migrate/database_tasks.rb
215
223
  - lib/data_migrate/legacy_migrator.rb
216
- - lib/data_migrate/migration.rb
217
224
  - lib/data_migrate/migration_context.rb
218
- - lib/data_migrate/migration_five.rb
219
225
  - lib/data_migrate/railtie.rb
220
226
  - lib/data_migrate/schema_dumper.rb
221
- - lib/data_migrate/schema_migration.rb
222
227
  - lib/data_migrate/schema_migration_five.rb
223
228
  - lib/data_migrate/schema_migration_six.rb
224
- - lib/data_migrate/status_service.rb
225
229
  - lib/data_migrate/status_service_five.rb
226
230
  - lib/data_migrate/tasks/data_migrate_tasks.rb
227
231
  - lib/data_migrate/version.rb
@@ -242,8 +246,6 @@ files:
242
246
  - spec/data_migrate/schema_migration_spec.rb
243
247
  - spec/data_migrate/status_service_spec.rb
244
248
  - spec/data_migrate/tasks/data_migrate_tasks_spec.rb
245
- - spec/db/5.0/20091231235959_some_name.rb
246
- - spec/db/5.0/20171231235959_super_update.rb
247
249
  - spec/db/6.0/20091231235959_some_name.rb
248
250
  - spec/db/6.0/20171231235959_super_update.rb
249
251
  - spec/db/data-6.0/20091231235959_some_name.rb
@@ -256,10 +258,6 @@ files:
256
258
  - spec/db/data/partial_schema/test_data_schema.rb
257
259
  - spec/db/data/schema/data_schema.rb
258
260
  - spec/db/data/schema/test_data_schema.rb
259
- - spec/db/migrate/4.2/20131111111111_late_migration.rb
260
- - spec/db/migrate/4.2/20202020202011_db_migration.rb
261
- - spec/db/migrate/5.0/20131111111111_late_migration.rb
262
- - spec/db/migrate/5.0/20202020202011_db_migration.rb
263
261
  - spec/db/migrate/5.2/20131111111111_late_migration.rb
264
262
  - spec/db/migrate/5.2/20202020202011_db_migration.rb
265
263
  - spec/db/migrate/6.0/20131111111111_late_migration.rb
@@ -289,11 +287,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
289
287
  version: '0'
290
288
  required_rubygems_version: !ruby/object:Gem::Requirement
291
289
  requirements:
292
- - - ">="
290
+ - - ">"
293
291
  - !ruby/object:Gem::Version
294
- version: '0'
292
+ version: 1.3.1
295
293
  requirements: []
296
- rubygems_version: 3.2.15
294
+ rubygems_version: 3.2.32
297
295
  signing_key:
298
296
  specification_version: 4
299
297
  summary: Rake tasks to migrate data alongside schema changes.
data/Gemfile.rails5 DELETED
@@ -1,5 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in data_migrate.gemspec
4
- gemspec
5
- gem 'rails', '~> 5.0.0'
data/Gemfile.rails5.1 DELETED
@@ -1,5 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in data_migrate.gemspec
4
- gemspec
5
- gem 'rails', '~> 5.1.7'
@@ -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