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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c10a3713f5640ee7249063d3df7236d263cb5a71
4
- data.tar.gz: df50932fcd76d06f830bafee7a186ac6a5d14c13
3
+ metadata.gz: d3bfd4ef03a42fa57d69e5207d20f9e4f7d453ed
4
+ data.tar.gz: d291ce32c88f47bfb42b1e34013c625cbdf44e8c
5
5
  SHA512:
6
- metadata.gz: 04b1c12a2dd58c459987a2d3c797cfc225500cb87ece9758b779d049fc62600c1a9b041d35b3e87a0d11000ab05517114ab8960a5003063ad59d7004c5707ba6
7
- data.tar.gz: 7ac14054e5d67e60bfb75582c164ba9b3360a4a59f135986a665a7c29da3b39feffb0ee40147f142ab6850cf541f117943499ff0748c11ace7474adde5816185
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.1
3
+ - 2.4.1
4
4
  gemfile:
5
5
  - Gemfile
6
- - test/gemfiles/activerecord32.gemfile
7
- - test/gemfiles/activerecord40.gemfile
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.2
20
+ rvm: 2.4.1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.7
2
+
3
+ - Added check for `force` option with `create_table`
4
+ - Added `auto_analyze` option
5
+
1
6
  ## 0.1.6
2
7
 
3
8
  - Adding an index to a newly created table is now safe
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in strong_migrations.gemspec
4
3
  gemspec
4
+
5
+ gem "activerecord", "~> 5.1.0"
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
- class User
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
@@ -5,6 +5,7 @@ Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
7
  t.test_files = FileList["test/**/*_test.rb"]
8
+ t.warning = false
8
9
  end
9
10
 
10
11
  task default: :test
@@ -32,7 +32,7 @@ module StrongMigrations
32
32
  raise_error :add_index_columns
33
33
  end
34
34
  options = args[2]
35
- if %w(PostgreSQL PostGIS).include?(connection.adapter_name) && !(options && options[:algorithm] == :concurrently) && !@new_tables.to_a.include?(args[0].to_s)
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
- (@new_tables ||= []) << args[0].to_s
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
- super
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 = '
@@ -1,3 +1,3 @@
1
1
  module StrongMigrations
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -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.6
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-03-24 00:00:00.000000000 Z
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.8
126
+ rubygems_version: 2.6.11
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Catch unsafe migrations at dev time