strong_migrations 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0dd3cbacfcf395cdb4ae90cb70d0da70d6411c18
4
- data.tar.gz: 4e9d3a96ee6e57347b448b7f8bd3c7a4a412b0d5
3
+ metadata.gz: d1d122ea065266614d32562e0692da6e53a44113
4
+ data.tar.gz: bffe96798471bf21ab7edb47a81ff4b97891b707
5
5
  SHA512:
6
- metadata.gz: fb8c4bc25cdea84f541199bf56cfdf27d64d8667e3c740729c06a1fdd3de2116c6b8d0ed794b8dc8a67486a7b84262c78f1a4dd428bf5a67518d00f2e9efadae
7
- data.tar.gz: 5e3eef7979383a2dd249ddbfd15c0e7fca2caaad288b69acb10ed1f4cec3ad6d8155bb004dc1daba35b36dcc2a08abc99304dad0a7112327635b802b7c927775
6
+ metadata.gz: 28c244787f1be158f9efa4f3151a93247b1e231b3e2613d03ce5b324b00649ea7118529af59a14a9643f923ae7529435557ab5e97ffeedd8a0b7f51b83297912
7
+ data.tar.gz: 88d883bd199c79f143c73cfd54b1a921fbe24549b82c847793d0ea8a10544d46b8c699a1d6895d4d1ff3a1b5440bf6c61b380c2e8b119d975ee2868e07212b4c
@@ -1,3 +1,8 @@
1
+ ## 0.2.2
2
+
3
+ - Friendlier output
4
+ - Better method of hooking into ActiveRecord
5
+
1
6
  ## 0.2.1
2
7
 
3
8
  - Recommend `disable_ddl_transaction!` over `commit_db_transaction`
data/README.md CHANGED
@@ -24,7 +24,7 @@ Strong Migrations detects potentially dangerous operations in migrations, preven
24
24
  \ \ /\ / / \ | | | | | |
25
25
  \ \/ \/ / /\ \ | | | | | |
26
26
  \ /\ / ____ \ _| |_ | | |_|
27
- \/ \/_/ \_\_____| |_| (_)
27
+ \/ \/_/ \_\_____| |_| (_) #strong_migrations
28
28
 
29
29
  ActiveRecord caches attributes which causes problems
30
30
  when removing columns. Be sure to ignore the column:
@@ -286,3 +286,12 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
286
286
  - Fix bugs and [submit pull requests](https://github.com/ankane/strong_migrations/pulls)
287
287
  - Write, clarify, or fix documentation
288
288
  - Suggest or add new features
289
+
290
+ To get started with development and testing:
291
+
292
+ ```sh
293
+ git clone https://github.com/ankane/strong_migrations.git
294
+ cd strong_migrations
295
+ bundle install
296
+ bundle exec rake test
297
+ ```
@@ -1,5 +1,6 @@
1
- require "active_record"
1
+ require "active_support"
2
2
  require "strong_migrations/version"
3
+ require "strong_migrations/database_tasks"
3
4
  require "strong_migrations/unsafe_migration"
4
5
  require "strong_migrations/migration"
5
6
  require "strong_migrations/railtie" if defined?(Rails)
@@ -53,9 +54,7 @@ If you really have to:
53
54
  5. Stop writing to the old column
54
55
  6. Drop the old column",
55
56
 
56
- remove_column:
57
- if ActiveRecord::VERSION::MAJOR >= 5
58
- "ActiveRecord caches attributes which causes problems
57
+ remove_column: "ActiveRecord caches attributes which causes problems
59
58
  when removing columns. Be sure to ignore the column:
60
59
 
61
60
  class User < ApplicationRecord
@@ -64,21 +63,7 @@ end
64
63
 
65
64
  Once that's deployed, wrap this step in a safety_assured { ... } block.
66
65
 
67
- More info: https://github.com/ankane/strong_migrations#removing-a-column"
68
- else
69
- "ActiveRecord caches attributes which causes problems
70
- when removing columns. Be sure to ignore the column:
71
-
72
- class User < ActiveRecord::Base
73
- def self.columns
74
- super.reject { |c| c.name == \"some_column\" }
75
- end
76
- end
77
-
78
- Once that's deployed, wrap this step in a safety_assured { ... } block.
79
-
80
- More info: https://github.com/ankane/strong_migrations#removing-a-column"
81
- end,
66
+ More info: https://github.com/ankane/strong_migrations#removing-a-column",
82
67
 
83
68
  rename_column:
84
69
  "If you really have to:
@@ -141,4 +126,25 @@ you're doing is safe before proceeding, then wrap it in a safety_assured { ... }
141
126
  }
142
127
  end
143
128
 
144
- ActiveRecord::Migration.send(:prepend, StrongMigrations::Migration)
129
+ ActiveSupport.on_load(:active_record) do
130
+ ActiveRecord::Migration.prepend(StrongMigrations::Migration)
131
+
132
+ if ActiveRecord::VERSION::MAJOR < 5
133
+ StrongMigrations.error_messages[:remove_column] = "ActiveRecord caches attributes which causes problems
134
+ when removing columns. Be sure to ignore the column:
135
+
136
+ class User < ActiveRecord::Base
137
+ def self.columns
138
+ super.reject { |c| c.name == \"some_column\" }
139
+ end
140
+ end
141
+
142
+ Once that's deployed, wrap this step in a safety_assured { ... } block.
143
+
144
+ More info: https://github.com/ankane/strong_migrations#removing-a-column"
145
+ end
146
+
147
+ if defined?(ActiveRecord::Tasks::DatabaseTasks)
148
+ ActiveRecord::Tasks::DatabaseTasks.singleton_class.prepend(StrongMigrations::DatabaseTasks)
149
+ end
150
+ end
@@ -0,0 +1,28 @@
1
+ module StrongMigrations
2
+ module DatabaseTasks
3
+ def migrate
4
+ super
5
+ rescue => e
6
+ if e.cause.is_a?(StrongMigrations::UnsafeMigration)
7
+ # strip cause and clean backtrace
8
+ def e.cause
9
+ nil
10
+ end
11
+
12
+ def e.message
13
+ super.sub("\n\n\n", "\n\n") + "\n"
14
+ end
15
+
16
+ unless Rake.application.options.trace
17
+ def e.backtrace
18
+ bc = ActiveSupport::BacktraceCleaner.new
19
+ bc.add_silencer { |line| line =~ /strong_migrations/ }
20
+ bc.clean(super)
21
+ end
22
+ end
23
+ end
24
+
25
+ raise e
26
+ end
27
+ end
28
+ end
@@ -102,7 +102,7 @@ module StrongMigrations
102
102
  \ \ /\ / / \ | | | | | |
103
103
  \ \/ \/ / /\ \ | | | | | |
104
104
  \ /\ / ____ \ _| |_ | | |_|
105
- \/ \/_/ \_\_____| |_| (_)
105
+ \/ \/_/ \_\_____| |_| (_) #strong_migrations
106
106
 
107
107
  '
108
108
  message = StrongMigrations.error_messages[message_key] || "Missing message"
@@ -1,3 +1,3 @@
1
1
  module StrongMigrations
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
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.2.1
4
+ version: 0.2.2
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: 2018-02-08 00:00:00.000000000 Z
13
+ date: 2018-02-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -98,6 +98,7 @@ files:
98
98
  - README.md
99
99
  - Rakefile
100
100
  - lib/strong_migrations.rb
101
+ - lib/strong_migrations/database_tasks.rb
101
102
  - lib/strong_migrations/migration.rb
102
103
  - lib/strong_migrations/railtie.rb
103
104
  - lib/strong_migrations/unsafe_migration.rb