ridgepole 0.2.8 → 0.2.9

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: 493879d39cd654fb10b76891dd5800b33c6b6f32
4
- data.tar.gz: 8afa5e085f0866ad5edc4777162e0e18cb394943
3
+ metadata.gz: ab7f38bb9a9792744ec9d0be95c424623bebc485
4
+ data.tar.gz: b0c4a492af6b717721f638151ff2551179db198c
5
5
  SHA512:
6
- metadata.gz: 449d9189b3b6e5e4bb1c9f72136379f19ad623527295dd75ab431028d13ab5dc2400e2766dbe7179e0bbd7bde9321c118f35c10256ccca4e2f1cec6e2d25cd8c
7
- data.tar.gz: 04883048e57550f4d0bbc93ed4caed8aa7583cff0124706914890becbc4a28db942aebfee6b38d9e12a72688c8599066a1bb33ac19571642e4d3de8f325c1c94
6
+ metadata.gz: 0d98972b1adb24a14092700c87640bcdeb392807a1040f15ca919c4516366f49a93db7ba1c24aab4c8b44e4fb7e812cbdce672bc2cd3ae52dc9dc7e8732ce33f
7
+ data.tar.gz: d081472f63fcd0e1fec7adf35336965f1e8946edb41f524423c47261b84b2f57ea283e6d43cb0ce1753f98f041b740aa4c531b17b65aa3a32c98cfc08cdc2679
@@ -1,4 +1,6 @@
1
1
  class Ridgepole::Delta
2
+ SCRIPT_NAME = '<Schema>'
3
+
2
4
  def initialize(delta, options = {})
3
5
  @delta = delta
4
6
  @options = options
@@ -57,7 +59,7 @@ class Ridgepole::Delta
57
59
  end
58
60
 
59
61
  Ridgepole::ExecuteExpander.without_operation(callback) do
60
- ActiveRecord::Schema.new.instance_eval(script)
62
+ eval_script(script)
61
63
  end
62
64
 
63
65
  buf.string.strip
@@ -65,10 +67,51 @@ class Ridgepole::Delta
65
67
  ActiveRecord::Migration.disable_logging = disable_logging_orig
66
68
  end
67
69
  else
68
- ActiveRecord::Schema.new.instance_eval(script)
70
+ eval_script(script)
71
+ end
72
+ end
73
+
74
+ def eval_script(script)
75
+ begin
76
+ ActiveRecord::Schema.new.instance_eval(script, SCRIPT_NAME, 1)
77
+ rescue => e
78
+ raise_exception(script, e)
79
+ end
80
+ end
81
+
82
+ def raise_exception(script, org)
83
+ lines = script.each_line
84
+ digit_number = (lines.count + 1).to_s.length
85
+ err_num = detect_error_line(org)
86
+
87
+ errmsg = lines.with_index.map {|l, i|
88
+ line_num = i + 1
89
+ prefix = (line_num == err_num) ? '* ' : ' '
90
+ "#{prefix}%*d: #{l}" % [digit_number, line_num]
91
+ }
92
+
93
+ if err_num > 0
94
+ from = err_num - 6
95
+ from = 0 if from < 0
96
+ to = err_num + 4
97
+ errmsg = errmsg.slice(from..to)
69
98
  end
99
+
100
+ e = RuntimeError.new(org.message + "\n" + errmsg.join)
101
+ e.set_backtrace(org.backtrace)
102
+ raise e
70
103
  end
71
104
 
105
+ def detect_error_line(e)
106
+ rgx = /\A#{Regexp.escape(SCRIPT_NAME)}:(\d+):/
107
+ line = e.backtrace.find {|i| i =~ rgx }
108
+
109
+ if line and (m = rgx.match(line))
110
+ m[1].to_i
111
+ else
112
+ 0
113
+ end
114
+ end
72
115
 
73
116
  def append_create_table(table_name, attrs, buf)
74
117
  options = attrs[:options] || {}
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.2.8'
2
+ VERSION = '0.2.9'
3
3
  end
@@ -0,0 +1,89 @@
1
+ describe 'Ridgepole::Client#diff -> migrate' do
2
+ context 'when database is empty' do
3
+ let(:actual_dsl) { '' }
4
+ let(:expected_dsl) {
5
+ <<-RUBY
6
+ create_table "clubs", force: true do |t|
7
+ t.string "name", default: "", null: false
8
+ end
9
+
10
+ add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
11
+
12
+ create_table "departments", primary_key: "dept_no", force: true do |t|
13
+ t.string "dept_name", limit: 40, null: false
14
+ end
15
+
16
+ add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
17
+
18
+ create_table "dept_emp", id: false, force: true do |t|
19
+ t.integer "emp_no", null: false
20
+ t.string "dept_no", limit: 4, null: false
21
+ t.date "from_date", null: false
22
+ t.date "to_date", null: false
23
+ end
24
+
25
+ add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
26
+ add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
27
+
28
+ create_table "dept_manager", id: false, force: true do |t|
29
+ t.string "dept_no", limit: 4, null: false
30
+ t.integer "emp_no", null: false
31
+ t.date "from_date", null: false
32
+ t.date "to_date", null: false
33
+ end
34
+
35
+ add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
36
+ add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
37
+
38
+ create_table "employee_clubs", force: true do |t|
39
+ t.integer "emp_no", unsigned: true, null: false
40
+ t.integer "club_id", unsigned: true, null: false
41
+ end
42
+
43
+ add_index "employee_clubs", ["emp_no", "Xclub_id"], name: "idx_emp_no_club_id", using: :btree
44
+
45
+ create_table "employees", primary_key: "emp_no", force: true do |t|
46
+ t.date "birth_date", null: false
47
+ t.string "first_name", limit: 14, null: false
48
+ t.string "last_name", limit: 16, null: false
49
+ t.string "gender", limit: 1, null: false
50
+ t.date "hire_date", null: false
51
+ end
52
+
53
+ create_table "salaries", id: false, force: true do |t|
54
+ t.integer "emp_no", null: false
55
+ t.integer "salary", null: false
56
+ t.date "from_date", null: false
57
+ t.date "to_date", null: false
58
+ end
59
+
60
+ add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
61
+
62
+ create_table "titles", id: false, force: true do |t|
63
+ t.integer "emp_no", null: false
64
+ t.string "title", limit: 50, null: false
65
+ t.date "from_date", null: false
66
+ t.date "to_date"
67
+ end
68
+
69
+ add_index "titles", ["emp_no"], name: "emp_no", using: :btree
70
+ RUBY
71
+ }
72
+
73
+ subject { client }
74
+
75
+ it {
76
+ delta = subject.diff(expected_dsl)
77
+ expect(delta.differ?).to be_truthy
78
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
79
+
80
+ errmsg = Regexp.new(Regexp.escape <<-EOS.strip)
81
+ 33: add_index("employee_clubs", ["emp_no", "Xclub_id"], {:name=>"idx_emp_no_club_id", :using=>:btree})
82
+ EOS
83
+
84
+ expect {
85
+ delta.migrate
86
+ }.to raise_error(RuntimeError, errmsg)
87
+ }
88
+ end
89
+ end
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.2.8
4
+ version: 0.2.9
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-07-22 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -147,6 +147,7 @@ files:
147
147
  - spec/migrate/migrate_same_default_null_spec.rb
148
148
  - spec/migrate/migrate_same_default_unsigned_spec.rb
149
149
  - spec/migrate/migrate_same_spec.rb
150
+ - spec/migrate/migrate_script_error_spec.rb
150
151
  - spec/migrate/migrate_skip_rename_column_spec.rb
151
152
  - spec/migrate/migrate_skip_rename_table_spec.rb
152
153
  - spec/migrate/migrate_with_ignore_tables_spec.rb
@@ -204,6 +205,7 @@ test_files:
204
205
  - spec/migrate/migrate_same_default_null_spec.rb
205
206
  - spec/migrate/migrate_same_default_unsigned_spec.rb
206
207
  - spec/migrate/migrate_same_spec.rb
208
+ - spec/migrate/migrate_script_error_spec.rb
207
209
  - spec/migrate/migrate_skip_rename_column_spec.rb
208
210
  - spec/migrate/migrate_skip_rename_table_spec.rb
209
211
  - spec/migrate/migrate_with_ignore_tables_spec.rb