strong_migrations 0.1.8 → 0.1.9
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/CHANGELOG.md +4 -0
- data/README.md +20 -1
- data/lib/strong_migrations/migration.rb +9 -5
- data/lib/strong_migrations/version.rb +1 -1
- data/lib/strong_migrations.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85bce3e28cb77bab6bea2ff5fe300c7e5b7b7b26
|
4
|
+
data.tar.gz: aa648b6c6cb9744cfd9bad3fa0af93544e62d056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0327c5add8b8d83026e1d2044740f115918c3ec588db1c09bf97130354bd812c59ac78ab0f9d2f13cff12c84593e5406b4a05d1fa1a426ed478869adcc7c94ba
|
7
|
+
data.tar.gz: 335feda7ce4b8fd0a55a52ea6272ac413e6bbffe1b308f2db9fc758ff0a0568a0a6a4b0e238dce5490979caee04568a4ab51c81b5a3c26efcc82d8db0d022b2a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -52,7 +52,10 @@ class AddSomeColumnToUsers < ActiveRecord::Migration
|
|
52
52
|
# 2
|
53
53
|
commit_db_transaction
|
54
54
|
|
55
|
-
# 3
|
55
|
+
# 3.a (Rails 5+)
|
56
|
+
User.in_batches.update_all some_column: "default_value"
|
57
|
+
|
58
|
+
# 3.b (Rails < 5)
|
56
59
|
User.find_in_batches do |users|
|
57
60
|
User.where(id: users.map(&:id)).update_all some_column: "default_value"
|
58
61
|
end
|
@@ -142,6 +145,14 @@ class MySafeMigration < ActiveRecord::Migration
|
|
142
145
|
end
|
143
146
|
```
|
144
147
|
|
148
|
+
## Existing Migrations
|
149
|
+
|
150
|
+
To mark migrations as safe that were created before installing this gem, create an initializer with:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
StrongMigrations.start_after = 20170101000000
|
154
|
+
```
|
155
|
+
|
145
156
|
## Dangerous Tasks
|
146
157
|
|
147
158
|
For safety, dangerous rake tasks are disabled in production - `db:drop`, `db:reset`, `db:schema:load`, and `db:structure:load`. To get around this, use:
|
@@ -167,6 +178,14 @@ Columns can flip order in `db/schema.rb` when you have multiple developers. One
|
|
167
178
|
task "db:schema:dump": "strong_migrations:alphabetize_columns"
|
168
179
|
```
|
169
180
|
|
181
|
+
## Analyze Tables (Postgres)
|
182
|
+
|
183
|
+
Analyze tables automatically (to update planner statistics) after an index is added. Create an initializer with:
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
StrongMigrations.auto_analyze = true
|
187
|
+
```
|
188
|
+
|
170
189
|
## Credits
|
171
190
|
|
172
191
|
Thanks to Bob Remeika and David Waller for the [original code](https://github.com/foobarfighter/safe-migrations).
|
@@ -14,7 +14,7 @@ module StrongMigrations
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def method_missing(method, *args, &block)
|
17
|
-
unless @safe || ENV["SAFETY_ASSURED"] || is_a?(ActiveRecord::Schema) || @direction == :down
|
17
|
+
unless @safe || ENV["SAFETY_ASSURED"] || is_a?(ActiveRecord::Schema) || @direction == :down || version_safe?
|
18
18
|
case method
|
19
19
|
when :remove_column
|
20
20
|
raise_error :remove_column
|
@@ -31,14 +31,14 @@ module StrongMigrations
|
|
31
31
|
if columns.is_a?(Array) && columns.size > 3
|
32
32
|
raise_error :add_index_columns
|
33
33
|
end
|
34
|
-
options = args[2]
|
35
|
-
if postgresql? &&
|
34
|
+
options = args[2] || {}
|
35
|
+
if postgresql? && options[:algorithm] != :concurrently && !@new_tables.to_a.include?(args[0].to_s)
|
36
36
|
raise_error :add_index
|
37
37
|
end
|
38
38
|
when :add_column
|
39
39
|
type = args[2]
|
40
|
-
options = args[3]
|
41
|
-
raise_error :add_column_default
|
40
|
+
options = args[3] || {}
|
41
|
+
raise_error :add_column_default unless options[:default].nil?
|
42
42
|
raise_error :add_column_json if type.to_s == "json"
|
43
43
|
when :change_column
|
44
44
|
raise_error :change_column
|
@@ -75,6 +75,10 @@ module StrongMigrations
|
|
75
75
|
%w(PostgreSQL PostGIS).include?(connection.adapter_name)
|
76
76
|
end
|
77
77
|
|
78
|
+
def version_safe?
|
79
|
+
version && version <= StrongMigrations.start_after
|
80
|
+
end
|
81
|
+
|
78
82
|
def raise_error(message_key)
|
79
83
|
message =
|
80
84
|
case message_key
|
data/lib/strong_migrations.rb
CHANGED
@@ -6,9 +6,10 @@ require "strong_migrations/railtie" if defined?(Rails)
|
|
6
6
|
|
7
7
|
module StrongMigrations
|
8
8
|
class << self
|
9
|
-
attr_accessor :auto_analyze
|
9
|
+
attr_accessor :auto_analyze, :start_after
|
10
10
|
end
|
11
11
|
self.auto_analyze = false
|
12
|
+
self.start_after = 0
|
12
13
|
end
|
13
14
|
|
14
15
|
ActiveRecord::Migration.send(:prepend, StrongMigrations::Migration)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strong_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Remeika
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-06-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|