data_migrate 9.0.0 → 10.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.
- checksums.yaml +4 -4
- data/.github/workflows/gempush.yml +1 -0
- data/.travis.yml +0 -3
- data/Appraisals +0 -4
- data/Changelog.md +8 -0
- data/README.md +3 -3
- 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 +28 -5
- metadata +9 -19
- 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: d212f0e6fa0c9b767cbdf17854c7c52d640a9c8611d0b10ed6c0460de68985cd
|
4
|
+
data.tar.gz: ac338ef447f1942d64eb5cf6c0fe520f71089968c04fb03fb829a1318534b4eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01ae940433e4cd51a2f421297fb3ffb72372503971ee906164129c035c89aedb6c18d5003cd083930c24245f16728c38c93aed94fb8d9b2f7d0288895362a3d4
|
7
|
+
data.tar.gz: 9d94ff40ed274256247960c0dd1325645b638ac2198d29b3bce2c3c11f842b4b0a2b381bd73fcb17af308ab366cdca16c7f99c9e2fa778da7ab6103352e50ba1
|
data/.travis.yml
CHANGED
@@ -5,13 +5,10 @@ rvm:
|
|
5
5
|
- 3.2
|
6
6
|
script: bundle exec rspec
|
7
7
|
gemfile:
|
8
|
-
- gemfiles/rails_5.2.gemfile
|
9
8
|
- gemfiles/rails_6.0.gemfile
|
10
9
|
- gemfiles/rails_6.1.gemfile
|
11
10
|
- gemfiles/rails_7.0.gemfile
|
12
11
|
jobs:
|
13
12
|
exclude:
|
14
13
|
- rvm: 3.0
|
15
|
-
gemfile: gemfiles/rails_5.2.gemfile
|
16
14
|
- rvm: 3.2
|
17
|
-
gemfile: gemfiles/rails_5.2.gemfile
|
data/Appraisals
CHANGED
data/Changelog.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 10.0.0.rc1
|
4
|
+
|
5
|
+
- Changes by [chaunce](https//:github.com/chaunce)
|
6
|
+
- Multiple databases support
|
7
|
+
- Refactor to clean things up
|
8
|
+
- Deprecate rails 5.2 support for real
|
9
|
+
|
10
|
+
|
3
11
|
## 9.0.0
|
4
12
|
|
5
13
|
Ruby 3.2 support [mehanoid](https://github.com/mehanoid)
|
data/README.md
CHANGED
@@ -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
|
@@ -162,9 +162,9 @@ Run tests for a specific version of Rails
|
|
162
162
|
|
163
163
|
```
|
164
164
|
bundle exec appraisal install
|
165
|
-
bundle exec appraisal rails-5.1 rspec
|
166
|
-
bundle exec appraisal rails-5.2 rspec
|
167
165
|
bundle exec appraisal rails-6.0 rspec
|
166
|
+
bundle exec appraisal rails-6.1 rspec
|
167
|
+
bundle exec appraisal rails-7.0 rspec
|
168
168
|
```
|
169
169
|
|
170
170
|
## Thanks
|
@@ -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("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
|
26
28
|
ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: spec_name).migrations_paths
|
27
|
-
elsif spec_name
|
29
|
+
elsif spec_name && Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
|
28
30
|
ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: spec_name).migrations_paths
|
29
31
|
else
|
30
32
|
Rails.application.config.paths["db/migrate"].to_a
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DataMigrate
|
2
4
|
class StatusService
|
3
5
|
class << self
|
@@ -32,12 +34,8 @@ module DataMigrate
|
|
32
34
|
end
|
33
35
|
|
34
36
|
# output
|
35
|
-
|
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("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
|
48
|
+
ActiveRecord::Base.connection_db_config.configuration_hash[:database]
|
49
|
+
elsif Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
|
50
|
+
ActiveRecord::Base.connection_config[:database]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
48
54
|
def db_list
|
49
55
|
DataMigrate::DataMigrator.migrations_status
|
50
56
|
end
|
@@ -1,19 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DataMigrate
|
2
4
|
module Tasks
|
3
5
|
module DataMigrateTasks
|
4
6
|
extend self
|
5
7
|
|
6
|
-
def schema_migrations_path
|
7
|
-
File.join('db', 'migrate')
|
8
|
-
end
|
9
|
-
|
10
8
|
def migrations_paths
|
11
9
|
@migrations_paths ||= DataMigrate.config.data_migrations_path
|
12
10
|
end
|
13
11
|
|
14
|
-
def dump
|
12
|
+
def dump(db_config)
|
15
13
|
if dump_schema_after_migration?
|
16
|
-
filename = DataMigrate::DatabaseTasks.
|
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("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
|
99
|
+
db_config.name
|
100
|
+
elsif Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
|
101
|
+
db_config.spec_name
|
121
102
|
end
|
122
|
-
config
|
123
103
|
end
|
124
104
|
end
|
125
105
|
end
|
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
|