sequel_migration_builder 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
1
  CHANGELOG
2
2
 
3
+ == 0.2.2
4
+
5
+ * Bug fix - decimal defaults are compared correctly.
6
+ * Bug fix - escaped ' in enum elements partially solved.
7
+
3
8
  == 0.2.1
4
9
 
5
10
  * Bug fix - cast :unique => nil to false in DbIndex.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -1,4 +1,5 @@
1
1
  require 'set'
2
+ require 'bigdecimal'
2
3
 
3
4
  module Sequel
4
5
  module Schema
@@ -26,6 +27,11 @@ module Sequel
26
27
  self.new *members.map {|key| attrs[key] || attrs[key.to_sym] }
27
28
  end
28
29
 
30
+ def initialize(*args)
31
+ super
32
+ normalize_default
33
+ end
34
+
29
35
  # Returns a Sequel migration statement to define a column in a
30
36
  # create_table block.
31
37
  #
@@ -147,6 +153,12 @@ module Sequel
147
153
  opts.render
148
154
  end
149
155
 
156
+ def normalize_default
157
+ if DECIMAL_TYPES.include?(column_type) && ! self[:default].nil?
158
+ self.default = BigDecimal(self[:default].to_s)
159
+ end
160
+ end
161
+
150
162
  # Formats column options in a Sequel migration
151
163
  class OptionBuilder
152
164
  def initialize
@@ -43,7 +43,7 @@ module Sequel
43
43
  db_schema.map do |column|
44
44
  type = parse_type(column.last[:db_type])
45
45
  DbColumn.build_from_hash(:name => column.first,
46
- :default => column.last[:ruby_default],
46
+ :default => column.last[:ruby_default] || column.last[:default],
47
47
  :null => column.last[:allow_null],
48
48
  :column_type => type,
49
49
  :unsigned => extract_unsigned(column.last[:db_type], type),
@@ -98,7 +98,7 @@ module Sequel
98
98
  return unless type == :enum
99
99
 
100
100
  match = db_type_string.match(/\((.+)\)/)
101
- eval('[' + match[1] + ']') if match[1]
101
+ eval('[' + match[1].gsub(/''/, "\\\\'") + ']') if match[1]
102
102
  end
103
103
  end
104
104
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sequel_migration_builder}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roland Swingler"]
12
- s.date = %q{2011-01-13}
12
+ s.date = %q{2011-01-14}
13
13
  s.description = %q{Build Sequel Migrations based on the differences between two schemas}
14
14
  s.email = %q{roland.swingler@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -99,6 +99,14 @@ describe Sequel::Schema::DbColumn do
99
99
  b.diff(a).should == [:elements].to_set
100
100
  end
101
101
 
102
+ it "should cast decimal defaults to the correct number" do
103
+ a = Sequel::Schema::DbColumn.new(:foo, :decimal, true, '0.00', true, [4,2], nil)
104
+ b = Sequel::Schema::DbColumn.new(:foo, :decimal, true, 0, true, [4,2], nil)
105
+
106
+ a.diff(b).should == Set.new
107
+ b.diff(a).should == Set.new
108
+ end
109
+
102
110
  it "should be buildable from a Hash" do
103
111
  Sequel::Schema::DbColumn.build_from_hash(:name => "foo",
104
112
  :column_type => "integer").column_type.should == "integer"
@@ -151,4 +151,18 @@ describe "Parsing an enum column" do
151
151
 
152
152
  lambda { parser.parse_table_schema(schema) }.should_not raise_error(SyntaxError)
153
153
  end
154
+
155
+ it "should correctly parse elements with escaped '' in them" do
156
+ parser = Sequel::Schema::DbSchemaParser.for_db(stub(:database))
157
+ schema = [[:example_column,
158
+ { :type => :enum,
159
+ :default => nil,
160
+ :ruby_default => nil,
161
+ :primary_key => false,
162
+ :db_type => "enum('don''t')",
163
+ :allow_null => true }]]
164
+
165
+
166
+ parser.parse_table_schema(schema).first.elements.should == ["don't"]
167
+ end
154
168
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_migration_builder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roland Swingler
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-13 00:00:00 +00:00
18
+ date: 2011-01-14 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency