nonschema_migrations 6.0.alpha1 → 6.6
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/.bundle/config +2 -0
- data/.github/FUNDING.yml +3 -0
- data/.gitignore +3 -0
- data/.travis.yml +36 -0
- data/Appraisals +32 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +102 -0
- data/LICENCE.md +21 -0
- data/README.md +169 -0
- data/Rakefile +31 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_4_0.gemfile +22 -0
- data/gemfiles/rails_4_0.gemfile.lock +0 -0
- data/gemfiles/rails_4_1.gemfile +21 -0
- data/gemfiles/rails_4_1.gemfile.lock +164 -0
- data/gemfiles/rails_4_2.gemfile +21 -0
- data/gemfiles/rails_4_2.gemfile.lock +189 -0
- data/gemfiles/rails_5_0.gemfile +21 -0
- data/gemfiles/rails_5_0.gemfile.lock +196 -0
- data/gemfiles/rails_5_1.gemfile +20 -0
- data/gemfiles/rails_5_1.gemfile.lock +195 -0
- data/gemfiles/rails_5_2.gemfile +20 -0
- data/gemfiles/rails_5_2.gemfile.lock +203 -0
- data/gemfiles/rails_6_0.gemfile +20 -0
- data/lib/active_record/data_migration.rb +16 -1
- data/lib/active_record/data_tasks.rb +91 -0
- data/lib/generators/data_migrations/templates/migration.rb +5 -0
- data/lib/nonschema_migrations/version.rb +3 -0
- data/lib/nonschema_migrator.rb +199 -167
- data/lib/tasks/data.rb +1 -7
- metadata +48 -19
data/lib/nonschema_migrator.rb
CHANGED
@@ -1,179 +1,211 @@
|
|
1
|
-
|
2
|
-
# This class related to data migration.
|
3
|
-
# Used in rake tasks (rake data:[migrate|rollback|up|down])
|
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
|
-
|
16
|
-
if defined?(ActiveRecord::MigrationContext)
|
17
|
-
class NonSchemaMigration < ActiveRecord::SchemaMigration
|
18
|
-
def self.table_name
|
19
|
-
NonschemaMigrator.schema_migrations_table_name
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class MigrationContext < ActiveRecord::MigrationContext
|
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
|
30
|
-
end
|
31
|
-
|
32
|
-
def new_migrator(*args)
|
33
|
-
result = NonschemaMigrator.new(*args)
|
34
|
-
result.migration_context = self
|
35
|
-
result
|
36
|
-
end
|
37
|
-
|
38
|
-
# these methods are copied from ActiveRecord::Migrator
|
39
|
-
# replaced:
|
40
|
-
# 1.) ActiveRecord::NonSchemaMigration with @schema_migration
|
41
|
-
# 2.) ActiveRecord::Migrator.new with new_migrator
|
42
|
-
|
43
|
-
def get_all_versions
|
44
|
-
if @schema_migration.table_exists?
|
45
|
-
@schema_migration.all_versions.map(&:to_i)
|
46
|
-
else
|
47
|
-
[]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def migrations_status
|
52
|
-
db_list = @schema_migration.normalized_versions
|
53
|
-
|
54
|
-
file_list = migration_files.map do |file|
|
55
|
-
version, name, scope = parse_migration_filename(file)
|
56
|
-
raise IllegalMigrationNameError.new(file) unless version
|
57
|
-
version = @schema_migration.normalize_migration_number(version)
|
58
|
-
status = db_list.delete(version) ? "up" : "down"
|
59
|
-
[status, version, (name + scope).humanize]
|
60
|
-
end.compact
|
61
|
-
|
62
|
-
db_list.map! do |version|
|
63
|
-
["up", version, "********** NO FILE **********"]
|
64
|
-
end
|
65
|
-
|
66
|
-
(db_list + file_list).sort_by { |_, version, _| version }
|
67
|
-
end
|
68
|
-
|
69
|
-
def rollback(steps)
|
70
|
-
move(:down, steps)
|
71
|
-
end
|
1
|
+
require_relative "./active_record/data_tasks.rb"
|
72
2
|
|
73
|
-
|
74
|
-
migrator = new_migrator(direction, migrations, schema_migration)
|
3
|
+
class NonschemaMigrator
|
75
4
|
|
76
|
-
|
77
|
-
raise UnknownMigrationVersionError.new(current_version)
|
78
|
-
end
|
5
|
+
# include ActiveRecord::Tasks::DatabaseTasks
|
79
6
|
|
80
|
-
|
81
|
-
|
82
|
-
0
|
83
|
-
else
|
84
|
-
migrator.migrations.index(migrator.current_migration)
|
85
|
-
end
|
86
|
-
|
87
|
-
finish = migrator.migrations[start_index + steps]
|
88
|
-
version = finish ? finish.version : 0
|
89
|
-
send(direction, version)
|
90
|
-
end
|
91
|
-
|
92
|
-
def up(target_version = nil)
|
93
|
-
selected_migrations = if block_given?
|
94
|
-
migrations.select { |m| yield m }
|
95
|
-
else
|
96
|
-
migrations
|
97
|
-
end
|
98
|
-
|
99
|
-
new_migrator(:up, selected_migrations, target_version).migrate
|
100
|
-
end
|
101
|
-
|
102
|
-
def down(target_version = nil)
|
103
|
-
selected_migrations = if block_given?
|
104
|
-
migrations.select { |m| yield m }
|
105
|
-
else
|
106
|
-
migrations
|
107
|
-
end
|
108
|
-
|
109
|
-
new_migrator(:down, selected_migrations, target_version).migrate
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
class << self
|
114
|
-
def context(path)
|
115
|
-
NonschemaMigrator::MigrationContext.new(path, ActiveRecord::DataMigration)
|
116
|
-
end
|
117
|
-
|
118
|
-
def new_migrator(path, *args)
|
119
|
-
result = self.new(*args)
|
120
|
-
result.migration_context=context(path)
|
121
|
-
result
|
122
|
-
end
|
123
|
-
|
124
|
-
def migrate(path)
|
125
|
-
context(path).migrate()
|
126
|
-
end
|
127
|
-
|
128
|
-
def rollback(path, steps = 1)
|
129
|
-
context(path).rollback(steps)
|
130
|
-
end
|
131
|
-
|
132
|
-
def run(direction, path, target_version)
|
133
|
-
new_migrator(path, direction, context(path).migrations, target_version).run
|
134
|
-
end
|
135
|
-
end
|
7
|
+
# This class related to data migration.
|
8
|
+
# Used in rake tasks (rake data:[migrate|rollback|up|down])
|
136
9
|
|
137
|
-
def migration_context=(context)
|
138
|
-
@migration_context = context
|
139
|
-
end
|
140
10
|
|
141
|
-
|
142
|
-
|
143
|
-
end
|
11
|
+
def self.migrate(version = nil)
|
12
|
+
ActiveRecord::Tasks::DataTasks.migrate(version)
|
144
13
|
end
|
145
14
|
|
146
|
-
def
|
147
|
-
|
148
|
-
migrated.delete(version)
|
149
|
-
ActiveRecord::DataMigration.where(:version => version.to_s).delete_all
|
150
|
-
else
|
151
|
-
migrated << version
|
152
|
-
ActiveRecord::DataMigration.create!(:version => version.to_s)
|
153
|
-
end
|
15
|
+
def self.rollback
|
16
|
+
ActiveRecord::Tasks::DataTasks.rollback
|
154
17
|
end
|
155
18
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
def schema_migrations_table_name
|
167
|
-
ActiveRecord::DataMigration.table_name
|
168
|
-
end
|
169
|
-
|
170
|
-
def get_all_versions(connection = ActiveRecord::Base.connection)
|
171
|
-
if connection.table_exists?(schema_migrations_table_name)
|
172
|
-
ActiveRecord::DataMigration.all.map { |x| x.version.to_i }.sort
|
173
|
-
else
|
174
|
-
[]
|
175
|
-
end
|
176
|
-
end
|
19
|
+
def initialize(direction, migrations, no_op, target_version = nil)
|
20
|
+
# @direction = direction
|
21
|
+
# @target_version = target_version
|
22
|
+
# @migrated_versions = nil
|
23
|
+
# @migrations = migrations
|
24
|
+
#
|
25
|
+
# validate(@migrations)
|
26
|
+
#
|
27
|
+
# ActiveRecord::DataMigration.create_table
|
177
28
|
end
|
29
|
+
|
30
|
+
# if defined?(ActiveRecord::MigrationContext)
|
31
|
+
# class NonSchemaMigration < ActiveRecord::SchemaMigration
|
32
|
+
# def self.table_name
|
33
|
+
# NonschemaMigrator.schema_migrations_table_name
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# def self.get_all_versions
|
37
|
+
# versions
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# def versions
|
41
|
+
# sm = Arel::SelectManager.new(arel_table)
|
42
|
+
# sm.project(arel_table[primary_key])
|
43
|
+
# sm.order(arel_table[primary_key].asc)
|
44
|
+
#
|
45
|
+
# connection.select_values(sm, "#{self.class} Load")
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# class MigrationContext < ActiveRecord::MigrationContext
|
50
|
+
# def initialize(migrations_paths, data_migration)
|
51
|
+
#
|
52
|
+
# # super(migrations_paths, data_migration)
|
53
|
+
# @migrations_paths = migrations_paths
|
54
|
+
#
|
55
|
+
# @schema_migration = NonschemaMigrator::NonSchemaMigration
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# def new_migrator(*args)
|
59
|
+
# result = NonschemaMigrator.new(*args)
|
60
|
+
# result.migration_context = self
|
61
|
+
# result
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# def schema_migrations_table_name
|
65
|
+
# 'data_migrations'
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# # these methods are copied from ActiveRecord::Migrator
|
69
|
+
# # replaced:
|
70
|
+
# # 1.) ActiveRecord::NonSchemaMigration with @schema_migration
|
71
|
+
# # 2.) ActiveRecord::Migrator.new with new_migrator
|
72
|
+
#
|
73
|
+
# def get_all_versions
|
74
|
+
# byebug
|
75
|
+
# if connection.table_exists?(schema_migrations_table_name)
|
76
|
+
# @schema_migration.all_versions.map(&:to_i)
|
77
|
+
# else
|
78
|
+
# []
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# def migrations_status
|
83
|
+
# db_list = @schema_migration.normalized_versions
|
84
|
+
#
|
85
|
+
# file_list = migration_files.map do |file|
|
86
|
+
# version, name, scope = parse_migration_filename(file)
|
87
|
+
# raise IllegalMigrationNameError.new(file) unless version
|
88
|
+
# version = @schema_migration.normalize_migration_number(version)
|
89
|
+
# status = db_list.delete(version) ? "up" : "down"
|
90
|
+
# [status, version, (name + scope).humanize]
|
91
|
+
# end.compact
|
92
|
+
#
|
93
|
+
# db_list.map! do |version|
|
94
|
+
# ["up", version, "********** NO FILE **********"]
|
95
|
+
# end
|
96
|
+
#
|
97
|
+
# (db_list + file_list).sort_by { |_, version, _| version }
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# def rollback(steps)
|
101
|
+
# move(:down, steps)
|
102
|
+
# end
|
103
|
+
#
|
104
|
+
# def move(direction, steps)
|
105
|
+
# migrator = new_migrator(direction, migrations, nil, schema_migration)
|
106
|
+
#
|
107
|
+
# if current_version != 0 && !migrator.current_migration
|
108
|
+
# raise UnknownMigrationVersionError.new(current_version)
|
109
|
+
# end
|
110
|
+
#
|
111
|
+
# start_index =
|
112
|
+
# if current_version == 0
|
113
|
+
# 0
|
114
|
+
# else
|
115
|
+
# migrator.migrations.index(migrator.current_migration)
|
116
|
+
# end
|
117
|
+
#
|
118
|
+
# finish = migrator.migrations[start_index + steps]
|
119
|
+
# version = finish ? finish.version : 0
|
120
|
+
# send(direction, version)
|
121
|
+
# end
|
122
|
+
#
|
123
|
+
# def up(target_version = nil)
|
124
|
+
# selected_migrations = if block_given?
|
125
|
+
# migrations.select { |m| yield m }
|
126
|
+
# else
|
127
|
+
# migrations
|
128
|
+
# end
|
129
|
+
#
|
130
|
+
# new_migrator(:up, selected_migrations, nil, target_version).migrate
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
# def down(target_version = nil)
|
134
|
+
# selected_migrations = if block_given?
|
135
|
+
# migrations.select { |m| yield m }
|
136
|
+
# else
|
137
|
+
# migrations
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# new_migrator(:down, selected_migrations, nil, target_version).migrate
|
141
|
+
# end
|
142
|
+
# end
|
143
|
+
#
|
144
|
+
# class << self
|
145
|
+
# def context(path)
|
146
|
+
# NonschemaMigrator::MigrationContext.new(path, ActiveRecord::DataMigration)
|
147
|
+
# end
|
148
|
+
#
|
149
|
+
# def new_migrator(path, *args)
|
150
|
+
# result = self.new(*args)
|
151
|
+
# result.migration_context=context(path)
|
152
|
+
# result
|
153
|
+
# end
|
154
|
+
#
|
155
|
+
# def migrate(path)
|
156
|
+
# context(path).migrate()
|
157
|
+
# end
|
158
|
+
#
|
159
|
+
# def rollback(path, steps = 1)
|
160
|
+
# context(path).rollback(steps)
|
161
|
+
# end
|
162
|
+
#
|
163
|
+
# def run(direction, path, target_version)
|
164
|
+
# new_migrator(path, direction, context(path).migrations, nil, target_version).run
|
165
|
+
# end
|
166
|
+
# end
|
167
|
+
#
|
168
|
+
# def migration_context=(context)
|
169
|
+
# @migration_context = context
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# def load_migrated
|
173
|
+
# @migrated_versions = Set.new(@migration_context.get_all_versions)
|
174
|
+
# end
|
175
|
+
#
|
176
|
+
# def schema_migrations_table_name
|
177
|
+
# 'data_migrations'
|
178
|
+
# end
|
179
|
+
#
|
180
|
+
# end
|
181
|
+
#
|
182
|
+
# def record_version_state_after_migrating(version)
|
183
|
+
# if down?
|
184
|
+
# migrated.delete(version)
|
185
|
+
# ActiveRecord::DataMigration.where(:version => version.to_s).delete_all
|
186
|
+
# else
|
187
|
+
# migrated << version
|
188
|
+
# ActiveRecord::DataMigration.create!(:version => version.to_s)
|
189
|
+
# end
|
190
|
+
# end
|
191
|
+
#
|
192
|
+
#
|
193
|
+
# class <<self
|
194
|
+
# def migrations_path
|
195
|
+
# MIGRATIONS_PATH
|
196
|
+
# end
|
197
|
+
#
|
198
|
+
# def schema_migrations_table_name
|
199
|
+
# 'data_migrations'
|
200
|
+
# end
|
201
|
+
#
|
202
|
+
# def get_all_versions(connection = ActiveRecord::Base.connection)
|
203
|
+
# if connection.table_exists?(schema_migrations_table_name)
|
204
|
+
# ActiveRecord::DataMigration.all.map { |x| x.version.to_i }.sort
|
205
|
+
# else
|
206
|
+
# []
|
207
|
+
# end
|
208
|
+
# end
|
209
|
+
# end
|
178
210
|
end
|
179
211
|
|
data/lib/tasks/data.rb
CHANGED
@@ -12,15 +12,9 @@ namespace :data do
|
|
12
12
|
|
13
13
|
desc "rollback data migration (#{MIGRATIONS_PATH})"
|
14
14
|
task :rollback => :data_migration_dependencies do
|
15
|
-
NonschemaMigrator.rollback
|
15
|
+
NonschemaMigrator.rollback
|
16
16
|
end
|
17
17
|
|
18
|
-
desc "honeybear (#{MIGRATIONS_PATH})"
|
19
|
-
task :honeybear => :data_migration_dependencies do
|
20
|
-
puts "hello honeybear"
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
18
|
namespace :migrate do
|
25
19
|
desc %Q{runs the "up" for a given _data_ migration VERSION}
|
26
20
|
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: 6.
|
4
|
+
version: '6.6'
|
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:
|
11
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 7.
|
19
|
+
version: '7.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.1'
|
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: '7.1'
|
30
|
+
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: 7.
|
32
|
+
version: '7.1'
|
27
33
|
description: Separate schema-only migrations from nonschema (data) migrations in your
|
28
34
|
Rails app
|
29
35
|
email: code@jasonfb.net
|
@@ -31,12 +37,39 @@ executables: []
|
|
31
37
|
extensions: []
|
32
38
|
extra_rdoc_files: []
|
33
39
|
files:
|
40
|
+
- ".bundle/config"
|
41
|
+
- ".github/FUNDING.yml"
|
42
|
+
- ".gitignore"
|
43
|
+
- ".travis.yml"
|
44
|
+
- Appraisals
|
45
|
+
- Gemfile
|
46
|
+
- Gemfile.lock
|
47
|
+
- LICENCE.md
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- gemfiles/.bundle/config
|
51
|
+
- gemfiles/rails_4_0.gemfile
|
52
|
+
- gemfiles/rails_4_0.gemfile.lock
|
53
|
+
- gemfiles/rails_4_1.gemfile
|
54
|
+
- gemfiles/rails_4_1.gemfile.lock
|
55
|
+
- gemfiles/rails_4_2.gemfile
|
56
|
+
- gemfiles/rails_4_2.gemfile.lock
|
57
|
+
- gemfiles/rails_5_0.gemfile
|
58
|
+
- gemfiles/rails_5_0.gemfile.lock
|
59
|
+
- gemfiles/rails_5_1.gemfile
|
60
|
+
- gemfiles/rails_5_1.gemfile.lock
|
61
|
+
- gemfiles/rails_5_2.gemfile
|
62
|
+
- gemfiles/rails_5_2.gemfile.lock
|
63
|
+
- gemfiles/rails_6_0.gemfile
|
34
64
|
- lib/active_record/data_migration.rb
|
65
|
+
- lib/active_record/data_tasks.rb
|
35
66
|
- lib/generators/data_migration_generator.rb
|
36
67
|
- lib/generators/data_migrations/install_generator.rb
|
37
68
|
- lib/generators/data_migrations/templates/create_data_migrations.rb
|
69
|
+
- lib/generators/data_migrations/templates/migration.rb
|
38
70
|
- lib/nonschema_migrations.rb
|
39
71
|
- lib/nonschema_migrations/railtie.rb
|
72
|
+
- lib/nonschema_migrations/version.rb
|
40
73
|
- lib/nonschema_migrator.rb
|
41
74
|
- lib/tasks/data.rb
|
42
75
|
homepage: https://github.com/jasonfb/nonschema_migrations
|
@@ -46,15 +79,11 @@ metadata:
|
|
46
79
|
source_code_uri: https://github.com/jasonfb/nonschema_migrations
|
47
80
|
documentation_uri: https://jasonfleetwoodboldt.com/my-open-source-projects/nonschema-migrations/
|
48
81
|
homepage_uri: https://heliosdev.shop/
|
49
|
-
post_install_message:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
rails generate data_migrations:install
|
55
|
-
|
56
|
-
For support please check us out at https://heliosdev.shop/
|
57
|
-
---------------------------------------------
|
82
|
+
post_install_message: "---------------------------------------------\nWelcome to Nonschema
|
83
|
+
Migrations\n\n1. run set up data migrations:\nrails generate data_migrations:install\n2.
|
84
|
+
to create a data migration use\nrails generate data_migration SetupExampleData\n\nYou
|
85
|
+
can think of data migrations like seed data for production, staging, and dev environments.
|
86
|
+
\n\nFor support please see https://heliosdev.shop/\n---------------------------------------------\n"
|
58
87
|
rdoc_options: []
|
59
88
|
require_paths:
|
60
89
|
- lib
|
@@ -65,11 +94,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
94
|
version: '0'
|
66
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
96
|
requirements:
|
68
|
-
- - "
|
97
|
+
- - ">="
|
69
98
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
99
|
+
version: '0'
|
71
100
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.4.10
|
73
102
|
signing_key:
|
74
103
|
specification_version: 4
|
75
104
|
summary: Nonschema(data-only) migrations for your Rails app
|