data_migrate 8.0.0.rc1 → 8.0.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.
- checksums.yaml +4 -4
- data/Changelog.md +4 -0
- data/README.md +1 -1
- data/lib/data_migrate/schema_dumper.rb +1 -1
- data/lib/data_migrate/status_service_five.rb +1 -1
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +81 -0
- data/lib/data_migrate/version.rb +1 -1
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +46 -0
- data/tasks/databases.rake +2 -63
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86bd9c5c658d19081e2f3832e2637197c53ba841fb779a0424dae6b6d87c6685
|
4
|
+
data.tar.gz: 8698b30801c19530248088d6521de33c1688f548e7ce8b218ccd75ca4058bffb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4303810721d723a76494aee931ca4026b20590f762d9600f056cafd2e8af3e955067f56c0ecdea271f53aa0c1f82eb1f803078e20dd3483ec2a311a3cb5a2d55
|
7
|
+
data.tar.gz: ebee6c3e420f9d272daf4f428cdd71a24f9453fb1b845aee783b1348a45ce18a6539a6d60ce40885f39c8180035c940c71be7a685988fba1780445a8df1bc287
|
data/Changelog.md
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,11 @@ module DataMigrate
|
|
2
2
|
module Tasks
|
3
3
|
module DataMigrateTasks
|
4
4
|
extend self
|
5
|
+
|
6
|
+
def schema_migrations_path
|
7
|
+
File.join('db', 'migrate')
|
8
|
+
end
|
9
|
+
|
5
10
|
def migrations_paths
|
6
11
|
@migrations_paths ||= DataMigrate.config.data_migrations_path
|
7
12
|
end
|
@@ -40,6 +45,82 @@ module DataMigrate
|
|
40
45
|
ActiveRecord::Base.dump_schema_after_migration
|
41
46
|
end
|
42
47
|
end
|
48
|
+
|
49
|
+
def status
|
50
|
+
config = connect_to_database
|
51
|
+
return unless config
|
52
|
+
|
53
|
+
connection = ActiveRecord::Base.connection
|
54
|
+
puts "\ndatabase: #{config['database']}\n\n"
|
55
|
+
DataMigrate::StatusService.dump(connection)
|
56
|
+
end
|
57
|
+
|
58
|
+
def status_with_schema
|
59
|
+
config = connect_to_database
|
60
|
+
return unless config
|
61
|
+
|
62
|
+
db_list_data = ActiveRecord::Base.connection.select_values(
|
63
|
+
"SELECT version FROM #{DataMigrate::DataSchemaMigration.table_name}"
|
64
|
+
)
|
65
|
+
db_list_schema = ActiveRecord::Base.connection.select_values(
|
66
|
+
"SELECT version FROM #{ActiveRecord::SchemaMigration.schema_migrations_table_name}"
|
67
|
+
)
|
68
|
+
file_list = []
|
69
|
+
|
70
|
+
Dir.foreach(File.join(Rails.root, migrations_paths)) do |file|
|
71
|
+
# only files matching "20091231235959_some_name.rb" pattern
|
72
|
+
if match_data = /(\d{14})_(.+)\.rb/.match(file)
|
73
|
+
status = db_list_data.delete(match_data[1]) ? 'up' : 'down'
|
74
|
+
file_list << [status, match_data[1], match_data[2], 'data']
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
Dir.foreach(File.join(Rails.root, schema_migrations_path)) do |file|
|
79
|
+
# only files matching "20091231235959_some_name.rb" pattern
|
80
|
+
if match_data = /(\d{14})_(.+)\.rb/.match(file)
|
81
|
+
status = db_list_schema.delete(match_data[1]) ? 'up' : 'down'
|
82
|
+
file_list << [status, match_data[1], match_data[2], 'schema']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
file_list.sort!{|a,b| "#{a[1]}_#{a[3] == 'data' ? 1 : 0}" <=> "#{b[1]}_#{b[3] == 'data' ? 1 : 0}" }
|
87
|
+
|
88
|
+
# output
|
89
|
+
puts "\ndatabase: #{config['database']}\n\n"
|
90
|
+
puts "#{"Status".center(8)} #{"Type".center(8)} #{"Migration ID".ljust(14)} Migration Name"
|
91
|
+
puts "-" * 60
|
92
|
+
file_list.each do |file|
|
93
|
+
puts "#{file[0].center(8)} #{file[3].center(8)} #{file[1].ljust(14)} #{file[2].humanize}"
|
94
|
+
end
|
95
|
+
db_list_schema.each do |version|
|
96
|
+
puts "#{'up'.center(8)} #{version.ljust(14)} *** NO SCHEMA FILE ***"
|
97
|
+
end
|
98
|
+
db_list_data.each do |version|
|
99
|
+
puts "#{'up'.center(8)} #{version.ljust(14)} *** NO DATA FILE ***"
|
100
|
+
end
|
101
|
+
puts
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def connect_to_database
|
107
|
+
config = if ActiveRecord.version < Gem::Version.new('6.1')
|
108
|
+
ActiveRecord::Base.configurations[Rails.env || 'development']
|
109
|
+
else
|
110
|
+
ActiveRecord::Base.configurations.find_db_config(Rails.env || 'development').configuration_hash
|
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
|
121
|
+
end
|
122
|
+
config
|
123
|
+
end
|
43
124
|
end
|
44
125
|
end
|
45
126
|
end
|
data/lib/data_migrate/version.rb
CHANGED
@@ -115,4 +115,50 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
118
|
+
|
119
|
+
describe :status do
|
120
|
+
let(:db_config) do
|
121
|
+
{
|
122
|
+
adapter: "sqlite3",
|
123
|
+
database: "spec/db/test.db"
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
before do
|
128
|
+
if Rails::VERSION::MAJOR == 5
|
129
|
+
ActiveRecord::Base.configurations['test'] = db_config
|
130
|
+
else
|
131
|
+
hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', db_config)
|
132
|
+
config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
|
133
|
+
allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
|
134
|
+
end
|
135
|
+
|
136
|
+
allow(Rails).to receive(:root) { '.' }
|
137
|
+
|
138
|
+
if Rails::VERSION::MAJOR == 5
|
139
|
+
allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:schema_migrations_path) { 'spec/db/migrate/5.2' }
|
140
|
+
else
|
141
|
+
allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:schema_migrations_path) { 'spec/db/migrate/6.0' }
|
142
|
+
end
|
143
|
+
|
144
|
+
DataMigrate::Tasks::DataMigrateTasks.migrate
|
145
|
+
end
|
146
|
+
|
147
|
+
after do
|
148
|
+
ActiveRecord::Migration.drop_table("data_migrations")
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should display data migration status" do
|
152
|
+
expect {
|
153
|
+
DataMigrate::Tasks::DataMigrateTasks.status
|
154
|
+
}.to output(/up 20091231235959 Some name/).to_stdout
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should display schema and data migration status" do
|
158
|
+
expect {
|
159
|
+
DataMigrate::Tasks::DataMigrateTasks.status_with_schema
|
160
|
+
}.to output(match(/up data 20091231235959 Some name/)
|
161
|
+
.and match(/down schema 20131111111111 Late migration/)).to_stdout
|
162
|
+
end
|
163
|
+
end
|
118
164
|
end
|
data/tasks/databases.rake
CHANGED
@@ -114,49 +114,7 @@ namespace :db do
|
|
114
114
|
namespace :status do
|
115
115
|
desc "Display status of data and schema migrations"
|
116
116
|
task :with_data => :environment do
|
117
|
-
|
118
|
-
next unless config
|
119
|
-
|
120
|
-
db_list_data = ActiveRecord::Base.connection.select_values(
|
121
|
-
"SELECT version FROM #{DataMigrate::DataSchemaMigration.table_name}"
|
122
|
-
)
|
123
|
-
db_list_schema = ActiveRecord::Base.connection.select_values(
|
124
|
-
"SELECT version FROM #{ActiveRecord::SchemaMigration.schema_migrations_table_name}"
|
125
|
-
)
|
126
|
-
file_list = []
|
127
|
-
|
128
|
-
Dir.foreach(File.join(Rails.root, data_migrations_path)) do |file|
|
129
|
-
# only files matching "20091231235959_some_name.rb" pattern
|
130
|
-
if match_data = /(\d{14})_(.+)\.rb/.match(file)
|
131
|
-
status = db_list_data.delete(match_data[1]) ? 'up' : 'down'
|
132
|
-
file_list << [status, match_data[1], match_data[2], 'data']
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
Dir.foreach(File.join(Rails.root, 'db', 'migrate')) do |file|
|
137
|
-
# only files matching "20091231235959_some_name.rb" pattern
|
138
|
-
if match_data = /(\d{14})_(.+)\.rb/.match(file)
|
139
|
-
status = db_list_schema.delete(match_data[1]) ? 'up' : 'down'
|
140
|
-
file_list << [status, match_data[1], match_data[2], 'schema']
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
file_list.sort!{|a,b| "#{a[1]}_#{a[3] == 'data' ? 1 : 0}" <=> "#{b[1]}_#{b[3] == 'data' ? 1 : 0}" }
|
145
|
-
|
146
|
-
# output
|
147
|
-
puts "\ndatabase: #{config['database']}\n\n"
|
148
|
-
puts "#{"Status".center(8)} #{"Type".center(8)} #{"Migration ID".ljust(14)} Migration Name"
|
149
|
-
puts "-" * 60
|
150
|
-
file_list.each do |file|
|
151
|
-
puts "#{file[0].center(8)} #{file[3].center(8)} #{file[1].ljust(14)} #{file[2].humanize}"
|
152
|
-
end
|
153
|
-
db_list_schema.each do |version|
|
154
|
-
puts "#{'up'.center(8)} #{version.ljust(14)} *** NO SCHEMA FILE ***"
|
155
|
-
end
|
156
|
-
db_list_data.each do |version|
|
157
|
-
puts "#{'up'.center(8)} #{version.ljust(14)} *** NO DATA FILE ***"
|
158
|
-
end
|
159
|
-
puts
|
117
|
+
DataMigrate::Tasks::DataMigrateTasks.status_with_schema
|
160
118
|
end
|
161
119
|
end
|
162
120
|
end # END OF MIGRATE NAME SPACE
|
@@ -272,11 +230,7 @@ namespace :data do
|
|
272
230
|
|
273
231
|
desc "Display status of data migrations"
|
274
232
|
task :status => :environment do
|
275
|
-
|
276
|
-
ActiveRecord::Base.establish_connection(config)
|
277
|
-
connection = ActiveRecord::Base.connection
|
278
|
-
puts "\ndatabase: #{config['database']}\n\n"
|
279
|
-
DataMigrate::StatusService.dump(connection)
|
233
|
+
DataMigrate::Tasks::DataMigrateTasks.status
|
280
234
|
end
|
281
235
|
end
|
282
236
|
|
@@ -358,21 +312,6 @@ def sort_string migration
|
|
358
312
|
"#{migration[:version]}_#{migration[:kind] == :data ? 1 : 0}"
|
359
313
|
end
|
360
314
|
|
361
|
-
def connect_to_database
|
362
|
-
config = ActiveRecord::Base.configurations[Rails.env || 'development']
|
363
|
-
ActiveRecord::Base.establish_connection(config)
|
364
|
-
|
365
|
-
unless DataMigrate::DataSchemaMigration.table_exists?
|
366
|
-
puts 'Data migrations table does not exist yet.'
|
367
|
-
config = nil
|
368
|
-
end
|
369
|
-
unless ActiveRecord::SchemaMigration.table_exists?
|
370
|
-
puts 'Schema migrations table does not exist yet.'
|
371
|
-
config = nil
|
372
|
-
end
|
373
|
-
config
|
374
|
-
end
|
375
|
-
|
376
315
|
def past_migrations(sort=nil)
|
377
316
|
DataMigrate::DatabaseTasks.past_migrations(sort)
|
378
317
|
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: 8.0.0
|
4
|
+
version: 8.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew J Vargo
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-03-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -287,9 +287,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
287
287
|
version: '0'
|
288
288
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
289
289
|
requirements:
|
290
|
-
- - "
|
290
|
+
- - ">="
|
291
291
|
- !ruby/object:Gem::Version
|
292
|
-
version:
|
292
|
+
version: '0'
|
293
293
|
requirements: []
|
294
294
|
rubygems_version: 3.2.32
|
295
295
|
signing_key:
|