data_migrate 11.1.0 → 11.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +11 -0
  3. data/README.md +13 -18
  4. data/lib/data_migrate/config.rb +2 -1
  5. data/lib/data_migrate/data_migrator.rb +0 -1
  6. data/lib/data_migrate/data_schema_migration.rb +2 -2
  7. data/lib/data_migrate/database_tasks.rb +14 -4
  8. data/lib/data_migrate/rails_helper.rb +1 -0
  9. data/lib/data_migrate/version.rb +1 -1
  10. metadata +5 -54
  11. data/.github/workflows/build.yml +0 -39
  12. data/.github/workflows/gempush.yml +0 -28
  13. data/.gitignore +0 -12
  14. data/.hound.yml +0 -4
  15. data/.overcommit.yml +0 -21
  16. data/.rbenv-gemsets +0 -2
  17. data/.rspec +0 -3
  18. data/.rubocop.yml +0 -2
  19. data/.ruby-style.yml +0 -1061
  20. data/Appraisals +0 -19
  21. data/Gemfile +0 -3
  22. data/Gemfile.lock +0 -192
  23. data/Rakefile +0 -2
  24. data/data_migrate.gemspec +0 -41
  25. data/gemfiles/rails_6.1.gemfile +0 -7
  26. data/gemfiles/rails_6.1.gemfile.lock +0 -237
  27. data/gemfiles/rails_7.0.gemfile +0 -7
  28. data/gemfiles/rails_7.0.gemfile.lock +0 -238
  29. data/gemfiles/rails_7.1.gemfile +0 -7
  30. data/gemfiles/rails_7.1.gemfile.lock +0 -277
  31. data/gemfiles/rails_7.2.gemfile +0 -7
  32. data/gemfiles/rails_7.2.gemfile.lock +0 -274
  33. data/gemfiles/rails_8.0.gemfile +0 -7
  34. data/gemfiles/rails_8.0.gemfile.lock +0 -268
  35. data/screenshot.png +0 -0
  36. data/spec/data_migrate/config_spec.rb +0 -69
  37. data/spec/data_migrate/data_migrator_spec.rb +0 -84
  38. data/spec/data_migrate/data_schema_migration_spec.rb +0 -33
  39. data/spec/data_migrate/data_spec.rb +0 -74
  40. data/spec/data_migrate/database_tasks_spec.rb +0 -214
  41. data/spec/data_migrate/migration.rb +0 -17
  42. data/spec/data_migrate/migration_context_spec.rb +0 -117
  43. data/spec/data_migrate/schema_dumper_spec.rb +0 -36
  44. data/spec/data_migrate/schema_migration_spec.rb +0 -104
  45. data/spec/data_migrate/status_service_spec.rb +0 -76
  46. data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +0 -129
  47. data/spec/db/data/20091231235959_some_name.rb +0 -9
  48. data/spec/db/data/20171231235959_super_update.rb +0 -9
  49. data/spec/db/data/20181128000207_excluded_file.rb.other_ext +0 -1
  50. data/spec/db/data/partial_schema/data_schema.rb +0 -1
  51. data/spec/db/data/partial_schema/test_data_schema.rb +0 -1
  52. data/spec/db/data/schema/data_schema.rb +0 -1
  53. data/spec/db/data/schema/test_data_schema.rb +0 -1
  54. data/spec/db/data_two/20241231235959_data_two_update.rb +0 -9
  55. data/spec/db/migrate/20131111111111_late_migration.rb +0 -9
  56. data/spec/db/migrate/20202020202011_db_migration.rb +0 -9
  57. data/spec/generators/data_migration/data_migration_generator_spec.rb +0 -101
  58. data/spec/spec_helper.rb +0 -28
  59. data/tasks/.gitkeep +0 -0
@@ -1,129 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe DataMigrate::Tasks::DataMigrateTasks do
6
- let(:db_config) do
7
- {
8
- adapter: "sqlite3",
9
- database: "spec/db/test.db"
10
- }
11
- end
12
-
13
- before do
14
- ActiveRecord::Base.establish_connection(db_config)
15
- DataMigrate::RailsHelper.schema_migration.create_table
16
- DataMigrate::RailsHelper.data_schema_migration.create_table
17
- end
18
-
19
- after do
20
- ActiveRecord::Migration.drop_table("data_migrations") rescue nil
21
- ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
22
- end
23
-
24
- describe :dump do
25
- before do
26
- allow(DataMigrate::DatabaseTasks).to receive(:db_dir).and_return("spec/db")
27
- DataMigrate::Tasks::DataMigrateTasks.migrate
28
- end
29
-
30
- context 'when not given a separate db config' do
31
- it 'does not override the default connection' do
32
- expect(ActiveRecord::Base).not_to receive(:establish_connection)
33
- expect(DataMigrate::SchemaDumper).to receive(:dump)
34
-
35
- DataMigrate::Tasks::DataMigrateTasks.dump
36
- end
37
- end
38
-
39
- context 'when given a separate db config' do
40
- let(:override_config) do
41
- {
42
- 'host' => '127.0.0.1',
43
- 'database' => 'other_test',
44
- 'adapter' => 'sqlite3',
45
- 'username' => 'root',
46
- 'password' => nil,
47
- }
48
- end
49
- let(:paths) { ["spec/db/migrate"] }
50
-
51
- before do
52
- DataMigrate.configure do |config|
53
- config.db_configuration = override_config
54
- end
55
- end
56
-
57
- it 'overrides the default connection' do
58
- expect(ActiveRecord::Base).to receive(:establish_connection).with(override_config)
59
- DataMigrate::Tasks::DataMigrateTasks.dump
60
- end
61
- end
62
- end
63
-
64
- describe :migrate do
65
- it "first run should run the first pending migration" do
66
- expect { DataMigrate::Tasks::DataMigrateTasks.migrate }.to output(/20091231235959 SomeName: migrating/).to_stdout
67
- end
68
-
69
- it "second run should run the second pending migration" do
70
- expect { DataMigrate::Tasks::DataMigrateTasks.migrate }.to output(/20171231235959 SuperUpdate: migrating/).to_stdout
71
- end
72
- end
73
-
74
- describe :abort_if_pending_migrations do
75
- subject { DataMigrate::Tasks::DataMigrateTasks.abort_if_pending_migrations(migrations, message) }
76
-
77
- let(:message) { "ABORT_MESSAGE" }
78
-
79
- context "when there are no pending migrations" do
80
- let(:migrations) { [] }
81
-
82
- it "shouldn't do anything" do
83
- expect { subject }.to_not raise_error
84
- end
85
- end
86
-
87
- context "when there are pending migrations" do
88
- let(:migrations) do
89
- [{
90
- name: "A",
91
- version: 1
92
- }, {
93
- name: 'B',
94
- version: 2
95
- }]
96
- end
97
-
98
- it "should abort with given message and print names and versions of pending migrations" do
99
- expect { subject }
100
- .to raise_error(SystemExit, message)
101
- .and output(match(/You have #{migrations.count} pending migrations:/)
102
- .and match(Regexp.new(migrations.map { |m| m.slice(:version, :name)
103
- .values.join("\\W+") }.join("\\W+")))).to_stdout
104
- end
105
- end
106
- end
107
-
108
- describe ".status" do
109
- before do
110
- allow(Rails).to receive(:root) { "." }
111
- allow(Rails).to receive(:application) { OpenStruct.new(config: OpenStruct.new(paths: { "db/migrate" => ["spec/db/migrate"] })) }
112
-
113
- DataMigrate::Tasks::DataMigrateTasks.migrate
114
- end
115
-
116
- it "should display data migration status" do
117
- expect {
118
- DataMigrate::Tasks::DataMigrateTasks.status
119
- }.to output(/up 20091231235959 Some name/).to_stdout
120
- end
121
-
122
- it "should display schema and data migration status" do
123
- expect {
124
- DataMigrate::Tasks::DataMigrateTasks.status_with_schema
125
- }.to output(match(/up data 20091231235959 Some name/)
126
- .and match(/down schema 20131111111111 Late migration/)).to_stdout
127
- end
128
- end
129
- end
@@ -1,9 +0,0 @@
1
- class SomeName < ActiveRecord::Migration[6.1]
2
- def up
3
- puts "Doing data migration"
4
- end
5
-
6
- def down
7
- puts "Undoing SomeName"
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class SuperUpdate < ActiveRecord::Migration[6.1]
2
- def up
3
- puts "Doing SuperUpdate"
4
- end
5
-
6
- def down
7
- puts "Undoing SuperUpdate"
8
- end
9
- end
@@ -1 +0,0 @@
1
- # This file should be excluded
@@ -1 +0,0 @@
1
- DataMigrate::Data.define(version: 20091231235959)
@@ -1 +0,0 @@
1
- DataMigrate::Data.define(version: 20091231235959)
@@ -1 +0,0 @@
1
- DataMigrate::Data.define(version: 20171231235959)
@@ -1 +0,0 @@
1
- DataMigrate::Data.define(version: 20171231235959)
@@ -1,9 +0,0 @@
1
- class DataTwoUpdate < ActiveRecord::Migration[6.1]
2
- def up
3
- puts "Doing DataTwoUpdate"
4
- end
5
-
6
- def down
7
- puts "Undoing DataTwoUpdate"
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class LateMigration < ActiveRecord::Migration[6.1]
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[6.1]
2
- def up
3
- puts "Doing schema migration"
4
- end
5
-
6
- def down
7
- puts "Undoing DbMigration"
8
- end
9
- end
@@ -1,101 +0,0 @@
1
- require 'spec_helper'
2
- require 'rails/generators'
3
- require 'rails/generators/migration'
4
- require 'generators/data_migration/data_migration_generator'
5
-
6
- describe DataMigrate::Generators::DataMigrationGenerator do
7
- subject { DataMigrate::Generators::DataMigrationGenerator }
8
-
9
- describe :next_migration_number do
10
- it "next migration" do
11
- Timecop.freeze("2016-12-03 22:15:26 -0800") do
12
- if ActiveRecord.version >= Gem::Version.new('7.0')
13
- expect(ActiveRecord).to receive(:timestamped_migrations) { true }
14
- else
15
- expect(ActiveRecord::Base).to receive(:timestamped_migrations) { true }
16
- end
17
- expect(subject.next_migration_number(1).to_s).to eq("20161204061526")
18
- end
19
- end
20
- end
21
-
22
- describe :migration_base_class_name do
23
- subject { generator.send(:migration_base_class_name) }
24
-
25
- let(:generator) { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) }
26
-
27
- it "returns the correct base class name" do
28
- is_expected.to eq("ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]")
29
- end
30
- end
31
-
32
- describe :create_data_migration do
33
- subject { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) }
34
-
35
- let(:data_migrations_file_path) { 'abc/my_migration.rb' }
36
-
37
- context 'when custom data migrations path has a trailing slash' do
38
- before do
39
- DataMigrate.config.data_migrations_path = 'abc/'
40
- end
41
-
42
- it 'returns correct file path' do
43
- is_expected.to receive(:migration_template).with(
44
- 'data_migration.rb', data_migrations_file_path
45
- )
46
-
47
- subject.create_data_migration
48
- end
49
- end
50
-
51
- context 'when custom data migrations path does not have a trailing slash' do
52
- before do
53
- DataMigrate.config.data_migrations_path = 'abc'
54
- end
55
-
56
- it 'returns correct file path' do
57
- is_expected.to receive(:migration_template).with(
58
- 'data_migration.rb', data_migrations_file_path
59
- )
60
-
61
- subject.create_data_migration
62
- end
63
- end
64
- end
65
-
66
- describe ".source_root" do
67
- subject { described_class.source_root }
68
-
69
- let(:default_source_root) do
70
- File.expand_path(
71
- File.dirname(File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb"))
72
- )
73
- end
74
-
75
- it { is_expected.to eq default_source_root }
76
-
77
- context "when DateMigrate.config.data_template_path is set" do
78
- before do
79
- @before = DataMigrate.config.data_template_path
80
- DataMigrate.configure do |config|
81
- config.data_template_path = data_template_path
82
- end
83
- end
84
-
85
- let(:data_template_path) do
86
- File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb")
87
- end
88
- let(:expected_source_root) { File.dirname(data_template_path) }
89
-
90
- after do
91
- DataMigrate.configure do |config|
92
- config.data_template_path = @before
93
- end
94
- end
95
-
96
- it "reads directory from config data template path" do
97
- is_expected.to eq expected_source_root
98
- end
99
- end
100
- end
101
- end
data/spec/spec_helper.rb DELETED
@@ -1,28 +0,0 @@
1
- require 'rspec'
2
- require 'rails'
3
- require 'sqlite3'
4
- require 'data_migrate'
5
- require 'pry'
6
- require 'timecop'
7
-
8
- RSpec.configure do |config|
9
- config.mock_with :rspec do |mocks|
10
- mocks.verify_partial_doubles = true
11
- end
12
-
13
- config.after(:each) do
14
- DataMigrate.configure do |config|
15
- config.data_migrations_path = @prev_data_migrations_path
16
- end
17
- end
18
-
19
- config.before(:each) do |example|
20
- if example.metadata[:no_override]
21
- else
22
- @prev_data_migrations_path = DataMigrate.config.data_migrations_path
23
- DataMigrate.configure do |config|
24
- config.data_migrations_path = ["spec/db/data", "spec/db/data_two"]
25
- end
26
- end
27
- end
28
- end
data/tasks/.gitkeep DELETED
File without changes