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
@@ -0,0 +1,203 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
nondestructive_migrations (1.3)
|
5
|
+
activerecord (~> 5.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (5.2.0.rc1)
|
11
|
+
actionpack (= 5.2.0.rc1)
|
12
|
+
nio4r (~> 2.0)
|
13
|
+
websocket-driver (>= 0.6.1)
|
14
|
+
actionmailer (5.2.0.rc1)
|
15
|
+
actionpack (= 5.2.0.rc1)
|
16
|
+
actionview (= 5.2.0.rc1)
|
17
|
+
activejob (= 5.2.0.rc1)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
actionpack (5.2.0.rc1)
|
21
|
+
actionview (= 5.2.0.rc1)
|
22
|
+
activesupport (= 5.2.0.rc1)
|
23
|
+
rack (~> 2.0)
|
24
|
+
rack-test (>= 0.6.3)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
+
actionview (5.2.0.rc1)
|
28
|
+
activesupport (= 5.2.0.rc1)
|
29
|
+
builder (~> 3.1)
|
30
|
+
erubi (~> 1.4)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
+
activejob (5.2.0.rc1)
|
34
|
+
activesupport (= 5.2.0.rc1)
|
35
|
+
globalid (>= 0.3.6)
|
36
|
+
activemodel (5.2.0.rc1)
|
37
|
+
activesupport (= 5.2.0.rc1)
|
38
|
+
activerecord (5.2.0.rc1)
|
39
|
+
activemodel (= 5.2.0.rc1)
|
40
|
+
activesupport (= 5.2.0.rc1)
|
41
|
+
arel (>= 9.0)
|
42
|
+
activestorage (5.2.0.rc1)
|
43
|
+
actionpack (= 5.2.0.rc1)
|
44
|
+
activerecord (= 5.2.0.rc1)
|
45
|
+
marcel (~> 0.3.1)
|
46
|
+
activesupport (5.2.0.rc1)
|
47
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
48
|
+
i18n (~> 0.7)
|
49
|
+
minitest (~> 5.1)
|
50
|
+
tzinfo (~> 1.1)
|
51
|
+
appraisal (2.2.0)
|
52
|
+
bundler
|
53
|
+
rake
|
54
|
+
thor (>= 0.14.0)
|
55
|
+
arel (9.0.0)
|
56
|
+
builder (3.2.3)
|
57
|
+
byebug (10.0.0)
|
58
|
+
coderay (1.1.2)
|
59
|
+
concurrent-ruby (1.0.5)
|
60
|
+
crass (1.0.3)
|
61
|
+
diff-lcs (1.3)
|
62
|
+
docile (1.1.5)
|
63
|
+
erubi (1.7.0)
|
64
|
+
ffi (1.9.21)
|
65
|
+
formatador (0.2.5)
|
66
|
+
globalid (0.4.1)
|
67
|
+
activesupport (>= 4.2.0)
|
68
|
+
guard (2.14.2)
|
69
|
+
formatador (>= 0.2.4)
|
70
|
+
listen (>= 2.7, < 4.0)
|
71
|
+
lumberjack (>= 1.0.12, < 2.0)
|
72
|
+
nenv (~> 0.1)
|
73
|
+
notiffany (~> 0.0)
|
74
|
+
pry (>= 0.9.12)
|
75
|
+
shellany (~> 0.0)
|
76
|
+
thor (>= 0.18.1)
|
77
|
+
guard-compat (1.2.1)
|
78
|
+
guard-rspec (4.7.3)
|
79
|
+
guard (~> 2.1)
|
80
|
+
guard-compat (~> 1.1)
|
81
|
+
rspec (>= 2.99.0, < 4.0)
|
82
|
+
i18n (0.9.5)
|
83
|
+
concurrent-ruby (~> 1.0)
|
84
|
+
json (2.1.0)
|
85
|
+
listen (3.1.5)
|
86
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
87
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
88
|
+
ruby_dep (~> 1.2)
|
89
|
+
loofah (2.2.0)
|
90
|
+
crass (~> 1.0.2)
|
91
|
+
nokogiri (>= 1.5.9)
|
92
|
+
lumberjack (1.0.12)
|
93
|
+
mail (2.7.0)
|
94
|
+
mini_mime (>= 0.1.1)
|
95
|
+
marcel (0.3.1)
|
96
|
+
mimemagic (~> 0.3.2)
|
97
|
+
metaclass (0.0.4)
|
98
|
+
method_source (0.9.0)
|
99
|
+
mimemagic (0.3.2)
|
100
|
+
mini_mime (1.0.0)
|
101
|
+
mini_portile2 (2.3.0)
|
102
|
+
minitest (5.11.3)
|
103
|
+
minitest-rg (5.2.0)
|
104
|
+
minitest (~> 5.0)
|
105
|
+
mocha (1.3.0)
|
106
|
+
metaclass (~> 0.0.1)
|
107
|
+
mysql2 (0.4.10)
|
108
|
+
nenv (0.3.0)
|
109
|
+
nio4r (2.2.0)
|
110
|
+
nokogiri (1.8.2)
|
111
|
+
mini_portile2 (~> 2.3.0)
|
112
|
+
notiffany (0.1.1)
|
113
|
+
nenv (~> 0.1)
|
114
|
+
shellany (~> 0.0)
|
115
|
+
pry (0.11.3)
|
116
|
+
coderay (~> 1.1.0)
|
117
|
+
method_source (~> 0.9.0)
|
118
|
+
rack (2.0.4)
|
119
|
+
rack-test (0.8.2)
|
120
|
+
rack (>= 1.0, < 3)
|
121
|
+
rails (5.2.0.rc1)
|
122
|
+
actioncable (= 5.2.0.rc1)
|
123
|
+
actionmailer (= 5.2.0.rc1)
|
124
|
+
actionpack (= 5.2.0.rc1)
|
125
|
+
actionview (= 5.2.0.rc1)
|
126
|
+
activejob (= 5.2.0.rc1)
|
127
|
+
activemodel (= 5.2.0.rc1)
|
128
|
+
activerecord (= 5.2.0.rc1)
|
129
|
+
activestorage (= 5.2.0.rc1)
|
130
|
+
activesupport (= 5.2.0.rc1)
|
131
|
+
bundler (>= 1.3.0)
|
132
|
+
railties (= 5.2.0.rc1)
|
133
|
+
sprockets-rails (>= 2.0.0)
|
134
|
+
rails-dom-testing (2.0.3)
|
135
|
+
activesupport (>= 4.2.0)
|
136
|
+
nokogiri (>= 1.6)
|
137
|
+
rails-html-sanitizer (1.0.3)
|
138
|
+
loofah (~> 2.0)
|
139
|
+
railties (5.2.0.rc1)
|
140
|
+
actionpack (= 5.2.0.rc1)
|
141
|
+
activesupport (= 5.2.0.rc1)
|
142
|
+
method_source
|
143
|
+
rake (>= 0.8.7)
|
144
|
+
thor (>= 0.18.1, < 2.0)
|
145
|
+
rake (12.3.0)
|
146
|
+
rb-fsevent (0.10.2)
|
147
|
+
rb-inotify (0.9.10)
|
148
|
+
ffi (>= 0.5.0, < 2)
|
149
|
+
rspec (3.7.0)
|
150
|
+
rspec-core (~> 3.7.0)
|
151
|
+
rspec-expectations (~> 3.7.0)
|
152
|
+
rspec-mocks (~> 3.7.0)
|
153
|
+
rspec-core (3.7.1)
|
154
|
+
rspec-support (~> 3.7.0)
|
155
|
+
rspec-expectations (3.7.0)
|
156
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
157
|
+
rspec-support (~> 3.7.0)
|
158
|
+
rspec-mocks (3.7.0)
|
159
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
160
|
+
rspec-support (~> 3.7.0)
|
161
|
+
rspec-support (3.7.1)
|
162
|
+
ruby_dep (1.5.0)
|
163
|
+
shellany (0.0.1)
|
164
|
+
simplecov (0.15.1)
|
165
|
+
docile (~> 1.1.0)
|
166
|
+
json (>= 1.8, < 3)
|
167
|
+
simplecov-html (~> 0.10.0)
|
168
|
+
simplecov-html (0.10.2)
|
169
|
+
sprockets (3.7.1)
|
170
|
+
concurrent-ruby (~> 1.0)
|
171
|
+
rack (> 1, < 3)
|
172
|
+
sprockets-rails (3.2.1)
|
173
|
+
actionpack (>= 4.0)
|
174
|
+
activesupport (>= 4.0)
|
175
|
+
sprockets (>= 3.0.0)
|
176
|
+
sqlite3 (1.3.13)
|
177
|
+
thor (0.20.0)
|
178
|
+
thread_safe (0.3.6)
|
179
|
+
tzinfo (1.2.5)
|
180
|
+
thread_safe (~> 0.1)
|
181
|
+
websocket-driver (0.7.0)
|
182
|
+
websocket-extensions (>= 0.1.0)
|
183
|
+
websocket-extensions (0.1.3)
|
184
|
+
|
185
|
+
PLATFORMS
|
186
|
+
ruby
|
187
|
+
|
188
|
+
DEPENDENCIES
|
189
|
+
appraisal
|
190
|
+
byebug
|
191
|
+
guard
|
192
|
+
guard-rspec
|
193
|
+
minitest-rg
|
194
|
+
mocha
|
195
|
+
mysql2
|
196
|
+
nondestructive_migrations!
|
197
|
+
rails (= 5.2.0.rc1)
|
198
|
+
rake
|
199
|
+
simplecov
|
200
|
+
sqlite3
|
201
|
+
|
202
|
+
BUNDLED WITH
|
203
|
+
1.16.1
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal"
|
6
|
+
gem "guard"
|
7
|
+
gem "guard-rspec"
|
8
|
+
gem "rake"
|
9
|
+
gem "byebug", platform: :mri_21
|
10
|
+
gem "sqlite3"
|
11
|
+
gem "mysql2"
|
12
|
+
gem "mocha"
|
13
|
+
gem "rails", "6.0.0"
|
14
|
+
gem "minitest-rg"
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem "simplecov", require: false
|
18
|
+
end
|
19
|
+
|
20
|
+
gemspec path: "../"
|
@@ -4,6 +4,21 @@ require 'active_record/base'
|
|
4
4
|
|
5
5
|
module ActiveRecord
|
6
6
|
class DataMigration < ActiveRecord::Base
|
7
|
+
def initialize(migrations)
|
8
|
+
|
9
|
+
@migration_struct = migrations
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def up
|
14
|
+
Migrator.new(:up, @migration_struct).migrate
|
15
|
+
end
|
16
|
+
|
17
|
+
def down
|
18
|
+
Migrator.new(:down, @migration_struct).migrate
|
19
|
+
end
|
20
|
+
|
21
|
+
|
7
22
|
class << self
|
8
23
|
def primary_key
|
9
24
|
nil
|
@@ -49,4 +64,4 @@ module ActiveRecord
|
|
49
64
|
super.to_i
|
50
65
|
end
|
51
66
|
end
|
52
|
-
end
|
67
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "active_record/database_configurations"
|
5
|
+
|
6
|
+
module ActiveRecord
|
7
|
+
module Tasks # :nodoc:
|
8
|
+
class DatabaseNotSupported < StandardError; end # :nodoc:
|
9
|
+
|
10
|
+
|
11
|
+
module DataTasks
|
12
|
+
##
|
13
|
+
# :singleton-method:
|
14
|
+
# Extra flags passed to database CLI tool (mysqldump/pg_dump) when calling db:schema:dump
|
15
|
+
# It can be used as a string/array (the typical case) or a hash (when you use multiple adapters)
|
16
|
+
# Example:
|
17
|
+
# ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = {
|
18
|
+
# mysql2: ['--no-defaults', '--skip-add-drop-table'],
|
19
|
+
# postgres: '--no-tablespaces'
|
20
|
+
# }
|
21
|
+
mattr_accessor :structure_dump_flags, instance_accessor: false
|
22
|
+
|
23
|
+
##
|
24
|
+
# :singleton-method:
|
25
|
+
# Extra flags passed to database CLI tool when calling db:schema:load
|
26
|
+
# It can be used as a string/array (the typical case) or a hash (when you use multiple adapters)
|
27
|
+
mattr_accessor :structure_load_flags, instance_accessor: false
|
28
|
+
|
29
|
+
extend self
|
30
|
+
|
31
|
+
attr_writer :data_dir, :migrations_paths, :fixtures_path, :root, :env, :seed_loader
|
32
|
+
attr_accessor :database_configuration
|
33
|
+
|
34
|
+
|
35
|
+
def self.data_migrations_table_name
|
36
|
+
"data_migrations"
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_protected_environments!(environment = env)
|
40
|
+
return if ENV["DISABLE_DATABASE_ENVIRONMENT_CHECK"]
|
41
|
+
|
42
|
+
configs_for(env_name: environment).each do |db_config|
|
43
|
+
check_current_protected_environment!(db_config)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def data_dir
|
48
|
+
@data_dir ||= Rails.application.config.paths["data"].first
|
49
|
+
end
|
50
|
+
|
51
|
+
def migrations_paths
|
52
|
+
@migrations_paths ||= Rails.application.paths["data/migrate"].to_a
|
53
|
+
end
|
54
|
+
|
55
|
+
def parse_migration_filename(filename)
|
56
|
+
File.basename(filename).scan(Migration::MigrationFilenameRegexp).first
|
57
|
+
end
|
58
|
+
|
59
|
+
def migration_files
|
60
|
+
paths = Array(Rails.root.join('db', 'data_migrate'))
|
61
|
+
Dir[*paths.flat_map { |path| "#{path}/**/[0-9]*_*.rb" }]
|
62
|
+
end
|
63
|
+
|
64
|
+
def migrate(version = nil)
|
65
|
+
# get all data migrations in data/migrations
|
66
|
+
# get list of data migrations in database
|
67
|
+
already_done = ActiveRecord::Base.connection.execute("SELECT version FROM data_migrations").map { |record| record['version'].to_i }
|
68
|
+
|
69
|
+
data_migrations = migration_files.map do |file|
|
70
|
+
version, name, scope = parse_migration_filename(file)
|
71
|
+
raise IllegalMigrationNameError.new(file) unless version
|
72
|
+
version = version.to_i
|
73
|
+
name = name.camelize
|
74
|
+
|
75
|
+
MigrationProxy.new(name, version, file, scope)
|
76
|
+
end
|
77
|
+
data_migrations.reject! do |mig|
|
78
|
+
already_done.include?(mig.version)
|
79
|
+
end
|
80
|
+
data_migrations.each do |migration|
|
81
|
+
require migration.filename
|
82
|
+
(eval(migration.name).new).migrate(:up)
|
83
|
+
|
84
|
+
# push the migration into the database
|
85
|
+
ActiveRecord::Base.connection.execute("INSERT INTO data_migrations (version) VALUES (#{migration.version})")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|