nonschema_migrations 3.0.1 → 5.1.1
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 +0 -1
- data/lib/nonschema_migrator.rb +36 -22
- data/lib/tasks/data.rb +7 -2
- metadata +19 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 548cbf414a8294a059f8ea134b04c55b61b22327eb2487c6f27c78253448c6a1
|
4
|
+
data.tar.gz: 41a26eea2b8565e486de2178f593bbfc7a7a2d875b62ab7fc443502b6d0c1cae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c915a45cad9df1ddea2df6b70b32f50468e905dfb076a3be91e752e73bdb4bacc31403ac951927ed85e286feaf8dfc3914e16f2803d2309ca439cc62f0823e6
|
7
|
+
data.tar.gz: f7d41831c51a8a06579f3274feaef7f3ce32a68b67e62815796aec23589cb9ccf97536516541274c1a6c15557db18b611ce501f087a322479d22862ec68d7093
|
data/lib/nonschema_migrations.rb
CHANGED
data/lib/nonschema_migrator.rb
CHANGED
@@ -1,21 +1,32 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
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
|
|
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
|
10
|
+
|
11
|
+
validate(@migrations)
|
12
|
+
|
13
|
+
ActiveRecord::InternalMetadata.create_table
|
14
|
+
end
|
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)
|
@@ -26,7 +37,7 @@ class NonschemaMigrator < ActiveRecord::Migrator
|
|
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,14 +66,12 @@ class NonschemaMigrator < ActiveRecord::Migrator
|
|
55
66
|
(db_list + file_list).sort_by { |_, version, _| version }
|
56
67
|
end
|
57
68
|
|
58
|
-
|
59
69
|
def rollback(steps)
|
60
70
|
move(:down, steps)
|
61
71
|
end
|
62
72
|
|
63
|
-
|
64
73
|
def move(direction, steps)
|
65
|
-
migrator = new_migrator(direction, migrations)
|
74
|
+
migrator = new_migrator(direction, migrations, schema_migration)
|
66
75
|
|
67
76
|
if current_version != 0 && !migrator.current_migration
|
68
77
|
raise UnknownMigrationVersionError.new(current_version)
|
@@ -82,20 +91,20 @@ class NonschemaMigrator < ActiveRecord::Migrator
|
|
82
91
|
|
83
92
|
def up(target_version = nil)
|
84
93
|
selected_migrations = if block_given?
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
94
|
+
migrations.select { |m| yield m }
|
95
|
+
else
|
96
|
+
migrations
|
97
|
+
end
|
89
98
|
|
90
99
|
new_migrator(:up, selected_migrations, target_version).migrate
|
91
100
|
end
|
92
101
|
|
93
102
|
def down(target_version = nil)
|
94
103
|
selected_migrations = if block_given?
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
104
|
+
migrations.select { |m| yield m }
|
105
|
+
else
|
106
|
+
migrations
|
107
|
+
end
|
99
108
|
|
100
109
|
new_migrator(:down, selected_migrations, target_version).migrate
|
101
110
|
end
|
@@ -103,7 +112,7 @@ class NonschemaMigrator < ActiveRecord::Migrator
|
|
103
112
|
|
104
113
|
class << self
|
105
114
|
def context(path)
|
106
|
-
NonschemaMigrator::MigrationContext.new(path)
|
115
|
+
NonschemaMigrator::MigrationContext.new(path, ActiveRecord::DataMigration)
|
107
116
|
end
|
108
117
|
|
109
118
|
def new_migrator(path, *args)
|
@@ -116,6 +125,10 @@ class NonschemaMigrator < ActiveRecord::Migrator
|
|
116
125
|
context(path).migrate()
|
117
126
|
end
|
118
127
|
|
128
|
+
def rollback(path, steps = 1)
|
129
|
+
context(path).rollback(steps)
|
130
|
+
end
|
131
|
+
|
119
132
|
def run(direction, path, target_version)
|
120
133
|
new_migrator(path, direction, context(path).migrations, target_version).run
|
121
134
|
end
|
@@ -145,7 +158,7 @@ class NonschemaMigrator < ActiveRecord::Migrator
|
|
145
158
|
def migrations_path
|
146
159
|
MIGRATIONS_PATH
|
147
160
|
end
|
148
|
-
|
161
|
+
|
149
162
|
def schema_migrations_table_name
|
150
163
|
'data_migrations'
|
151
164
|
end
|
@@ -162,4 +175,5 @@ class NonschemaMigrator < ActiveRecord::Migrator
|
|
162
175
|
end
|
163
176
|
end
|
164
177
|
end
|
165
|
-
end
|
178
|
+
end
|
179
|
+
|
data/lib/tasks/data.rb
CHANGED
@@ -12,10 +12,15 @@ namespace :data do
|
|
12
12
|
|
13
13
|
desc "rollback data migration (#{MIGRATIONS_PATH})"
|
14
14
|
task :rollback => :data_migration_dependencies do
|
15
|
-
|
16
|
-
NonschemaMigrator.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
|
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.1
|
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:
|
11
|
+
date: 2020-10-29 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
|
@@ -39,11 +45,12 @@ files:
|
|
39
45
|
- lib/nonschema_migrations/railtie.rb
|
40
46
|
- lib/nonschema_migrator.rb
|
41
47
|
- lib/tasks/data.rb
|
42
|
-
homepage: https://
|
48
|
+
homepage: https://blog.jasonfleetwoodboldt.com/nonschema-migrations/
|
43
49
|
licenses:
|
44
50
|
- MIT
|
45
|
-
metadata:
|
46
|
-
|
51
|
+
metadata:
|
52
|
+
source_code_uri: https://github.com/jasonfb/nonschema_migrations
|
53
|
+
post_install_message:
|
47
54
|
rdoc_options: []
|
48
55
|
require_paths:
|
49
56
|
- lib
|
@@ -58,9 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
65
|
- !ruby/object:Gem::Version
|
59
66
|
version: '0'
|
60
67
|
requirements: []
|
61
|
-
|
62
|
-
|
63
|
-
signing_key:
|
68
|
+
rubygems_version: 3.0.8
|
69
|
+
signing_key:
|
64
70
|
specification_version: 4
|
65
71
|
summary: Nonschema(data-only) migrations for your Rails app
|
66
72
|
test_files: []
|