strong_migrations 0.1.0 → 0.1.1
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 +6 -0
- data/README.md +27 -22
- data/lib/strong_migrations/migration.rb +3 -7
- data/lib/strong_migrations/version.rb +1 -1
- data/strong_migrations.gemspec +2 -2
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 802c5c2d23094377d345af4b5024f7b59234c57d
|
4
|
+
data.tar.gz: 5c6d8799de8f254ce8cad115f348a4f36c81b4d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26e985a319fb114d949a22346f276d4fc4102f370416d3a96c8adbd65192b0af8289d06e30666f54562c4638803711c6794c1abaf90273579cbab3d9a0ab6392
|
7
|
+
data.tar.gz: 6c5f3aee2424a5bf1e87373c18b90f8eb71518316b817dd8b7faec715b0895065fa066c653730558ecee1a0f54db3127a6733f6568a734b5701b5da8c106b0c7
|
data/.travis.yml
CHANGED
@@ -9,7 +9,13 @@ gemfile:
|
|
9
9
|
script: bundle exec rake test
|
10
10
|
before_script:
|
11
11
|
- psql -c 'create database strong_migrations_test;' -U postgres
|
12
|
+
- mysql -e 'create database strong_migrations_test;'
|
12
13
|
notifications:
|
13
14
|
email:
|
14
15
|
on_success: never
|
15
16
|
on_failure: change
|
17
|
+
matrix:
|
18
|
+
include:
|
19
|
+
- gemfile: test/gemfiles/mysql2.gemfile
|
20
|
+
env: ADAPTER=mysql2
|
21
|
+
rvm: 2.2
|
data/README.md
CHANGED
@@ -14,13 +14,13 @@ gem 'strong_migrations'
|
|
14
14
|
|
15
15
|
## Dangerous Operations
|
16
16
|
|
17
|
-
- adding
|
18
|
-
- adding a column with a non-null default value
|
17
|
+
- adding a column with a non-null default value to an existing table
|
19
18
|
- changing the type of a column
|
20
19
|
- renaming a table
|
21
20
|
- renaming a column
|
22
21
|
- removing a column
|
23
|
-
- adding
|
22
|
+
- adding an index non-concurrently (Postgres only)
|
23
|
+
- adding a `json` column to an existing table (Postgres only)
|
24
24
|
|
25
25
|
For more info, check out:
|
26
26
|
|
@@ -29,19 +29,6 @@ For more info, check out:
|
|
29
29
|
|
30
30
|
## The Zero Downtime Way
|
31
31
|
|
32
|
-
### Adding an index
|
33
|
-
|
34
|
-
Add indexes concurrently.
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
class AddSomeIndexToUsers < ActiveRecord::Migration
|
38
|
-
def change
|
39
|
-
commit_db_transaction
|
40
|
-
add_index :users, :some_index, algorithm: :concurrently
|
41
|
-
end
|
42
|
-
end
|
43
|
-
```
|
44
|
-
|
45
32
|
### Adding a column with a default value
|
46
33
|
|
47
34
|
1. Add the column without a default value
|
@@ -75,8 +62,6 @@ end
|
|
75
62
|
|
76
63
|
### Renaming or changing the type of a column
|
77
64
|
|
78
|
-
There’s no way to do this without downtime.
|
79
|
-
|
80
65
|
If you really have to:
|
81
66
|
|
82
67
|
1. Create a new column
|
@@ -88,11 +73,18 @@ If you really have to:
|
|
88
73
|
|
89
74
|
### Renaming a table
|
90
75
|
|
91
|
-
|
76
|
+
If you really have to:
|
77
|
+
|
78
|
+
1. Create a new table
|
79
|
+
2. Write to both tables
|
80
|
+
3. Backfill data from the old table to new table
|
81
|
+
4. Move reads from the old table to the new table
|
82
|
+
5. Stop writing to the old table
|
83
|
+
6. Drop the old table
|
92
84
|
|
93
85
|
### Removing a column
|
94
86
|
|
95
|
-
Tell ActiveRecord to
|
87
|
+
Tell ActiveRecord to ignore the column from its cache.
|
96
88
|
|
97
89
|
```ruby
|
98
90
|
class User
|
@@ -104,9 +96,22 @@ end
|
|
104
96
|
|
105
97
|
Once it’s deployed, create a migration to remove the column.
|
106
98
|
|
107
|
-
### Adding
|
99
|
+
### Adding an index (Postgres)
|
100
|
+
|
101
|
+
Add indexes concurrently.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
class AddSomeIndexToUsers < ActiveRecord::Migration
|
105
|
+
def change
|
106
|
+
commit_db_transaction
|
107
|
+
add_index :users, :some_index, algorithm: :concurrently
|
108
|
+
end
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
### Adding a json column (Postgres)
|
108
113
|
|
109
|
-
There’s no equality operator for the `json` column type. Replace all calls to `uniq` with a custom scope.
|
114
|
+
There’s no equality operator for the `json` column type, which causes issues for `SELECT DISTINCT` queries. Replace all calls to `uniq` with a custom scope.
|
110
115
|
|
111
116
|
```ruby
|
112
117
|
scope :uniq_on_id, -> { select("DISTINCT ON (your_table.id) your_table.*") }
|
@@ -23,7 +23,7 @@ module StrongMigrations
|
|
23
23
|
raise_error :rename_column
|
24
24
|
when :add_index
|
25
25
|
options = args[2]
|
26
|
-
|
26
|
+
if %w(PostgreSQL PostGIS).include?(connection.adapter_name) && !(options && options[:algorithm] == :concurrently)
|
27
27
|
raise_error :add_index
|
28
28
|
end
|
29
29
|
when :add_column
|
@@ -83,9 +83,7 @@ end
|
|
83
83
|
|
84
84
|
Once it's deployed, wrap this step in a safety_assured { ... } block."
|
85
85
|
when :rename_column
|
86
|
-
"
|
87
|
-
|
88
|
-
If you really have to:
|
86
|
+
"If you really have to:
|
89
87
|
|
90
88
|
1. Create a new column
|
91
89
|
2. Write to both columns
|
@@ -94,9 +92,7 @@ If you really have to:
|
|
94
92
|
5. Stop writing to the old column
|
95
93
|
6. Drop the old column"
|
96
94
|
when :rename_table
|
97
|
-
"
|
98
|
-
|
99
|
-
If you really have to:
|
95
|
+
"If you really have to:
|
100
96
|
|
101
97
|
1. Create a new table
|
102
98
|
2. Write to both tables
|
data/strong_migrations.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_dependency "activerecord", ">= 3.2.0"
|
21
21
|
|
22
|
-
spec.add_development_dependency "bundler"
|
23
|
-
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "rake"
|
24
24
|
spec.add_development_dependency "minitest"
|
25
25
|
spec.add_development_dependency "pg"
|
26
26
|
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.1.
|
4
|
+
version: 0.1.1
|
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: 2015-11-
|
13
|
+
date: 2015-11-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -30,30 +30,30 @@ dependencies:
|
|
30
30
|
name: bundler
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - "
|
33
|
+
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '
|
35
|
+
version: '0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - "
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rake
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - "
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
49
|
+
version: '0'
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - "
|
54
|
+
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
56
|
+
version: '0'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: minitest
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|