sequel_migration_builder 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -100,7 +100,7 @@ module Sequel
100
100
  indent do
101
101
  output_columns(table[:columns], table[:primary_key])
102
102
  output_indexes(table[:indexes])
103
- output_composite_primary_key(table[:primary_key])
103
+ output_primary_key(table)
104
104
  end
105
105
  add_line "end"
106
106
  end
@@ -112,7 +112,7 @@ module Sequel
112
112
  def output_columns(columns, primary_key)
113
113
  columns.each do |c|
114
114
  column = Schema::DbColumn.build_from_hash(c)
115
- if primary_key && primary_key.size == 1 && primary_key.first == column.name
115
+ if inline_primary_key?(primary_key, column)
116
116
  column.single_primary_key = true
117
117
  end
118
118
  add_line column.define_statement
@@ -128,8 +128,13 @@ module Sequel
128
128
  end
129
129
  end
130
130
 
131
- def output_composite_primary_key(primary_key)
132
- if primary_key && primary_key.size > 1
131
+ def output_primary_key(table)
132
+ primary_key = table[:primary_key]
133
+ primary_key_already_output = table[:columns].any? do |c|
134
+ inline_primary_key?(primary_key, Schema::DbColumn.build_from_hash(c))
135
+ end
136
+
137
+ if primary_key && ! primary_key_already_output
133
138
  add_blank_line
134
139
  add_line "primary_key #{primary_key.inspect}"
135
140
  end
@@ -137,6 +142,13 @@ module Sequel
137
142
 
138
143
  private
139
144
 
145
+ def inline_primary_key?(primary_key, column)
146
+ primary_key &&
147
+ primary_key.size == 1 &&
148
+ primary_key.first == column.name &&
149
+ column.integer_type?
150
+ end
151
+
140
152
  attr_reader :result
141
153
 
142
154
  def each_table(table_names, tables)
@@ -91,6 +91,10 @@ module Sequel
91
91
  }.select {|attribute, method| __send__(method, attribute, other) }.map {|a| a.first }.to_set
92
92
  end
93
93
 
94
+ def integer_type?
95
+ INTEGER_TYPES.include?(column_type)
96
+ end
97
+
94
98
  # Returns true if this column is numeric.
95
99
  #
96
100
  def numeric?
@@ -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.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Roland Swingler"]
12
- s.date = %q{2011-03-01}
11
+ s.authors = [%q{Roland Swingler}]
12
+ s.date = %q{2012-05-11}
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 = [
@@ -38,20 +38,11 @@ Gem::Specification.new do |s|
38
38
  "spec/spec_helper.rb"
39
39
  ]
40
40
  s.homepage = %q{http://github.com/knaveofdiamonds/sequel_migration_builder}
41
- s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.7}
41
+ s.require_paths = [%q{lib}]
42
+ s.rubygems_version = %q{1.8.6}
43
43
  s.summary = %q{Build Sequel Migrations based on the differences between two schemas}
44
- s.test_files = [
45
- "spec/alter_table_operations_spec.rb",
46
- "spec/db_column_spec.rb",
47
- "spec/db_index_spec.rb",
48
- "spec/db_schema_parser_spec.rb",
49
- "spec/migration_builder_spec.rb",
50
- "spec/spec_helper.rb"
51
- ]
52
44
 
53
45
  if s.respond_to? :specification_version then
54
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
46
  s.specification_version = 3
56
47
 
57
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -10,11 +10,11 @@ describe Sequel::Schema::DbColumn do
10
10
  @column.define_statement.should == "integer :foo, :null => false, :default => 10, :unsigned => true, :size => 10"
11
11
  end
12
12
 
13
- it "should return a primary_key invocation if single_primary_key is set" do
13
+ it "should return a primary_key invocation if single_primary_key is set and the column is an integer" do
14
14
  @column.single_primary_key = true
15
15
  @column.define_statement.should == "primary_key :foo, :type => :integer, :null => false, :default => 10, :unsigned => true, :size => 10"
16
16
  end
17
-
17
+
18
18
  it "should return a #drop_statement" do
19
19
  @column.drop_statement.should == "drop_column :foo"
20
20
  end
@@ -71,6 +71,11 @@ describe "A hash in the array returned by Sequel::Schema::DbSchemaParser#parse_t
71
71
  @parser.parse_table_schema(@schema).first.size.should == [14,5]
72
72
  end
73
73
 
74
+ it "should contain a :size attribute for binary columns" do
75
+ set_db_type "binary(16)", :blob
76
+ @parser.parse_table_schema(@schema).first.size.should == 16
77
+ end
78
+
74
79
  it "should contain :unsigned false if a numeric column is not unsigned" do
75
80
  set_db_type "int(10)"
76
81
  @parser.parse_table_schema(@schema).first.unsigned.should == false
@@ -78,6 +78,27 @@ END
78
78
  should == expected.strip
79
79
  end
80
80
 
81
+ it "should add the non-integer primary key of the table" do
82
+ mock_db = mock(:database)
83
+ mock_db.should_receive(:tables).at_least(:once).and_return([])
84
+ table = {
85
+ :primary_key => :foo,
86
+ :columns => [{:name => :foo, :column_type => :binary}, {:name => :bar, :column_type => :varchar}]
87
+ }
88
+
89
+ expected = <<-END
90
+ create_table :example_table do
91
+ binary :foo, :null => false
92
+ varchar :bar, :null => false
93
+
94
+ primary_key [:foo]
95
+ end
96
+ END
97
+
98
+ Sequel::MigrationBuilder.new(mock_db).create_table_statement(:example_table, table).join("\n").
99
+ should == expected.strip
100
+ end
101
+
81
102
  it "should add the table options do the create_table statement" do
82
103
  mock_db = mock(:database)
83
104
  mock_db.should_receive(:tables).at_least(:once).and_return([])
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: 17
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roland Swingler
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-01 00:00:00 +00:00
19
- default_executable:
18
+ date: 2012-05-11 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: sequel
@@ -79,7 +78,6 @@ files:
79
78
  - spec/migration_builder_spec.rb
80
79
  - spec/spec.opts
81
80
  - spec/spec_helper.rb
82
- has_rdoc: true
83
81
  homepage: http://github.com/knaveofdiamonds/sequel_migration_builder
84
82
  licenses: []
85
83
 
@@ -109,14 +107,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
107
  requirements: []
110
108
 
111
109
  rubyforge_project:
112
- rubygems_version: 1.3.7
110
+ rubygems_version: 1.8.6
113
111
  signing_key:
114
112
  specification_version: 3
115
113
  summary: Build Sequel Migrations based on the differences between two schemas
116
- test_files:
117
- - spec/alter_table_operations_spec.rb
118
- - spec/db_column_spec.rb
119
- - spec/db_index_spec.rb
120
- - spec/db_schema_parser_spec.rb
121
- - spec/migration_builder_spec.rb
122
- - spec/spec_helper.rb
114
+ test_files: []
115
+