strong_migrations 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +19 -2
- data/lib/strong_migrations/version.rb +1 -1
- data/lib/tasks/strong_migrations.rake +19 -0
- 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: f67458180c4e45e4b7b1d20fd0746df2b4a0a46d
|
4
|
+
data.tar.gz: 78682176b14aa2aaa4c933631cdfa2add9035780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8855bafda7a3557422117791dc0482dfdc8ab0e9feca9f76f9099f2eee6b8424ec84809d69c09f6e44ef8b4293f2806d7e1b8addd211056577c205c51f6ce6c0
|
7
|
+
data.tar.gz: 7aeee47fb045dfa43cc9918b51a151d766827f8588e8d870526fd66a2b2a1c3ff718ecca4ee68fd42fb8f0ade36ddd9e6674306b6be3e25cd840c2c4dd18e6af
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -135,14 +135,31 @@ class MySafeMigration < ActiveRecord::Migration
|
|
135
135
|
end
|
136
136
|
```
|
137
137
|
|
138
|
-
##
|
138
|
+
## Dangerous Tasks
|
139
139
|
|
140
|
-
|
140
|
+
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:
|
141
141
|
|
142
142
|
```sh
|
143
143
|
SAFETY_ASSURED=1 rake db:drop
|
144
144
|
```
|
145
145
|
|
146
|
+
## Faster Migrations
|
147
|
+
|
148
|
+
Only dump the schema when adding a new migration. If you use Git, create an initializer with:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
ActiveRecord::Base.dump_schema_after_migration = Rails.env.development? &&
|
152
|
+
!`git status db/migrate/`.include?("working directory clean")
|
153
|
+
```
|
154
|
+
|
155
|
+
## Schema Sanity
|
156
|
+
|
157
|
+
Columns can flip order in `db/schema.rb` when you have multiple developers. One way to prevent this is to [alphabetize them](https://www.pgrs.net/2008/03/13/alphabetize-schema-rb-columns/). Add to the end of your `Rakefile`:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
task "db:schema:dump": "strong_migrations:alphabetize_columns"
|
161
|
+
```
|
162
|
+
|
146
163
|
## Credits
|
147
164
|
|
148
165
|
Thanks to Bob Remeika and David Waller for the [original code](https://github.com/foobarfighter/safe-migrations).
|
@@ -4,6 +4,25 @@ namespace :strong_migrations do
|
|
4
4
|
task safety_assured: :environment do
|
5
5
|
raise "Set SAFETY_ASSURED=1 to run this task in production" if Rails.env.production? && !ENV["SAFETY_ASSURED"]
|
6
6
|
end
|
7
|
+
|
8
|
+
# https://www.pgrs.net/2008/03/13/alphabetize-schema-rb-columns/
|
9
|
+
task :alphabetize_columns do
|
10
|
+
$stderr.puts "Dumping schema"
|
11
|
+
ActiveRecord::Base.logger.level = Logger::INFO
|
12
|
+
|
13
|
+
class << ActiveRecord::Base.connection
|
14
|
+
alias_method :old_columns, :columns unless instance_methods.include?("old_columns")
|
15
|
+
alias_method :old_extensions, :extensions unless instance_methods.include?("old_extensions")
|
16
|
+
|
17
|
+
def columns(*args)
|
18
|
+
old_columns(*args).sort_by(&:name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def extensions(*args)
|
22
|
+
old_extensions(*args).sort
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
7
26
|
end
|
8
27
|
|
9
28
|
["db:drop", "db:reset", "db:schema:load", "db:structure:load"].each do |t|
|
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.4
|
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: 2016-03-
|
13
|
+
date: 2016-03-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|