strong_migrations 0.1.6 → 0.1.7
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/.travis.yml +4 -5
- data/CHANGELOG.md +5 -0
- data/Gemfile +2 -1
- data/README.md +7 -1
- data/Rakefile +1 -0
- data/lib/strong_migrations/migration.rb +36 -3
- data/lib/strong_migrations/version.rb +1 -1
- data/lib/strong_migrations.rb +7 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3bfd4ef03a42fa57d69e5207d20f9e4f7d453ed
|
4
|
+
data.tar.gz: d291ce32c88f47bfb42b1e34013c625cbdf44e8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f10a0f58b62bed953fc0f066bcf032639386ca4db62c1fc0f23c63d849514176e402fc419453d8617232c3b613f907b743ed1b330a4249f6f37c66f634d6af4b
|
7
|
+
data.tar.gz: 64c2d0ab3d3b0bc7cce8a0f7f0bd60f855d1f6e14ee720ce2e1af9a8dd402a72cbc2ecbb6ca99bf0a35b5f85334b4f4cd04daae6057207217e68ab21574c7ea9
|
data/.travis.yml
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
3
|
+
- 2.4.1
|
4
4
|
gemfile:
|
5
5
|
- Gemfile
|
6
|
-
- test/gemfiles/
|
7
|
-
- test/gemfiles/
|
8
|
-
- test/gemfiles/activerecord41.gemfile
|
6
|
+
- test/gemfiles/activerecord50.gemfile
|
7
|
+
- test/gemfiles/activerecord42.gemfile
|
9
8
|
script: bundle exec rake test
|
10
9
|
before_script:
|
11
10
|
- psql -c 'create database strong_migrations_test;' -U postgres
|
@@ -18,4 +17,4 @@ matrix:
|
|
18
17
|
include:
|
19
18
|
- gemfile: test/gemfiles/mysql2.gemfile
|
20
19
|
env: ADAPTER=mysql2
|
21
|
-
rvm: 2.
|
20
|
+
rvm: 2.4.1
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -93,7 +93,13 @@ If you really have to:
|
|
93
93
|
Tell ActiveRecord to ignore the column from its cache.
|
94
94
|
|
95
95
|
```ruby
|
96
|
-
|
96
|
+
# For Rails 5+
|
97
|
+
class User < ActiveRecord::Base
|
98
|
+
self.ignored_columns = %w(some_column)
|
99
|
+
end
|
100
|
+
|
101
|
+
# For Rails < 5
|
102
|
+
class User < ActiveRecord::Base
|
97
103
|
def self.columns
|
98
104
|
super.reject { |c| c.name == "some_column" }
|
99
105
|
end
|
data/Rakefile
CHANGED
@@ -32,7 +32,7 @@ module StrongMigrations
|
|
32
32
|
raise_error :add_index_columns
|
33
33
|
end
|
34
34
|
options = args[2]
|
35
|
-
if
|
35
|
+
if postgresql? && !(options && 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
|
@@ -43,15 +43,36 @@ module StrongMigrations
|
|
43
43
|
when :change_column
|
44
44
|
raise_error :change_column
|
45
45
|
when :create_table
|
46
|
-
|
46
|
+
options = args[1]
|
47
|
+
raise_error :create_table if options[:force]
|
48
|
+
when :add_reference
|
49
|
+
options = args[2] || {}
|
50
|
+
index_value = options.fetch(:index, ActiveRecord::VERSION::MAJOR >= 5 ? true : false)
|
51
|
+
if postgresql? && index_value
|
52
|
+
raise_error :add_reference
|
53
|
+
end
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|
50
|
-
|
57
|
+
if method == :create_table
|
58
|
+
(@new_tables ||= []) << args[0].to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
result = super
|
62
|
+
|
63
|
+
if StrongMigrations.auto_analyze && postgresql? && method == :add_index
|
64
|
+
connection.execute "ANALYZE VERBOSE #{connection.quote_table_name(args[0])}"
|
65
|
+
end
|
66
|
+
|
67
|
+
result
|
51
68
|
end
|
52
69
|
|
53
70
|
private
|
54
71
|
|
72
|
+
def postgresql?
|
73
|
+
%w(PostgreSQL PostGIS).include?(connection.adapter_name)
|
74
|
+
end
|
75
|
+
|
55
76
|
def raise_error(message_key)
|
56
77
|
message =
|
57
78
|
case message_key
|
@@ -111,6 +132,14 @@ Once it's deployed, wrap this step in a safety_assured { ... } block."
|
|
111
132
|
4. Move reads from the old table to the new table
|
112
133
|
5. Stop writing to the old table
|
113
134
|
6. Drop the old table"
|
135
|
+
when :add_reference
|
136
|
+
"Adding a non-concurrent index locks the table. Instead, use:
|
137
|
+
|
138
|
+
def change
|
139
|
+
add_reference :users, :reference, index: false
|
140
|
+
commit_db_transaction
|
141
|
+
add_index :users, :reference_id, algorithm: :concurrently
|
142
|
+
end"
|
114
143
|
when :add_index
|
115
144
|
"Adding a non-concurrent index locks the table. Instead, use:
|
116
145
|
|
@@ -126,6 +155,10 @@ If you're sure this is what you want, wrap it in a safety_assured { ... } block.
|
|
126
155
|
"The strong_migrations gem does not support inspecting what happens inside a
|
127
156
|
change_table block, so cannot help you here. Please make really sure that what
|
128
157
|
you're doing is safe before proceding, then wrap it in a safety_assured { ... } block."
|
158
|
+
when :create_table
|
159
|
+
"The force option will destroy existing tables.
|
160
|
+
If this is intended, drop the existing table first.
|
161
|
+
Otherwise, remove the option."
|
129
162
|
end
|
130
163
|
|
131
164
|
wait_message = '
|
data/lib/strong_migrations.rb
CHANGED
@@ -4,4 +4,11 @@ require "strong_migrations/unsafe_migration"
|
|
4
4
|
require "strong_migrations/migration"
|
5
5
|
require "strong_migrations/railtie" if defined?(Rails)
|
6
6
|
|
7
|
+
module StrongMigrations
|
8
|
+
class << self
|
9
|
+
attr_accessor :auto_analyze
|
10
|
+
end
|
11
|
+
self.auto_analyze = false
|
12
|
+
end
|
13
|
+
|
7
14
|
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.7
|
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-05-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.6.
|
126
|
+
rubygems_version: 2.6.11
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Catch unsafe migrations at dev time
|