nonschema_migrations 3.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/data_migrations/templates/create_data_migrations.rb +1 -1
- data/lib/nonschema_migrations.rb +1 -2
- data/lib/nonschema_migrator.rb +40 -22
- data/lib/tasks/data.rb +10 -5
- metadata +16 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fcfd00d5152839069513ddc818ad6d4d2cc321c305b28e9ce1f975a6d749468
|
4
|
+
data.tar.gz: 43a8c72e87a0c2b46eecf8a423feb80e8738e6fc72a6bfcf4807611bf51b3c57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d0140f019c9e674d7467d038ddc4652f7c0f5f1e4f6c607b37396a52efb9e07d0e4e4b20af6d851daf75873ac44ba6c21a732d2ba9d6a022650b39506cbbb07
|
7
|
+
data.tar.gz: '097a3a4cd7ecd186f808a32bbe9eec6acd85fa0e05689d85fb4fed5d4c0560f16f7eb9862ee3e6757c8ba8b838f4946d893dd42b044b80a3f8d55924bf2c6591'
|
data/lib/nonschema_migrations.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
MIGRATIONS_PATH = 'db/data_migrate'
|
3
2
|
|
4
3
|
require 'generators/data_migrations/install_generator.rb'
|
@@ -6,6 +5,6 @@ require 'generators/data_migration_generator.rb'
|
|
6
5
|
require 'active_record/data_migration.rb'
|
7
6
|
require 'nonschema_migrator.rb'
|
8
7
|
|
9
|
-
module
|
8
|
+
module NonschemaMigrations
|
10
9
|
require "nonschema_migrations/railtie.rb" if defined?(Rails)
|
11
10
|
end
|
data/lib/nonschema_migrator.rb
CHANGED
@@ -1,32 +1,43 @@
|
|
1
|
+
class NonschemaMigrator < ActiveRecord::Migrator
|
2
|
+
# This class related to data migration.
|
3
|
+
# Used in rake tasks (rake data:[migrate|rollback|up|down])
|
1
4
|
|
5
|
+
def initialize(direction, migrations, no_op, target_version = nil)
|
6
|
+
@direction = direction
|
7
|
+
@target_version = target_version
|
8
|
+
@migrated_versions = nil
|
9
|
+
@migrations = migrations
|
2
10
|
|
11
|
+
validate(@migrations)
|
3
12
|
|
4
|
-
|
5
|
-
|
6
|
-
# Used in rake tasks (rake data:[migrate|rollback|up|down])
|
13
|
+
ActiveRecord::InternalMetadata.create_table
|
14
|
+
end
|
7
15
|
|
8
16
|
if defined?(ActiveRecord::MigrationContext)
|
9
|
-
class
|
17
|
+
class NonSchemaMigration < ActiveRecord::SchemaMigration
|
10
18
|
def self.table_name
|
11
|
-
|
19
|
+
NonschemaMigrator.schema_migrations_table_name
|
12
20
|
end
|
13
21
|
end
|
14
22
|
|
15
23
|
class MigrationContext < ActiveRecord::MigrationContext
|
16
|
-
def initialize(migrations_paths)
|
17
|
-
|
18
|
-
|
24
|
+
def initialize(migrations_paths, data_migration)
|
25
|
+
|
26
|
+
# super(migrations_paths, data_migration)
|
27
|
+
@migrations_paths = migrations_paths
|
28
|
+
|
29
|
+
@schema_migration = NonschemaMigrator::NonSchemaMigration
|
19
30
|
end
|
20
31
|
|
21
32
|
def new_migrator(*args)
|
22
|
-
result =
|
33
|
+
result = NonschemaMigrator.new(*args)
|
23
34
|
result.migration_context = self
|
24
35
|
result
|
25
36
|
end
|
26
37
|
|
27
38
|
# these methods are copied from ActiveRecord::Migrator
|
28
39
|
# replaced:
|
29
|
-
# 1.) ActiveRecord::
|
40
|
+
# 1.) ActiveRecord::NonSchemaMigration with @schema_migration
|
30
41
|
# 2.) ActiveRecord::Migrator.new with new_migrator
|
31
42
|
|
32
43
|
def get_all_versions
|
@@ -55,8 +66,12 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
55
66
|
(db_list + file_list).sort_by { |_, version, _| version }
|
56
67
|
end
|
57
68
|
|
69
|
+
def rollback(steps)
|
70
|
+
move(:down, steps)
|
71
|
+
end
|
72
|
+
|
58
73
|
def move(direction, steps)
|
59
|
-
migrator = new_migrator(direction, migrations)
|
74
|
+
migrator = new_migrator(direction, migrations, schema_migration)
|
60
75
|
|
61
76
|
if current_version != 0 && !migrator.current_migration
|
62
77
|
raise UnknownMigrationVersionError.new(current_version)
|
@@ -76,20 +91,20 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
76
91
|
|
77
92
|
def up(target_version = nil)
|
78
93
|
selected_migrations = if block_given?
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
94
|
+
migrations.select { |m| yield m }
|
95
|
+
else
|
96
|
+
migrations
|
97
|
+
end
|
83
98
|
|
84
99
|
new_migrator(:up, selected_migrations, target_version).migrate
|
85
100
|
end
|
86
101
|
|
87
102
|
def down(target_version = nil)
|
88
103
|
selected_migrations = if block_given?
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
104
|
+
migrations.select { |m| yield m }
|
105
|
+
else
|
106
|
+
migrations
|
107
|
+
end
|
93
108
|
|
94
109
|
new_migrator(:down, selected_migrations, target_version).migrate
|
95
110
|
end
|
@@ -97,7 +112,7 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
97
112
|
|
98
113
|
class << self
|
99
114
|
def context(path)
|
100
|
-
|
115
|
+
NonschemaMigrator::MigrationContext.new(path, ActiveRecord::DataMigration)
|
101
116
|
end
|
102
117
|
|
103
118
|
def new_migrator(path, *args)
|
@@ -110,6 +125,10 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
110
125
|
context(path).migrate()
|
111
126
|
end
|
112
127
|
|
128
|
+
def rollback(path, steps = 1)
|
129
|
+
context(path).rollback(steps)
|
130
|
+
end
|
131
|
+
|
113
132
|
def run(direction, path, target_version)
|
114
133
|
new_migrator(path, direction, context(path).migrations, target_version).run
|
115
134
|
end
|
@@ -139,7 +158,7 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
139
158
|
def migrations_path
|
140
159
|
MIGRATIONS_PATH
|
141
160
|
end
|
142
|
-
|
161
|
+
|
143
162
|
def schema_migrations_table_name
|
144
163
|
'data_migrations'
|
145
164
|
end
|
@@ -158,4 +177,3 @@ class NondestructiveMigrator < ActiveRecord::Migrator
|
|
158
177
|
end
|
159
178
|
end
|
160
179
|
|
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,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nonschema_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Fleetwood-Boldt
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '6.0'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
32
|
+
version: '7'
|
27
33
|
description: Separate schema-only migrations from nonschema (data) migrations in your
|
28
34
|
Rails app
|
29
35
|
email: jason.fb@datatravels.com
|
@@ -43,7 +49,7 @@ homepage: https://github.com/jasonfb/nonschema_migrations
|
|
43
49
|
licenses:
|
44
50
|
- MIT
|
45
51
|
metadata: {}
|
46
|
-
post_install_message:
|
52
|
+
post_install_message:
|
47
53
|
rdoc_options: []
|
48
54
|
require_paths:
|
49
55
|
- lib
|
@@ -58,9 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
64
|
- !ruby/object:Gem::Version
|
59
65
|
version: '0'
|
60
66
|
requirements: []
|
61
|
-
|
62
|
-
|
63
|
-
signing_key:
|
67
|
+
rubygems_version: 3.0.8
|
68
|
+
signing_key:
|
64
69
|
specification_version: 4
|
65
70
|
summary: Nonschema(data-only) migrations for your Rails app
|
66
71
|
test_files: []
|