nonschema_migrations 4.0.0 → 4.0.2
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/lib/nonschema_migrations.rb +1 -1
- data/lib/nonschema_migrator.rb +22 -18
- data/lib/tasks/data.rb +10 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 308147d2c0f3916b38a56e11aea98c3f9808e0a7ab7897eacacc7ee121e9c4dc
|
4
|
+
data.tar.gz: a51be4a671f86652e25f090617be568db61422f2e2d0b20af4ad93df70670649
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8708734499a58f62de26d2f19da57ab469c52fc40bb7223fa71d9593a43324bdc52dac451aad363a7f3396094f6aa81cf7b040ae76b6968659e6c035a2925aa
|
7
|
+
data.tar.gz: 35f45f07ca8b51e3821b5a7abbbdebb380c9b77e28204e97d09cccc7b7bc75d7a1964a2d0da93ed2d11b2b284103f155874fdb7a979970f51a6dd94079daf43e
|
data/lib/nonschema_migrations.rb
CHANGED
data/lib/nonschema_migrator.rb
CHANGED
@@ -1,25 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
class NondestructiveMigrator < ActiveRecord::Migrator
|
1
|
+
class NonschemaMigrator < ActiveRecord::Migrator
|
5
2
|
# This class related to data migration.
|
6
3
|
# Used in rake tasks (rake data:[migrate|rollback|up|down])
|
7
4
|
|
8
5
|
if defined?(ActiveRecord::MigrationContext)
|
9
6
|
class SchemaMigration < ActiveRecord::SchemaMigration
|
10
7
|
def self.table_name
|
11
|
-
|
8
|
+
NonschemaMigrator.schema_migrations_table_name
|
12
9
|
end
|
13
10
|
end
|
14
11
|
|
15
12
|
class MigrationContext < ActiveRecord::MigrationContext
|
16
13
|
def initialize(migrations_paths)
|
17
14
|
super(migrations_paths)
|
18
|
-
@schema_migration =
|
15
|
+
@schema_migration = NonschemaMigrator::SchemaMigration
|
19
16
|
end
|
20
17
|
|
21
18
|
def new_migrator(*args)
|
22
|
-
result =
|
19
|
+
result = NonschemaMigrator.new(*args)
|
23
20
|
result.migration_context = self
|
24
21
|
result
|
25
22
|
end
|
@@ -55,6 +52,10 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
55
52
|
(db_list + file_list).sort_by { |_, version, _| version }
|
56
53
|
end
|
57
54
|
|
55
|
+
def rollback(steps)
|
56
|
+
move(:down, steps)
|
57
|
+
end
|
58
|
+
|
58
59
|
def move(direction, steps)
|
59
60
|
migrator = new_migrator(direction, migrations)
|
60
61
|
|
@@ -76,20 +77,20 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
76
77
|
|
77
78
|
def up(target_version = nil)
|
78
79
|
selected_migrations = if block_given?
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
migrations.select { |m| yield m }
|
81
|
+
else
|
82
|
+
migrations
|
83
|
+
end
|
83
84
|
|
84
85
|
new_migrator(:up, selected_migrations, target_version).migrate
|
85
86
|
end
|
86
87
|
|
87
88
|
def down(target_version = nil)
|
88
89
|
selected_migrations = if block_given?
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
migrations.select { |m| yield m }
|
91
|
+
else
|
92
|
+
migrations
|
93
|
+
end
|
93
94
|
|
94
95
|
new_migrator(:down, selected_migrations, target_version).migrate
|
95
96
|
end
|
@@ -97,7 +98,7 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
97
98
|
|
98
99
|
class << self
|
99
100
|
def context(path)
|
100
|
-
|
101
|
+
NonschemaMigrator::MigrationContext.new(path)
|
101
102
|
end
|
102
103
|
|
103
104
|
def new_migrator(path, *args)
|
@@ -110,6 +111,10 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
110
111
|
context(path).migrate()
|
111
112
|
end
|
112
113
|
|
114
|
+
def rollback(path, steps = 1)
|
115
|
+
context(path).rollback(steps)
|
116
|
+
end
|
117
|
+
|
113
118
|
def run(direction, path, target_version)
|
114
119
|
new_migrator(path, direction, context(path).migrations, target_version).run
|
115
120
|
end
|
@@ -139,7 +144,7 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
139
144
|
def migrations_path
|
140
145
|
MIGRATIONS_PATH
|
141
146
|
end
|
142
|
-
|
147
|
+
|
143
148
|
def schema_migrations_table_name
|
144
149
|
'data_migrations'
|
145
150
|
end
|
@@ -158,4 +163,3 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
158
163
|
end
|
159
164
|
end
|
160
165
|
|
161
|
-
|
data/lib/tasks/data.rb
CHANGED
@@ -7,28 +7,33 @@ namespace :data do
|
|
7
7
|
|
8
8
|
desc "run data migration (#{MIGRATIONS_PATH})"
|
9
9
|
task :migrate => :data_migration_dependencies do
|
10
|
-
|
10
|
+
NonschemaMigrator.migrate(MIGRATIONS_PATH)
|
11
11
|
end
|
12
12
|
|
13
13
|
desc "rollback data migration (#{MIGRATIONS_PATH})"
|
14
14
|
task :rollback => :data_migration_dependencies do
|
15
|
-
|
16
|
-
NondestructiveMigrator.rollback(MIGRATIONS_PATH,step)
|
15
|
+
NonschemaMigrator.rollback(MIGRATIONS_PATH)
|
17
16
|
end
|
18
17
|
|
18
|
+
desc "honeybear (#{MIGRATIONS_PATH})"
|
19
|
+
task :honeybear => :data_migration_dependencies do
|
20
|
+
puts "hello honeybear"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
19
24
|
namespace :migrate do
|
20
25
|
desc %Q{runs the "up" for a given _data_ migration VERSION}
|
21
26
|
task :up => :data_migration_dependencies do
|
22
27
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
23
28
|
raise "VERSION is required" unless version
|
24
|
-
|
29
|
+
NonschemaMigrator.run(:up, MIGRATIONS_PATH, version)
|
25
30
|
end
|
26
31
|
|
27
32
|
desc %Q{runs the "down" for a given _data_ migration VERSION}
|
28
33
|
task :down => :data_migration_dependencies do
|
29
34
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
30
35
|
raise "VERSION is required" unless version
|
31
|
-
|
36
|
+
NonschemaMigrator.run(:down, MIGRATIONS_PATH, version)
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nonschema_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Fleetwood-Boldt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|