handcuffs 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +0 -0
- data/README.md +7 -7
- data/lib/handcuffs/errors.rb +11 -1
- data/lib/handcuffs/phase_filter.rb +15 -3
- data/lib/handcuffs/version.rb +1 -1
- metadata +19 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fad65d31075a71be8ae84c5d27c6f92c7b0cef64
|
4
|
+
data.tar.gz: 3090970bf6d57882a3cd7573729c4a84a9e44ed4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba80cc8d9c509ef9e4b43f72bc745e2969f318e748927dc1927021f399c0d31963f9ebf2135a065d2836adb9385a8866d5bcbe832913f997e5068972ca90b289
|
7
|
+
data.tar.gz: 632e11dfd992d24f71b8464e9a1f6a60b181351c88ea474ad18e8744a4516ecf7e268bdf2e7eb6f7407fc4e7824ff32d023c3053ffddab46105a4d82f6eff64b
|
data/.ruby-version
ADDED
File without changes
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ To configure, first create a handcuff initializer and define a configuration
|
|
11
11
|
# config/initializers/handcuffs.rb
|
12
12
|
|
13
13
|
Handcuffs.configure do |config|
|
14
|
-
config.phases = [:
|
14
|
+
config.phases = [:pre_restart, :post_restart]
|
15
15
|
end
|
16
16
|
```
|
17
17
|
|
@@ -22,7 +22,7 @@ Then call `phase` from inside your migrations
|
|
22
22
|
|
23
23
|
class AddOnSaleColumn < ActiveRecord::Migration
|
24
24
|
|
25
|
-
phase :
|
25
|
+
phase :pre_restart
|
26
26
|
|
27
27
|
def up
|
28
28
|
add_column :products, :on_sale, :boolean
|
@@ -40,7 +40,7 @@ end
|
|
40
40
|
|
41
41
|
class AddOnSaleIndex < ActiveRecord::Migration
|
42
42
|
|
43
|
-
phase :
|
43
|
+
phase :post_restart
|
44
44
|
|
45
45
|
def up
|
46
46
|
add_index :products, :on_sale, algorithm: :concurrently
|
@@ -55,11 +55,11 @@ end
|
|
55
55
|
|
56
56
|
You can then run your migrations in phases using
|
57
57
|
```bash
|
58
|
-
rake handcuffs:migrate[
|
58
|
+
rake handcuffs:migrate[pre_restart]
|
59
59
|
```
|
60
60
|
or
|
61
61
|
```bash
|
62
|
-
rake handcuffs:migrate[
|
62
|
+
rake handcuffs:migrate[post_restart]
|
63
63
|
```
|
64
64
|
|
65
65
|
You can run all migrations using
|
@@ -77,8 +77,8 @@ error, you can define a default phase for migrations that don't define one.
|
|
77
77
|
# config/initializers/handcuffs.rb
|
78
78
|
|
79
79
|
Handcuffs.configure do |config|
|
80
|
-
config.phases = [:
|
81
|
-
config.default_phase = :
|
80
|
+
config.phases = [:pre_restart, :post_restart]
|
81
|
+
config.default_phase = :pre_restart
|
82
82
|
end
|
83
83
|
```
|
84
84
|
|
data/lib/handcuffs/errors.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
def initialize(task)
|
6
6
|
msg = <<-MESSAGE
|
7
7
|
rake #{task} requires a phase argument.
|
8
|
-
For example: #{task}[
|
8
|
+
For example: #{task}[pre_restart]
|
9
9
|
MESSAGE
|
10
10
|
super(msg)
|
11
11
|
end
|
@@ -31,6 +31,16 @@
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
class HandcuffsPhaseUndeclaredError < HandcuffsError
|
35
|
+
def initialize(found_phases, allowed_phases)
|
36
|
+
msg = <<-MESSAGE
|
37
|
+
found declarations for #{found_phases.to_sentence}
|
38
|
+
but only #{allowed_phases.to_sentence} are allowed
|
39
|
+
MESSAGE
|
40
|
+
super msg
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
34
44
|
class HandcuffsPhaseOutOfOrderError < HandcuffsError
|
35
45
|
def initialize(not_run_phase, attempted_phase)
|
36
46
|
msg = <<-MESSAGE
|
@@ -10,6 +10,7 @@ class Handcuffs::PhaseFilter
|
|
10
10
|
def filter(migration_proxies)
|
11
11
|
migration_hashes = proxies_with_migrations(migration_proxies)
|
12
12
|
check_for_undefined_phases!(migration_hashes)
|
13
|
+
check_for_undeclared_phases!(migration_hashes)
|
13
14
|
by_phase = migration_hashes.lazy.group_by { |mh| phase(mh[:migration]) }
|
14
15
|
defined_phases = Handcuffs.config.phases
|
15
16
|
if(attempted_phase == :all)
|
@@ -49,9 +50,9 @@ class Handcuffs::PhaseFilter
|
|
49
50
|
|
50
51
|
def check_order_down!(by_phase, defined_phases)
|
51
52
|
#There's no way to do this without some super hackery. If we run rake
|
52
|
-
#handcuffs::rollback[:
|
53
|
-
#in a
|
54
|
-
#last
|
53
|
+
#handcuffs::rollback[:post_restart] and the top of the list (in desc order)
|
54
|
+
#in a pre_restart, we don't know if that was run before or after the
|
55
|
+
#last post_restart because we can't count on the versions to give us the
|
55
56
|
#execution order. Without storing the execution order in another table,
|
56
57
|
#there's no way to implement this
|
57
58
|
end
|
@@ -74,6 +75,17 @@ class Handcuffs::PhaseFilter
|
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
78
|
+
def check_for_undeclared_phases!(migration_hashes)
|
79
|
+
unknown_phases = migration_hashes
|
80
|
+
.lazy
|
81
|
+
.map { |mh| mh[:migration].handcuffs_phase }
|
82
|
+
.reject(&:nil?)
|
83
|
+
.select { |phase| !phase.in?(Handcuffs.config.phases) }.to_a
|
84
|
+
if (unknown_phases.any?)
|
85
|
+
raise HandcuffsPhaseUndeclaredError.new(unknown_phases, Handcuffs.config.phases)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
77
89
|
def phase(migration)
|
78
90
|
migration.handcuffs_phase || Handcuffs.config.default_phase
|
79
91
|
end
|
data/lib/handcuffs/version.rb
CHANGED
metadata
CHANGED
@@ -1,89 +1,89 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handcuffs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Urani
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pg
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry-byebug
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '4.0'
|
76
|
-
- -
|
76
|
+
- - <
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '5.0'
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
|
-
- -
|
83
|
+
- - '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '4.0'
|
86
|
-
- -
|
86
|
+
- - <
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '5.0'
|
89
89
|
description: Allows you to define a phase on Active Record migrations and provides
|
@@ -95,7 +95,8 @@ executables: []
|
|
95
95
|
extensions: []
|
96
96
|
extra_rdoc_files: []
|
97
97
|
files:
|
98
|
-
-
|
98
|
+
- .gitignore
|
99
|
+
- .ruby-version
|
99
100
|
- CODE_OF_CONDUCT.md
|
100
101
|
- Gemfile
|
101
102
|
- LICENSE.txt
|
@@ -126,17 +127,17 @@ require_paths:
|
|
126
127
|
- lib
|
127
128
|
required_ruby_version: !ruby/object:Gem::Requirement
|
128
129
|
requirements:
|
129
|
-
- -
|
130
|
+
- - '>='
|
130
131
|
- !ruby/object:Gem::Version
|
131
132
|
version: '0'
|
132
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
134
|
requirements:
|
134
|
-
- -
|
135
|
+
- - '>='
|
135
136
|
- !ruby/object:Gem::Version
|
136
137
|
version: '0'
|
137
138
|
requirements: []
|
138
139
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.0.14.1
|
140
141
|
signing_key:
|
141
142
|
specification_version: 4
|
142
143
|
summary: A Ruby gem for running Active Record migrations in phases
|