strong_migrations 0.1.3 → 0.1.4

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: bb8e5f835e883f2053abe736e2cf1f86547cb78f
4
- data.tar.gz: d4488980ee75f4297fdc6bf0d22e0595debe0c48
3
+ metadata.gz: f67458180c4e45e4b7b1d20fd0746df2b4a0a46d
4
+ data.tar.gz: 78682176b14aa2aaa4c933631cdfa2add9035780
5
5
  SHA512:
6
- metadata.gz: 57b28bb5f980754035971fc2918d75c24e4778d7ebf8532989f3dc2a17fe5b0447388d8007bd8822713fa0bf901b33b508a3aa89c5dc718d79b78df8d1c76f60
7
- data.tar.gz: 41f2e2e734cf6331cdabc3270d07b890a73ed323a9007e644dfa7c9124451aff656ab77d3a97cc352c8033dfb0fd61a65d6a6720f40f370968a9e8435ceb644d
6
+ metadata.gz: 8855bafda7a3557422117791dc0482dfdc8ab0e9feca9f76f9099f2eee6b8424ec84809d69c09f6e44ef8b4293f2806d7e1b8addd211056577c205c51f6ce6c0
7
+ data.tar.gz: 7aeee47fb045dfa43cc9918b51a151d766827f8588e8d870526fd66a2b2a1c3ff718ecca4ee68fd42fb8f0ade36ddd9e6674306b6be3e25cd840c2c4dd18e6af
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.4
2
+
3
+ - Added alphabetize columns
4
+
1
5
  ## 0.1.3
2
6
 
3
7
  - Disabled dangerous rake tasks in production
data/README.md CHANGED
@@ -135,14 +135,31 @@ class MySafeMigration < ActiveRecord::Migration
135
135
  end
136
136
  ```
137
137
 
138
- ## Production
138
+ ## Dangerous Tasks
139
139
 
140
- Dangerous rake tasks are disabled in production - `db:drop`, `db:reset`, `db:schema:load`, and `db:structure:load`. To get around this, use:
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).
@@ -1,3 +1,3 @@
1
1
  module StrongMigrations
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -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.3
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-12 00:00:00.000000000 Z
13
+ date: 2016-03-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord