ridgepole 0.5.3.beta4 → 0.6.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -50
  3. data/bin/ridgepole +8 -18
  4. data/lib/ridgepole/client.rb +10 -16
  5. data/lib/ridgepole/delta.rb +57 -19
  6. data/lib/ridgepole/diff.rb +45 -14
  7. data/lib/ridgepole/dsl_parser.rb +38 -8
  8. data/lib/ridgepole/execute_expander.rb +0 -29
  9. data/lib/ridgepole/ext/mysql_awesome.rb +1 -5
  10. data/lib/ridgepole/version.rb +1 -1
  11. data/lib/ridgepole.rb +10 -2
  12. data/ridgepole.gemspec +3 -8
  13. data/spec/bigint_pk/bigint_pkspec.rb +2 -2
  14. data/spec/cli/ridgepole_spec.rb +3 -5
  15. data/spec/collation/collation_spec.rb +35 -35
  16. data/spec/diff/diff2_spec.rb +18 -18
  17. data/spec/diff/diff_spec.rb +18 -18
  18. data/spec/dump/dump_class_method_spec.rb +18 -18
  19. data/spec/dump/dump_some_tables_spec.rb +12 -12
  20. data/spec/dump/dump_spec.rb +18 -18
  21. data/spec/dump/dump_without_table_options_spec.rb +6 -6
  22. data/spec/migrate/check_orphan_index_spec.rb +8 -8
  23. data/spec/migrate/migrate_add_column2_spec.rb +15 -15
  24. data/spec/migrate/migrate_add_column_spec.rb +40 -40
  25. data/spec/migrate/migrate_change_column2_spec.rb +5 -5
  26. data/spec/migrate/migrate_change_column3_spec.rb +26 -26
  27. data/spec/migrate/migrate_change_column_float_spec.rb +7 -7
  28. data/spec/migrate/migrate_change_column_spec.rb +42 -42
  29. data/spec/migrate/migrate_change_index2_spec.rb +13 -13
  30. data/spec/migrate/migrate_change_index3_spec.rb +26 -26
  31. data/spec/migrate/migrate_change_index4_spec.rb +28 -28
  32. data/spec/migrate/migrate_change_index_spec.rb +46 -46
  33. data/spec/migrate/migrate_change_table_option_spec.rb +2 -2
  34. data/spec/migrate/migrate_create_index_spec.rb +18 -18
  35. data/spec/migrate/migrate_create_table_spec.rb +18 -18
  36. data/spec/migrate/migrate_create_table_with_options_spec.rb +3 -3
  37. data/spec/migrate/migrate_drop_column_and_index_2_spec.rb +35 -35
  38. data/spec/migrate/migrate_drop_column_and_index_spec.rb +33 -33
  39. data/spec/migrate/migrate_drop_column_spec.rb +36 -36
  40. data/spec/migrate/migrate_drop_index_spec.rb +18 -18
  41. data/spec/migrate/migrate_drop_table_spec.rb +24 -24
  42. data/spec/migrate/migrate_duplicate_index_spec.rb +1 -1
  43. data/spec/migrate/migrate_duplicate_table_spec.rb +2 -2
  44. data/spec/migrate/migrate_empty_spec.rb +18 -18
  45. data/spec/migrate/migrate_execute_spec.rb +58 -49
  46. data/spec/migrate/migrate_merge_mode_spec.rb +38 -38
  47. data/spec/migrate/migrate_noop_spec.rb +40 -40
  48. data/spec/migrate/migrate_rename_column_spec.rb +37 -37
  49. data/spec/migrate/migrate_rename_table_spec.rb +39 -39
  50. data/spec/migrate/migrate_same_default_null_spec.rb +4 -4
  51. data/spec/migrate/migrate_same_spec.rb +18 -18
  52. data/spec/migrate/migrate_script_error_spec.rb +8 -8
  53. data/spec/migrate/migrate_skip_rename_column_spec.rb +36 -36
  54. data/spec/migrate/migrate_skip_rename_table_spec.rb +36 -36
  55. data/spec/migrate/migrate_with_ignore_tables_spec.rb +12 -12
  56. data/spec/migrate/migrate_with_pre_post_query_spec.rb +32 -32
  57. data/spec/migrate/migrate_with_tables_spec.rb +12 -12
  58. data/spec/migrate_0/migrate_change_fk_spec.rb +11 -11
  59. data/spec/migrate_0/migrate_create_fk_spec.rb +29 -30
  60. data/spec/migrate_0/migrate_drop_fk_spec.rb +22 -23
  61. data/spec/spec_helper.rb +24 -2
  62. metadata +10 -89
  63. data/lib/ridgepole/ext/foreign_key.rb +0 -121
  64. data/spec/0_diff/dump_disable_unsigned_spec.rb +0 -75
  65. data/spec/comment/comment_spec.rb +0 -179
  66. data/spec/migrate/migrate_same_default_unsigned_spec.rb +0 -63
  67. data/spec/~pkdump/pkdump_spec.rb +0 -67
@@ -2,13 +2,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
2
2
  context 'when create fk' do
3
3
  let(:actual_dsl) {
4
4
  <<-RUBY
5
- create_table "child", force: true do |t|
6
- t.integer "parent_id", unsigned: true
5
+ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
6
+ t.integer "parent_id", limit: 4#{unsigned_if_enabled}
7
7
  end
8
8
 
9
9
  add_index "child", ["parent_id"], name: "par_ind", using: :btree
10
10
 
11
- create_table "parent", force: true do |t|
11
+ create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
12
12
  end
13
13
  RUBY
14
14
  }
@@ -16,12 +16,12 @@ end
16
16
  let(:expected_dsl) {
17
17
  actual_dsl + (<<-RUBY)
18
18
 
19
- add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
19
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
20
20
  RUBY
21
21
  }
22
22
 
23
23
  before { subject.diff(actual_dsl).migrate }
24
- subject { client(enable_foreigner: true) }
24
+ subject { client }
25
25
 
26
26
  it {
27
27
  delta = subject.diff(expected_dsl)
@@ -32,7 +32,7 @@ add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
32
32
  }
33
33
 
34
34
  it {
35
- delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true, enable_foreigner: true)
35
+ delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true, default_int_limit: 4)
36
36
  expect(delta.differ?).to be_truthy
37
37
  expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
38
38
  remove_foreign_key("child", {:name=>"child_ibfk_1"})
@@ -40,13 +40,11 @@ add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
40
40
  }
41
41
 
42
42
  it {
43
- delta = client(enable_foreigner: true, bulk_change: true).diff(expected_dsl)
43
+ delta = client(bulk_change: true).diff(expected_dsl)
44
44
  expect(delta.differ?).to be_truthy
45
45
  expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
46
46
  expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
47
- change_table("child", {:bulk => true}) do |t|
48
- t.foreign_key("parent", {:name=>"child_ibfk_1", :dependent=>:delete})
49
- end
47
+ add_foreign_key("child", "parent", {:name=>"child_ibfk_1"})
50
48
  RUBY
51
49
  delta.migrate
52
50
  expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
@@ -57,35 +55,36 @@ add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
57
55
  let(:dsl) {
58
56
  <<-RUBY
59
57
  # Define parent before child
60
- create_table "parent", force: true do |t|
58
+ create_table "parent", force: :cascade do |t|
61
59
  end
62
60
 
63
- create_table "child", force: true do |t|
61
+ create_table "child", force: :cascade do |t|
64
62
  t.integer "parent_id", unsigned: true
65
63
  end
66
64
 
67
65
  add_index "child", ["parent_id"], name: "par_ind", using: :btree
68
66
 
69
- add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
67
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
70
68
  RUBY
71
69
  }
72
70
 
73
71
  let(:sorted_dsl) {
74
72
  <<-RUBY
75
- create_table "child", force: true do |t|
76
- t.integer "parent_id", unsigned: true
73
+
74
+ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
75
+ t.integer "parent_id", limit: 4#{unsigned_if_enabled}
77
76
  end
78
77
 
79
78
  add_index "child", ["parent_id"], name: "par_ind", using: :btree
80
79
 
81
- create_table "parent", force: true do |t|
80
+ create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
82
81
  end
83
82
 
84
- add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
83
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
85
84
  RUBY
86
85
  }
87
86
 
88
- subject { client(enable_foreigner: true) }
87
+ subject { client }
89
88
 
90
89
  it {
91
90
  delta = subject.diff(dsl)
@@ -100,22 +99,22 @@ add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
100
99
  let(:dsl) {
101
100
  <<-RUBY
102
101
  # Define parent before child
103
- create_table "parent", force: true do |t|
102
+ create_table "parent", force: :cascade do |t|
104
103
  end
105
104
 
106
- create_table "child", force: true do |t|
105
+ create_table "child", force: :cascade do |t|
107
106
  t.integer "parent_id", unsigned: true
108
107
  end
109
108
 
110
109
  add_index "child", ["parent_id"], name: "par_ind", using: :btree
111
110
 
112
- add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
111
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
113
112
 
114
- add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
113
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
115
114
  RUBY
116
115
  }
117
116
 
118
- subject { client(enable_foreigner: true) }
117
+ subject { client }
119
118
 
120
119
  it {
121
120
  expect {
@@ -128,20 +127,20 @@ add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
128
127
  let(:dsl) {
129
128
  <<-RUBY
130
129
  # Define parent before child
131
- create_table "parent", force: true do |t|
130
+ create_table "parent", force: :cascade do |t|
132
131
  end
133
132
 
134
- create_table "child", force: true do |t|
133
+ create_table "child", force: :cascade do |t|
135
134
  t.integer "parent_id", unsigned: true
136
135
  end
137
136
 
138
137
  add_index "child", ["parent_id"], name: "par_ind", using: :btree
139
138
 
140
- add_foreign_key "child", "parent", dependent: :delete
139
+ add_foreign_key "child", "parent"
141
140
  RUBY
142
141
  }
143
142
 
144
- subject { client(enable_foreigner: true) }
143
+ subject { client }
145
144
 
146
145
  it {
147
146
  expect {
@@ -154,14 +153,14 @@ add_foreign_key "child", "parent", dependent: :delete
154
153
  let(:dsl) {
155
154
  <<-RUBY
156
155
  # Define parent before child
157
- create_table "parent", force: true do |t|
156
+ create_table "parent", force: :cascade do |t|
158
157
  end
159
158
 
160
- add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
159
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
161
160
  RUBY
162
161
  }
163
162
 
164
- subject { client(enable_foreigner: true) }
163
+ subject { client }
165
164
 
166
165
  it {
167
166
  expect {
@@ -2,41 +2,41 @@ describe 'Ridgepole::Client#diff -> migrate' do
2
2
  context 'when drop fk' do
3
3
  let(:actual_dsl) {
4
4
  <<-RUBY
5
- create_table "parent", force: true do |t|
5
+ create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
6
6
  end
7
7
 
8
- create_table "child", force: true do |t|
9
- t.integer "parent_id", unsigned: true
8
+ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
9
+ t.integer "parent_id"#{unsigned_if_enabled}
10
10
  end
11
11
 
12
12
  add_index "child", ["parent_id"], name: "par_ind", using: :btree
13
13
 
14
- add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
14
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
15
15
  RUBY
16
16
  }
17
17
 
18
18
  let(:sorted_actual_dsl) {
19
19
  expected_dsl + (<<-RUBY)
20
20
 
21
- add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
21
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
22
22
  RUBY
23
23
  }
24
24
 
25
25
  let(:expected_dsl) {
26
26
  <<-RUBY
27
- create_table "child", force: true do |t|
28
- t.integer "parent_id", unsigned: true
27
+ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
28
+ t.integer "parent_id", limit: 4#{unsigned_if_enabled}
29
29
  end
30
30
 
31
31
  add_index "child", ["parent_id"], name: "par_ind", using: :btree
32
32
 
33
- create_table "parent", force: true do |t|
33
+ create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
34
34
  end
35
35
  RUBY
36
36
  }
37
37
 
38
38
  before { subject.diff(actual_dsl).migrate }
39
- subject { client(enable_foreigner: true) }
39
+ subject { client }
40
40
 
41
41
  it {
42
42
  delta = subject.diff(expected_dsl)
@@ -47,21 +47,19 @@ end
47
47
  }
48
48
 
49
49
  it {
50
- delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true, enable_foreigner: true)
50
+ delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true, default_int_limit: 4)
51
51
  expect(delta.differ?).to be_truthy
52
52
  expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
53
- add_foreign_key("child", "parent", {:name=>"child_ibfk_1", :dependent=>:delete})
53
+ add_foreign_key("child", "parent", {:name=>"child_ibfk_1"})
54
54
  RUBY
55
55
  }
56
56
 
57
57
  it {
58
- delta = client(enable_foreigner: true, bulk_change: true).diff(expected_dsl)
58
+ delta = client(bulk_change: true).diff(expected_dsl)
59
59
  expect(delta.differ?).to be_truthy
60
60
  expect(subject.dump).to eq sorted_actual_dsl.strip_heredoc.strip
61
61
  expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
62
- change_table("child", {:bulk => true}) do |t|
63
- t.remove_foreign_key({:name=>"child_ibfk_1"})
64
- end
62
+ remove_foreign_key("child", {:name=>"child_ibfk_1"})
65
63
  RUBY
66
64
  delta.migrate
67
65
  expect(subject.dump.each_line.select {|i| i !~ /\A\Z/ }.join).to eq expected_dsl.strip_heredoc.strip.each_line.select {|i| i !~ /\A\Z/ }.join
@@ -71,36 +69,37 @@ end
71
69
  context 'when drop fk when drop table' do
72
70
  let(:dsl) {
73
71
  <<-RUBY
74
- create_table "parent", force: true do |t|
72
+ create_table "parent", force: :cascade do |t|
75
73
  end
76
74
 
77
- create_table "child", force: true do |t|
75
+
76
+ create_table "child", force: :cascade do |t|
78
77
  t.integer "parent_id", unsigned: true
79
78
  end
80
79
 
81
80
  add_index "child", ["parent_id"], name: "par_ind", using: :btree
82
81
 
83
- add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
82
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
84
83
  RUBY
85
84
  }
86
85
 
87
86
  let(:sorted_dsl) {
88
87
  <<-RUBY
89
- create_table "child", force: true do |t|
90
- t.integer "parent_id", unsigned: true
88
+ create_table "child"#{unsigned_if_enabled}, force: :cascade do |t|
89
+ t.integer "parent_id", limit: 4#{unsigned_if_enabled}
91
90
  end
92
91
 
93
92
  add_index "child", ["parent_id"], name: "par_ind", using: :btree
94
93
 
95
- create_table "parent", force: true do |t|
94
+ create_table "parent"#{unsigned_if_enabled}, force: :cascade do |t|
96
95
  end
97
96
 
98
- add_foreign_key "child", "parent", name: "child_ibfk_1", dependent: :delete
97
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
99
98
  RUBY
100
99
  }
101
100
 
102
101
  before { subject.diff(dsl).migrate }
103
- subject { client(enable_foreigner: true) }
102
+ subject { client }
104
103
 
105
104
  it {
106
105
  delta = subject.diff('')
data/spec/spec_helper.rb CHANGED
@@ -57,8 +57,6 @@ def client(options = {}, config = {})
57
57
  default_options[:enable_mysql_awesome] = true
58
58
  default_options[:dump_without_table_options] = true
59
59
  default_options[:mysql_awesome_unsigned_pk] = true
60
- else
61
- default_options[:enable_mysql_unsigned] = true
62
60
  end
63
61
 
64
62
  options = default_options.merge(options)
@@ -142,3 +140,27 @@ end
142
140
  def mysql_awesome_enabled?
143
141
  ENV['ENABLE_MYSQL_AWESOME'] == '1'
144
142
  end
143
+
144
+ def if_mysql_awesome_enabled(then_str, else_str = '')
145
+ if mysql_awesome_enabled?
146
+ then_str
147
+ else
148
+ else_str
149
+ end
150
+ end
151
+
152
+ def unsigned_if_enabled(prefix = ', ', suffix = '')
153
+ if_mysql_awesome_enabled("#{prefix}unsigned: true#{suffix}")
154
+ end
155
+
156
+ def unsigned_false_if_enabled(prefix = ', ', suffix = '')
157
+ if_mysql_awesome_enabled("#{prefix}unsigned: false#{suffix}")
158
+ end
159
+
160
+ def unsigned_if_enabled2(prefix = ', ', suffix = '')
161
+ if_mysql_awesome_enabled("#{prefix}:unsigned=>true#{suffix}")
162
+ end
163
+
164
+ def unsigned_false_if_enabled2(prefix = ', ', suffix = '')
165
+ if_mysql_awesome_enabled("#{prefix}:unsigned=>false#{suffix}")
166
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3.beta4
4
+ version: 0.6.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-13 00:00:00.000000000 Z
11
+ date: 2015-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - <
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0
19
+ version: 4.2.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - <
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.0
26
+ version: 4.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: sqlite3
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: coveralls
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -109,75 +95,19 @@ dependencies:
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
- name: activerecord-mysql-unsigned
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ~>
116
- - !ruby/object:Gem::Version
117
- version: 0.3.1
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ~>
123
- - !ruby/object:Gem::Version
124
- version: 0.3.1
125
- - !ruby/object:Gem::Dependency
126
- name: foreigner
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - <=
130
- - !ruby/object:Gem::Version
131
- version: 1.7.1
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - <=
137
- - !ruby/object:Gem::Version
138
- version: 1.7.1
139
- - !ruby/object:Gem::Dependency
140
- name: activerecord-mysql-pkdump
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - '>='
144
- - !ruby/object:Gem::Version
145
- version: 0.1.0
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - '>='
151
- - !ruby/object:Gem::Version
152
- version: 0.1.0
153
- - !ruby/object:Gem::Dependency
154
- name: migration_comments
98
+ name: activerecord-mysql-awesome
155
99
  requirement: !ruby/object:Gem::Requirement
156
100
  requirements:
157
101
  - - '>='
158
102
  - !ruby/object:Gem::Version
159
- version: '0'
103
+ version: 0.0.7
160
104
  type: :development
161
105
  prerelease: false
162
106
  version_requirements: !ruby/object:Gem::Requirement
163
107
  requirements:
164
108
  - - '>='
165
109
  - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: activerecord-mysql-awesome
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - <=
172
- - !ruby/object:Gem::Version
173
- version: 0.0.4
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - <=
179
- - !ruby/object:Gem::Version
180
- version: 0.0.4
110
+ version: 0.0.7
181
111
  description: Ridgepole is a tool to manage DB schema. It defines DB schema using Rails
182
112
  DSL, and updates DB schema according to DSL.
183
113
  email:
@@ -203,19 +133,16 @@ files:
203
133
  - lib/ridgepole/dsl_parser.rb
204
134
  - lib/ridgepole/dumper.rb
205
135
  - lib/ridgepole/execute_expander.rb
206
- - lib/ridgepole/ext/foreign_key.rb
207
136
  - lib/ridgepole/ext/mysql_awesome.rb
208
137
  - lib/ridgepole/logger.rb
209
138
  - lib/ridgepole/migration_ext.rb
210
139
  - lib/ridgepole/schema_dumper_ext.rb
211
140
  - lib/ridgepole/version.rb
212
141
  - ridgepole.gemspec
213
- - spec/0_diff/dump_disable_unsigned_spec.rb
214
142
  - spec/bigint_pk/bigint_pkspec.rb
215
143
  - spec/cli/config_spec.rb
216
144
  - spec/cli/ridgepole_spec.rb
217
145
  - spec/collation/collation_spec.rb
218
- - spec/comment/comment_spec.rb
219
146
  - spec/diff/diff2_spec.rb
220
147
  - spec/diff/diff_spec.rb
221
148
  - spec/dump/dump_class_method_spec.rb
@@ -251,7 +178,6 @@ files:
251
178
  - spec/migrate/migrate_rename_column_spec.rb
252
179
  - spec/migrate/migrate_rename_table_spec.rb
253
180
  - spec/migrate/migrate_same_default_null_spec.rb
254
- - spec/migrate/migrate_same_default_unsigned_spec.rb
255
181
  - spec/migrate/migrate_same_spec.rb
256
182
  - spec/migrate/migrate_script_error_spec.rb
257
183
  - spec/migrate/migrate_skip_rename_column_spec.rb
@@ -266,8 +192,7 @@ files:
266
192
  - spec/ridgepole_test_tables.sql
267
193
  - spec/spec_helper.rb
268
194
  - spec/string_ext.rb
269
- - spec/~pkdump/pkdump_spec.rb
270
- homepage: http://ridgepole.codenize.tools/
195
+ homepage: https://github.com/winebarrel/ridgepole/tree/v0.6.0
271
196
  licenses:
272
197
  - MIT
273
198
  metadata: {}
@@ -292,12 +217,10 @@ signing_key:
292
217
  specification_version: 4
293
218
  summary: Ridgepole is a tool to manage DB schema.
294
219
  test_files:
295
- - spec/0_diff/dump_disable_unsigned_spec.rb
296
220
  - spec/bigint_pk/bigint_pkspec.rb
297
221
  - spec/cli/config_spec.rb
298
222
  - spec/cli/ridgepole_spec.rb
299
223
  - spec/collation/collation_spec.rb
300
- - spec/comment/comment_spec.rb
301
224
  - spec/diff/diff2_spec.rb
302
225
  - spec/diff/diff_spec.rb
303
226
  - spec/dump/dump_class_method_spec.rb
@@ -333,7 +256,6 @@ test_files:
333
256
  - spec/migrate/migrate_rename_column_spec.rb
334
257
  - spec/migrate/migrate_rename_table_spec.rb
335
258
  - spec/migrate/migrate_same_default_null_spec.rb
336
- - spec/migrate/migrate_same_default_unsigned_spec.rb
337
259
  - spec/migrate/migrate_same_spec.rb
338
260
  - spec/migrate/migrate_script_error_spec.rb
339
261
  - spec/migrate/migrate_skip_rename_column_spec.rb
@@ -348,4 +270,3 @@ test_files:
348
270
  - spec/ridgepole_test_tables.sql
349
271
  - spec/spec_helper.rb
350
272
  - spec/string_ext.rb
351
- - spec/~pkdump/pkdump_spec.rb
@@ -1,121 +0,0 @@
1
- class Ridgepole::ForeignKey
2
- class << self
3
- def init
4
- require 'foreigner'
5
-
6
- ActiveSupport.on_load :active_record do
7
- Foreigner.load
8
- end
9
-
10
- Ridgepole::DSLParser::Context.include_module(Ridgepole::ForeignKey::DSL)
11
- end
12
-
13
- def check_orphan_foreign_key(definition)
14
- definition.each do |table_name, attrs|
15
- if attrs[:foreign_keys] and not attrs[:definition]
16
- raise "Table `#{table_name}` to create the foreign key is not defined: #{attrs[:foreign_keys].keys.join(',')}"
17
- end
18
- end
19
- end
20
-
21
- def scan_foreign_keys_change(from, to, table_delta, options)
22
- from = (from || {}).dup
23
- to = (to || {}).dup
24
- foreign_keys_delta = {}
25
-
26
- to.each do |foreign_key_name, to_attrs|
27
- from_attrs = from.delete(foreign_key_name)
28
-
29
- if from_attrs
30
- if from_attrs != to_attrs
31
- foreign_keys_delta[:add] ||= {}
32
- foreign_keys_delta[:add][foreign_key_name] = to_attrs
33
-
34
- unless options[:merge]
35
- foreign_keys_delta[:delete] ||= {}
36
- foreign_keys_delta[:delete][foreign_key_name] = from_attrs
37
- end
38
- end
39
- else
40
- foreign_keys_delta[:add] ||= {}
41
- foreign_keys_delta[:add][foreign_key_name] = to_attrs
42
- end
43
- end
44
-
45
- unless options[:merge]
46
- from.each do |foreign_key_name, from_attrs|
47
- foreign_keys_delta[:delete] ||= {}
48
- foreign_keys_delta[:delete][foreign_key_name] = from_attrs
49
- end
50
- end
51
-
52
- unless foreign_keys_delta.empty?
53
- table_delta[:foreign_keys] = foreign_keys_delta
54
- end
55
- end
56
-
57
- def append_change_foreign_keys(table_name, delta, buf, options)
58
- (delta[:delete] || {}).each do |foreign_key_name, attrs|
59
- append_remove_foreign_key(table_name, foreign_key_name, attrs, buf, options)
60
- end
61
-
62
- (delta[:add] || {}).each do |foreign_key_name, attrs|
63
- append_add_foreign_key(table_name, foreign_key_name, attrs, buf, options)
64
- end
65
- end
66
-
67
- def append_add_foreign_key(table_name, foreign_key_name, attrs, buf, options)
68
- to_table = attrs.fetch(:to_table)
69
- attrs_options = attrs[:options] || {}
70
-
71
- if options[:bulk_change]
72
- buf.puts(<<-EOS)
73
- t.foreign_key(#{to_table.inspect}, #{attrs_options.inspect})
74
- EOS
75
- else
76
- buf.puts(<<-EOS)
77
- add_foreign_key(#{table_name.inspect}, #{to_table.inspect}, #{attrs_options.inspect})
78
- EOS
79
- end
80
- end
81
-
82
- def append_remove_foreign_key(table_name, foreign_key_name, attrs, buf, options)
83
- attrs_options = attrs[:options] || {}
84
- target = {:name => attrs_options.fetch(:name)}
85
-
86
- if options[:bulk_change]
87
- buf.puts(<<-EOS)
88
- t.remove_foreign_key(#{target.inspect})
89
- EOS
90
- else
91
- buf.puts(<<-EOS)
92
- remove_foreign_key(#{table_name.inspect}, #{target.inspect})
93
- EOS
94
- end
95
- end
96
- end # of class methods
97
-
98
- module DSL
99
- def add_foreign_key(from_table, to_table, options = {})
100
- unless options[:name]
101
- raise "Foreign key name in `#{from_table}` is undefined"
102
- end
103
-
104
- from_table = from_table.to_s
105
- to_table = to_table.to_s
106
- options[:name] = options[:name].to_s
107
- @__definition[from_table] ||= {}
108
- @__definition[from_table][:foreign_keys] ||= {}
109
- idx = options[:name]
110
-
111
- if @__definition[from_table][:foreign_keys][idx]
112
- raise "Foreign Key `#{from_table}(#{idx})` already defined"
113
- end
114
-
115
- @__definition[from_table][:foreign_keys][idx] = {
116
- :to_table => to_table,
117
- :options => options,
118
- }
119
- end
120
- end
121
- end