data_migrate 9.0.0 → 10.0.3.rc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gempush.yml +1 -0
- data/.gitignore +3 -1
- data/Appraisals +0 -4
- data/Changelog.md +31 -0
- data/README.md +9 -7
- data/lib/data_migrate/{data_migrator_five.rb → data_migrator.rb} +0 -11
- data/lib/data_migrate/database_tasks.rb +12 -72
- data/lib/data_migrate/{schema_migration_six.rb → schema_migration.rb} +4 -2
- data/lib/data_migrate/{status_service_five.rb → status_service.rb} +12 -6
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +19 -39
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +3 -8
- data/spec/data_migrate/config_spec.rb +13 -10
- data/spec/data_migrate/data_migrator_spec.rb +11 -32
- data/spec/data_migrate/data_spec.rb +0 -11
- data/spec/data_migrate/database_tasks_spec.rb +10 -58
- data/spec/data_migrate/legacy_migrator_spec.rb +6 -18
- data/spec/data_migrate/migration.rb +11 -13
- data/spec/data_migrate/migration_context_spec.rb +11 -37
- data/spec/data_migrate/schema_dumper_spec.rb +10 -23
- data/spec/data_migrate/schema_migration_spec.rb +40 -42
- data/spec/data_migrate/status_service_spec.rb +26 -55
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +37 -71
- data/spec/db/data/20091231235959_some_name.rb +1 -1
- data/spec/db/data/20171231235959_super_update.rb +1 -1
- data/spec/spec_helper.rb +2 -8
- data/tasks/databases.rake +38 -5
- metadata +9 -21
- data/.ruby-version +0 -1
- data/.travis.yml +0 -17
- data/Gemfile.rails5.2 +0 -10
- data/gemfiles/rails_5.2.gemfile +0 -8
- data/lib/data_migrate/schema_migration_five.rb +0 -31
- data/spec/db/6.0/20091231235959_some_name.rb +0 -9
- data/spec/db/6.0/20171231235959_super_update.rb +0 -9
- data/spec/db/data-6.0/20091231235959_some_name.rb +0 -9
- data/spec/db/data-6.0/20171231235959_super_update.rb +0 -9
- data/spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext +0 -1
- data/spec/db/migrate/5.2/20131111111111_late_migration.rb +0 -9
- data/spec/db/migrate/5.2/20202020202011_db_migration.rb +0 -9
- /data/spec/db/migrate/{6.0/20131111111111_late_migration.rb → 20131111111111_late_migration.rb} +0 -0
- /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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bb05d428228b17b10beb94404770d5290cbb9727b7185356f3833dc440a40e6
|
4
|
+
data.tar.gz: e1a996f14dce42f3743db8bc74a128893b97a41cc97c63db1202db1733b1349e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 005deffc4ecd6a9f02ca76c84f2fbd8ad70f4e294e6d4259d92f2e2ce1f54f1a5032767ec2a0759af762571ff99fe1f7e290d9d3ec414ba69ebc2b7b673a2c65
|
7
|
+
data.tar.gz: a4db456966db55f1b3428a239a76dd00ba352417a796957474b20cd163918fe48f79096cad7d513d9d1bd180465bbde2969c39a182c38c08afde64705d23880d
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
data/Changelog.md
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 10.0.3.rc
|
4
|
+
|
5
|
+
- Remove all travis references [leoarnold](https//:github.com/leoarnold)
|
6
|
+
- Changing to rc because of ongoing discussion how to properly handle multiple database environments
|
7
|
+
|
8
|
+
## 10.0.2
|
9
|
+
|
10
|
+
Change "rails" dependencies to "railties"
|
11
|
+
|
12
|
+
## 10.0.1
|
13
|
+
|
14
|
+
- Bug fix for Rails 6 config [chaunce](https//:github.com/chaunce)
|
15
|
+
- Railties bug fix by [opti](https://github.com/opti)
|
16
|
+
|
17
|
+
## 10.0.0
|
18
|
+
|
19
|
+
Releasing 10.0.0
|
20
|
+
|
21
|
+
!!! Breaking changes !!!
|
22
|
+
|
23
|
+
- This version introduces a breaking change which may lead to undesired
|
24
|
+
behavior in multi-database environments. See https://github.com/ilyakatz/data-migrate/issues/181
|
25
|
+
|
26
|
+
## 10.0.0.rc1
|
27
|
+
|
28
|
+
- Changes by [chaunce](https//:github.com/chaunce)
|
29
|
+
- Multiple databases support
|
30
|
+
- Refactor to clean things up
|
31
|
+
- Deprecate rails 5.2 support for real
|
32
|
+
|
33
|
+
|
3
34
|
## 9.0.0
|
4
35
|
|
5
36
|
Ruby 3.2 support [mehanoid](https://github.com/mehanoid)
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
- [![Version](http://img.shields.io/gem/v/data_migrate.svg?style=flat-square)](https://rubygems.org/gems/data_migrate)
|
4
4
|
- [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
|
5
|
-
-
|
5
|
+
- ![.github/workflows/build.yml](https://github.com/ilyakatz/data-migrate/actions/workflows/.github/workflows/build.yml/badge.svg)
|
6
6
|
- [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
|
7
7
|
|
8
8
|
Run data migrations alongside schema migrations.
|
@@ -12,7 +12,7 @@ migrations, except they should be reserved for data migrations. For
|
|
12
12
|
instance, if you realize you need to titleize all your titles, this
|
13
13
|
is the place to do it.
|
14
14
|
|
15
|
-
![
|
15
|
+
![directory tree example](./screenshot.png)
|
16
16
|
|
17
17
|
## Why should I use this?
|
18
18
|
|
@@ -36,7 +36,7 @@ table to track all migrations.
|
|
36
36
|
|
37
37
|
## Rails Support
|
38
38
|
|
39
|
-
Support Rails
|
39
|
+
Support Rails 6.0 through 7.0
|
40
40
|
|
41
41
|
|
42
42
|
#### v1
|
@@ -92,11 +92,13 @@ You can generate a data migration as you would a schema migration:
|
|
92
92
|
rake db:version:with_data # Retrieves the current schema version numbers for data and schema migrations
|
93
93
|
|
94
94
|
|
95
|
-
Tasks work as they would with the 'vanilla' db version. The 'with_data' addition to the 'db' tasks will run the task in the context of both the data and schema migrations. That is, rake db:rollback:with_data will check to see if it was a schema or data migration invoked last, and do that. Tasks invoked in that space also have an additional line of output, indicating if the action is performed on data or schema.
|
95
|
+
Tasks work as they would with the 'vanilla' db version. The 'with_data' addition to the 'db' tasks will run the task in the context of both the data and schema migrations. That is, rake db:rollback:with_data will check to see if it was a schema or data migration invoked last, and do that. Tasks invoked in that space also have an additional line of output, indicating if the action is performed on data or schema.
|
96
96
|
|
97
97
|
With 'up' and 'down', you can specify the option 'BOTH', which defaults to false. Using true, will migrate both the data and schema (in the desired direction) if they both match the version provided. Again, going up, schema is given precedence. Down its data.
|
98
98
|
|
99
|
-
`rake db:migrate:
|
99
|
+
When using `rake db:migrate:with_data` migrations will be run in ascending order by their version. For example, if you have a data migration with version 20230410000000 and a schema migration with version 20230415000000, expect the data migration to run first.
|
100
|
+
|
101
|
+
`rake db:migrate:status:with_data` provides an additional column to indicate which type of migration.
|
100
102
|
|
101
103
|
### Configuration
|
102
104
|
|
@@ -162,9 +164,9 @@ Run tests for a specific version of Rails
|
|
162
164
|
|
163
165
|
```
|
164
166
|
bundle exec appraisal install
|
165
|
-
bundle exec appraisal rails-5.1 rspec
|
166
|
-
bundle exec appraisal rails-5.2 rspec
|
167
167
|
bundle exec appraisal rails-6.0 rspec
|
168
|
+
bundle exec appraisal rails-6.1 rspec
|
169
|
+
bundle exec appraisal rails-7.0 rspec
|
168
170
|
```
|
169
171
|
|
170
172
|
## Thanks
|
@@ -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(
|
17
|
-
filename = if
|
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
|
-
"#{
|
20
|
+
"#{spec_name}_#{schema_file_type(format)}"
|
21
21
|
end
|
22
22
|
|
23
|
-
ENV["DATA_SCHEMA"] || File.join(
|
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
|
59
|
-
migrations
|
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,
|
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
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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 &&
|
27
|
+
if spec_name && Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].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("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].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
|
-
|
36
|
-
|
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("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
|
48
|
+
ActiveRecord::Base.connection_db_config.configuration_hash[:database]
|
49
|
+
elsif Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].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.
|
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
|
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
|
-
|
51
|
-
|
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::
|
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
|
-
|
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: #{
|
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
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
|
99
|
+
db_config.name
|
100
|
+
elsif Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
|
101
|
+
db_config.spec_name
|
121
102
|
end
|
122
|
-
config
|
123
103
|
end
|
124
104
|
end
|
125
105
|
end
|
data/lib/data_migrate/version.rb
CHANGED
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", "
|
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", "
|
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
|
-
@
|
19
|
+
@original_data_migrations_path = DataMigrate.config.data_migrations_path
|
20
|
+
|
16
21
|
DataMigrate.configure do |config|
|
17
|
-
config.data_migrations_path =
|
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 = @
|
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
|
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
|
-
@
|
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 = @
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
31
|
-
|
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
|
-
|
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
|