ridgepole 0.5.1.beta2 → 0.5.1.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9af86c581c1569a32fe9979ae3ae931da5460d4e
4
- data.tar.gz: fd26b890b1d8c15c422cad66a1e30e46548d348a
3
+ metadata.gz: 72dc76a06336b986b39d1d06245b66f1990b331e
4
+ data.tar.gz: 6c0efa155b47314e400137233524b902d08ed6bd
5
5
  SHA512:
6
- metadata.gz: 529d087f92bf40940a7265a3d7a5ede5446b6f2fcad262fbe01263908d51c480af6e768ede05ab251a63fd65433ad95570e86b52c859ea677ab72cb98d3e0365
7
- data.tar.gz: c8a2cf8a7748b6c28b0547adf5e856226c5b0b80504b5962e81eb818dab256dea5025098892542144f1bea7c647294fd775db54bba1bcb74d01217d8df42ba4e
6
+ metadata.gz: 765c85bdff9c195f721ba25505e9b3fa5a481089f40f8e9d4520f1c5568d121872235a4da2df4633fcc4477fafd4b96d376578882efedcd0a6d320bc59910dd4
7
+ data.tar.gz: 362add68bbbd28c8eda6a304d5cfa12beda6efd2ae36fcc2f8c72915e6ddbaffc4a8e7de755a75053697110be4e16e52abb562ebc25871601fe558c6dd8dee22
data/bin/ridgepole CHANGED
@@ -199,7 +199,7 @@ begin
199
199
  if %w(.yml .yaml).include?(file_ext)
200
200
  Ridgepole::Config.load(file, env)
201
201
  else
202
- File.read(file)
202
+ File.open(file)
203
203
  end
204
204
  else
205
205
  YAML.load(file)
@@ -63,9 +63,20 @@ class Ridgepole::Client
63
63
  private
64
64
 
65
65
  def load_definition(dsl_or_config, options = {})
66
- dsl_or_config = dump(dsl_or_config, options) if dsl_or_config.kind_of?(Hash)
66
+ parse_opts = {}
67
+
68
+ case dsl_or_config
69
+ when Hash
70
+ dsl_or_config = dump(dsl_or_config, options)
71
+ when File
72
+ file = dsl_or_config
73
+ parse_opts[:path] = file.path
74
+ dsl_or_config = file.read
75
+ file.close
76
+ end
77
+
67
78
  parser = Ridgepole::DSLParser.new(options)
68
- parser.parse(dsl_or_config)
79
+ parser.parse(dsl_or_config, parse_opts)
69
80
  end
70
81
  end # of class methods
71
82
  end
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.5.1.beta2'
2
+ VERSION = '0.5.1.beta3'
3
3
  end
@@ -377,9 +377,9 @@ describe 'ridgepole' do
377
377
 
378
378
  expect(status.success?).to be_truthy
379
379
 
380
- expect(out.strip).to eq <<-'EOS'.strip_heredoc.strip
380
+ expect(out.strip).to eq <<-EOS.strip_heredoc.strip
381
381
  Ridgepole::Client#initialize([{"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
382
- Ridgepole::Client.diff(["create_table :table do\nend\n", {"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
382
+ Ridgepole::Client.diff([#{conf_file.path}, {"adapter"=>"mysql2", "database"=>"ridgepole_test"}, {:dry_run=>false, :debug=>false}])
383
383
  Ridgepole::Delta#differ?
384
384
  EOS
385
385
  end
@@ -0,0 +1,184 @@
1
+ describe 'Ridgepole::Client.diff' do
2
+ context 'when change column' do
3
+ let(:tmpdir) { Dir.mktmpdir }
4
+
5
+ let(:actual_dsl) {
6
+ open("#{tmpdir}/file1.required", 'w') do |f|
7
+ f.puts <<-RUBY
8
+ create_table "clubs", force: true do |t|
9
+ t.string "name", default: "", null: false
10
+ end
11
+
12
+ add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
13
+
14
+ create_table "departments", primary_key: "dept_no", force: true do |t|
15
+ t.string "dept_name", limit: 40, null: false
16
+ end
17
+
18
+ add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
19
+
20
+ create_table "dept_emp", id: false, force: true do |t|
21
+ t.integer "emp_no", null: false
22
+ t.string "dept_no", limit: 4, null: false
23
+ t.date "from_date", null: false
24
+ t.date "to_date", null: false
25
+ end
26
+
27
+ add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
28
+ add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
29
+
30
+ create_table "dept_manager", id: false, force: true do |t|
31
+ t.string "dept_no", limit: 4, null: false
32
+ t.integer "emp_no", null: false
33
+ t.date "from_date", null: false
34
+ t.date "to_date", null: false
35
+ end
36
+
37
+ add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
38
+ add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
39
+ RUBY
40
+ end
41
+
42
+ f = open("#{tmpdir}/file1", 'w+')
43
+
44
+ f.puts <<-RUBY
45
+ require "file1.required"
46
+
47
+ create_table "employee_clubs", force: true do |t|
48
+ t.integer "emp_no", null: false, unsigned: true
49
+ t.integer "club_id", null: false, unsigned: true
50
+ end
51
+
52
+ add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
53
+
54
+ create_table "employees", primary_key: "emp_no", force: true do |t|
55
+ t.date "birth_date", null: false
56
+ t.string "first_name", limit: 14, null: false
57
+ t.string "last_name", limit: 16, null: false
58
+ t.string "gender", limit: 1, null: false
59
+ t.date "hire_date", null: false
60
+ end
61
+
62
+ create_table "salaries", id: false, force: true do |t|
63
+ t.integer "emp_no", null: false
64
+ t.integer "salary", null: false
65
+ t.date "from_date", null: false
66
+ t.date "to_date", null: false
67
+ end
68
+
69
+ add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
70
+
71
+ create_table "titles", id: false, force: true do |t|
72
+ t.integer "emp_no", null: false
73
+ t.string "title", limit: 50, null: false
74
+ t.date "from_date", null: false
75
+ t.date "to_date"
76
+ end
77
+
78
+ add_index "titles", ["emp_no"], name: "emp_no", using: :btree
79
+ RUBY
80
+
81
+ f.flush
82
+ f.rewind
83
+ f
84
+ }
85
+
86
+ let(:expected_dsl) {
87
+ open("#{tmpdir}/file2.required", 'w') do |f|
88
+ f.puts <<-RUBY
89
+ create_table "clubs", force: true do |t|
90
+ t.string "name", default: "", null: false
91
+ end
92
+
93
+ add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
94
+
95
+ create_table "departments", primary_key: "dept_no", force: true do |t|
96
+ t.string "dept_name", limit: 40, null: false
97
+ end
98
+
99
+ add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
100
+
101
+ create_table "dept_emp", id: false, force: true do |t|
102
+ t.integer "emp_no", null: false
103
+ t.string "dept_no", limit: 4, null: false
104
+ t.date "from_date", null: false
105
+ t.date "to_date", null: false
106
+ end
107
+
108
+ add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
109
+ add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
110
+
111
+ create_table "dept_manager", id: false, force: true do |t|
112
+ t.string "dept_no", limit: 4, null: false
113
+ t.integer "emp_no", null: false
114
+ t.date "from_date", null: false
115
+ t.date "to_date", null: false
116
+ end
117
+
118
+ add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
119
+ add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
120
+ RUBY
121
+ end
122
+
123
+ f = open("#{tmpdir}/file2", 'w+')
124
+
125
+ f.puts <<-RUBY
126
+ require "file2.required"
127
+
128
+ create_table "employee_clubs", force: true do |t|
129
+ t.integer "emp_no", unsigned: true, null: false
130
+ t.integer "club_id", unsigned: false, null: true
131
+ end
132
+
133
+ add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
134
+
135
+ create_table "employees", primary_key: "emp_no", force: true do |t|
136
+ t.date "birth_date", null: false
137
+ t.string "first_name", limit: 14, null: false
138
+ t.string "last_name", limit: 20, default: "XXX", null: false
139
+ t.string "gender", limit: 2, null: false
140
+ t.date "hire_date", null: false
141
+ end
142
+
143
+ create_table "salaries", id: false, force: true do |t|
144
+ t.integer "emp_no", null: false
145
+ t.integer "salary", null: false
146
+ t.date "from_date", null: false
147
+ t.date "to_date", null: false
148
+ end
149
+
150
+ add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
151
+
152
+ create_table "titles", id: false, force: true do |t|
153
+ t.integer "emp_no", null: false
154
+ t.string "title", limit: 50, null: false
155
+ t.date "from_date", null: false
156
+ t.date "to_date"
157
+ end
158
+
159
+ add_index "titles", ["emp_no"], name: "emp_no", using: :btree
160
+ RUBY
161
+
162
+ f.flush
163
+ f.rewind
164
+ f
165
+ }
166
+
167
+ subject { Ridgepole::Client }
168
+
169
+ it {
170
+ delta = subject.diff(actual_dsl, expected_dsl, enable_mysql_unsigned: true)
171
+ expect(delta.differ?).to be_truthy
172
+ expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
173
+ change_column("employee_clubs", "club_id", :integer, {:unsigned=>false, :null=>true, :default=>nil})
174
+
175
+ change_column("employees", "last_name", :string, {:limit=>20, :default=>"XXX", :null=>false, :unsigned=>false})
176
+ change_column("employees", "gender", :string, {:limit=>2, :null=>false, :unsigned=>false})
177
+ RUBY
178
+ }
179
+
180
+ after do
181
+ FileUtils.remove_entry_secure(tmpdir)
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,68 @@
1
+ describe 'Ridgepole::Client#diff -> migrate' do
2
+ context 'when change float column' do
3
+ let(:actual_dsl) {
4
+ <<-RUBY
5
+ create_table "salaries", id: false, force: true do |t|
6
+ t.integer "emp_no", null: false
7
+ t.float "salary", limit: 24, null: false
8
+ t.date "from_date", null: false
9
+ t.date "to_date", null: false
10
+ end
11
+ RUBY
12
+ }
13
+
14
+ let(:expected_dsl) {
15
+ <<-RUBY
16
+ create_table "salaries", id: false, force: true do |t|
17
+ t.integer "emp_no", null: false
18
+ t.float "salary", null: false
19
+ t.date "from_date", null: false
20
+ t.date "to_date", null: false
21
+ end
22
+ RUBY
23
+ }
24
+
25
+ before { subject.diff(actual_dsl).migrate }
26
+ subject { client }
27
+
28
+ it {
29
+ delta = subject.diff(expected_dsl)
30
+ expect(delta.differ?).to be_truthy
31
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
32
+ delta.migrate
33
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
34
+ }
35
+ end
36
+
37
+ context 'when change float column (no change)' do
38
+ let(:actual_dsl) {
39
+ <<-RUBY
40
+ create_table "salaries", id: false, force: true do |t|
41
+ t.integer "emp_no", null: false
42
+ t.float "salary", limit: 24, null: false
43
+ t.date "from_date", null: false
44
+ t.date "to_date", null: false
45
+ end
46
+ RUBY
47
+ }
48
+
49
+ let(:expected_dsl) {
50
+ <<-RUBY
51
+ create_table "salaries", id: false, force: true do |t|
52
+ t.integer "emp_no", null: false
53
+ t.float "salary", null: false
54
+ t.date "from_date", null: false
55
+ t.date "to_date", null: false
56
+ end
57
+ RUBY
58
+ }
59
+
60
+ before { subject.diff(actual_dsl).migrate }
61
+ subject { client(normalize_mysql_float: true) }
62
+
63
+ it {
64
+ delta = subject.diff(expected_dsl)
65
+ expect(delta.differ?).to be_falsey
66
+ }
67
+ end
68
+ end
data/spec/spec_helper.rb CHANGED
@@ -93,7 +93,7 @@ def default_cli_hook
93
93
 
94
94
  class Ridgepole::Client
95
95
  def initialize(*args)
96
- puts "Ridgepole::Client#initialize(\#{args.inspect})"
96
+ puts "Ridgepole::Client#initialize([\#{args.map {|i| i.kind_of?(File) ? i.path : i.inspect}.join(', ')}])"
97
97
  end
98
98
  def dump
99
99
  puts "Ridgepole::Client#dump"
@@ -104,7 +104,7 @@ def default_cli_hook
104
104
  end
105
105
  class << self
106
106
  def diff(*args)
107
- puts "Ridgepole::Client.diff(\#{args.inspect})"
107
+ puts "Ridgepole::Client.diff([\#{args.map {|i| i.kind_of?(File) ? i.path : i.inspect}.join(', ')}])"
108
108
  Ridgepole::Delta.new
109
109
  end
110
110
  def dump(args)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1.beta2
4
+ version: 0.5.1.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-21 00:00:00.000000000 Z
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -185,6 +185,7 @@ files:
185
185
  - spec/cli/config_spec.rb
186
186
  - spec/cli/ridgepole_spec.rb
187
187
  - spec/comment/comment_spec.rb
188
+ - spec/diff/diff2_spec.rb
188
189
  - spec/diff/diff_spec.rb
189
190
  - spec/dump/dump_class_method_spec.rb
190
191
  - spec/dump/dump_some_tables_spec.rb
@@ -194,6 +195,7 @@ files:
194
195
  - spec/migrate/migrate_add_column_spec.rb
195
196
  - spec/migrate/migrate_change_column2_spec.rb
196
197
  - spec/migrate/migrate_change_column3_spec.rb
198
+ - spec/migrate/migrate_change_column_float_spec.rb
197
199
  - spec/migrate/migrate_change_column_spec.rb
198
200
  - spec/migrate/migrate_change_index2_spec.rb
199
201
  - spec/migrate/migrate_change_index3_spec.rb
@@ -262,6 +264,7 @@ test_files:
262
264
  - spec/cli/config_spec.rb
263
265
  - spec/cli/ridgepole_spec.rb
264
266
  - spec/comment/comment_spec.rb
267
+ - spec/diff/diff2_spec.rb
265
268
  - spec/diff/diff_spec.rb
266
269
  - spec/dump/dump_class_method_spec.rb
267
270
  - spec/dump/dump_some_tables_spec.rb
@@ -271,6 +274,7 @@ test_files:
271
274
  - spec/migrate/migrate_add_column_spec.rb
272
275
  - spec/migrate/migrate_change_column2_spec.rb
273
276
  - spec/migrate/migrate_change_column3_spec.rb
277
+ - spec/migrate/migrate_change_column_float_spec.rb
274
278
  - spec/migrate/migrate_change_column_spec.rb
275
279
  - spec/migrate/migrate_change_index2_spec.rb
276
280
  - spec/migrate/migrate_change_index3_spec.rb