sequel 0.4.4 → 0.4.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Rakefile +1 -1
- data/lib/sequel/adapters/mysql.rb +2 -2
- data/lib/sequel/database.rb +4 -4
- data/lib/sequel/model/schema.rb +2 -2
- data/lib/sequel/schema/schema_generator.rb +3 -5
- data/lib/sequel/schema/schema_sql.rb +14 -7
- data/spec/adapters/mysql_spec.rb +17 -0
- data/spec/schema_generator_spec.rb +2 -2
- metadata +2 -2
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
|
|
6
6
|
include FileUtils
|
7
7
|
|
8
8
|
NAME = "sequel"
|
9
|
-
VERS = "0.4.4"
|
9
|
+
VERS = "0.4.4.1"
|
10
10
|
CLEAN.include ['**/.*.sw?', 'pkg/*', '.config', 'doc/*', 'coverage/*']
|
11
11
|
RDOC_OPTS = ['--quiet', '--title', "Sequel: Concise ORM for Ruby",
|
12
12
|
"--opname", "index.html",
|
@@ -146,9 +146,9 @@ module Sequel
|
|
146
146
|
def alter_table_sql(table, op)
|
147
147
|
case op[:op]
|
148
148
|
when :rename_column
|
149
|
-
"ALTER TABLE #{table} CHANGE COLUMN #{op[:name]} #{op[:new_name]} #{op[:type]}"
|
149
|
+
"ALTER TABLE #{table} CHANGE COLUMN #{literal(op[:name])} #{literal(op[:new_name])} #{op[:type]}"
|
150
150
|
when :set_column_type
|
151
|
-
"ALTER TABLE #{table} CHANGE COLUMN #{op[:name]} #{op[:name]} #{op[:type]}"
|
151
|
+
"ALTER TABLE #{table} CHANGE COLUMN #{literal(op[:name])} #{literal(op[:name])} #{op[:type]}"
|
152
152
|
when :drop_index
|
153
153
|
"DROP INDEX #{default_index_name(table, op[:columns])} ON #{table}"
|
154
154
|
else
|
data/lib/sequel/database.rb
CHANGED
@@ -156,7 +156,7 @@ module Sequel
|
|
156
156
|
true
|
157
157
|
end
|
158
158
|
|
159
|
-
include Dataset::SQL
|
159
|
+
# include Dataset::SQL
|
160
160
|
include Schema::SQL
|
161
161
|
|
162
162
|
# default serial primary key definition. this should be overriden for each adapter.
|
@@ -173,8 +173,8 @@ module Sequel
|
|
173
173
|
# index :title
|
174
174
|
# end
|
175
175
|
def create_table(name, &block)
|
176
|
-
g = Schema::Generator.new(self,
|
177
|
-
create_table_sql_list(*g.create_info).each {|sql| execute(sql)}
|
176
|
+
g = Schema::Generator.new(self, &block)
|
177
|
+
create_table_sql_list(name, *g.create_info).each {|sql| execute(sql)}
|
178
178
|
end
|
179
179
|
|
180
180
|
# Forcibly creates a table. If the table already exists it is dropped.
|
@@ -193,7 +193,7 @@ module Sequel
|
|
193
193
|
end
|
194
194
|
|
195
195
|
def alter_table(name, &block)
|
196
|
-
g = Schema::AlterTableGenerator.new(self,
|
196
|
+
g = Schema::AlterTableGenerator.new(self, &block)
|
197
197
|
alter_table_sql_list(name, g.operations).each {|sql| execute(sql)}
|
198
198
|
end
|
199
199
|
|
data/lib/sequel/model/schema.rb
CHANGED
@@ -6,7 +6,7 @@ module Sequel
|
|
6
6
|
# methods.
|
7
7
|
def self.set_schema(name = nil, &block)
|
8
8
|
name ? set_dataset(db[name]) : name = table_name
|
9
|
-
@schema = Schema::Generator.new(db,
|
9
|
+
@schema = Schema::Generator.new(db, &block)
|
10
10
|
if @schema.primary_key_name
|
11
11
|
set_primary_key @schema.primary_key_name
|
12
12
|
end
|
@@ -29,7 +29,7 @@ module Sequel
|
|
29
29
|
|
30
30
|
# Creates table.
|
31
31
|
def self.create_table
|
32
|
-
db.create_table_sql_list(*schema.create_info).each {|s| db << s}
|
32
|
+
db.create_table_sql_list(table_name, *schema.create_info).each {|s| db << s}
|
33
33
|
end
|
34
34
|
|
35
35
|
# Drops table.
|
@@ -1,9 +1,8 @@
|
|
1
1
|
module Sequel
|
2
2
|
module Schema
|
3
3
|
class Generator
|
4
|
-
def initialize(db,
|
4
|
+
def initialize(db, &block)
|
5
5
|
@db = db
|
6
|
-
@table_name = table_name
|
7
6
|
@columns = []
|
8
7
|
@indexes = []
|
9
8
|
@primary_key = nil
|
@@ -59,16 +58,15 @@ module Sequel
|
|
59
58
|
if @primary_key && !has_column?(@primary_key[:name])
|
60
59
|
@columns.unshift(@primary_key)
|
61
60
|
end
|
62
|
-
[@
|
61
|
+
[@columns, @indexes]
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
66
65
|
class AlterTableGenerator
|
67
66
|
attr_reader :operations
|
68
67
|
|
69
|
-
def initialize(db,
|
68
|
+
def initialize(db, &block)
|
70
69
|
@db = db
|
71
|
-
@table_name = table_name
|
72
70
|
@operations = []
|
73
71
|
instance_eval(&block) if block
|
74
72
|
end
|
@@ -30,9 +30,17 @@ module Sequel
|
|
30
30
|
|
31
31
|
TYPES = Hash.new {|h, k| k}
|
32
32
|
TYPES[:double] = 'double precision'
|
33
|
+
|
34
|
+
def schema_utility_dataset
|
35
|
+
@schema_utility_dataset ||= dataset
|
36
|
+
end
|
37
|
+
|
38
|
+
def literal(v)
|
39
|
+
schema_utility_dataset.literal(v)
|
40
|
+
end
|
33
41
|
|
34
42
|
def column_definition_sql(column)
|
35
|
-
sql = "#{column[:name]} #{TYPES[column[:type]]}"
|
43
|
+
sql = "#{literal(column[:name].to_sym)} #{TYPES[column[:type]]}"
|
36
44
|
column[:size] ||= 255 if column[:type] == :varchar
|
37
45
|
elements = column[:size] || column[:elements]
|
38
46
|
sql << "(#{literal(elements)})" if elements
|
@@ -60,12 +68,11 @@ module Sequel
|
|
60
68
|
end
|
61
69
|
|
62
70
|
def index_definition_sql(table_name, index)
|
63
|
-
columns = index[:columns].join(COMMA_SEPARATOR)
|
64
71
|
index_name = index[:name] || default_index_name(table_name, index[:columns])
|
65
72
|
if index[:unique]
|
66
|
-
"CREATE UNIQUE INDEX #{index_name} ON #{table_name} (#{columns})"
|
73
|
+
"CREATE UNIQUE INDEX #{index_name} ON #{table_name} (#{literal(index[:columns])})"
|
67
74
|
else
|
68
|
-
"CREATE INDEX #{index_name} ON #{table_name} (#{columns})"
|
75
|
+
"CREATE INDEX #{index_name} ON #{table_name} (#{literal(index[:columns])})"
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
@@ -98,11 +105,11 @@ module Sequel
|
|
98
105
|
when :add_column
|
99
106
|
"ALTER TABLE #{table} ADD COLUMN #{column_definition_sql(op)}"
|
100
107
|
when :drop_column
|
101
|
-
"ALTER TABLE #{table} DROP COLUMN #{op[:name]}"
|
108
|
+
"ALTER TABLE #{table} DROP COLUMN #{literal(op[:name])}"
|
102
109
|
when :rename_column
|
103
|
-
"ALTER TABLE #{table} RENAME COLUMN #{op[:name]} TO #{op[:new_name]}"
|
110
|
+
"ALTER TABLE #{table} RENAME COLUMN #{literal(op[:name])} TO #{literal(op[:new_name])}"
|
104
111
|
when :set_column_type
|
105
|
-
"ALTER TABLE #{table} ALTER COLUMN #{op[:name]} TYPE #{op[:type]}"
|
112
|
+
"ALTER TABLE #{table} ALTER COLUMN #{literal(op[:name])} TYPE #{op[:type]}"
|
106
113
|
when :add_index
|
107
114
|
index_definition_sql(table, op)
|
108
115
|
when :drop_index
|
data/spec/adapters/mysql_spec.rb
CHANGED
@@ -311,3 +311,20 @@ context "A MySQL database" do
|
|
311
311
|
@db.drop_index :test2, :value
|
312
312
|
end
|
313
313
|
end
|
314
|
+
|
315
|
+
context "A MySQL database" do
|
316
|
+
setup do
|
317
|
+
@db = MYSQL_DB
|
318
|
+
end
|
319
|
+
|
320
|
+
specify "should support defaults for boolean columns" do
|
321
|
+
g = Sequel::Schema::Generator.new(@db) do
|
322
|
+
boolean :active1, :default => true
|
323
|
+
boolean :active2, :default => false
|
324
|
+
end
|
325
|
+
statements = @db.create_table_sql_list(:items, *g.create_info)
|
326
|
+
statements.should == [
|
327
|
+
"CREATE TABLE items (`active1` boolean DEFAULT 1, `active2` boolean DEFAULT 0)"
|
328
|
+
]
|
329
|
+
end
|
330
|
+
end
|
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
2
2
|
|
3
3
|
describe Sequel::Schema::Generator do
|
4
4
|
before :all do
|
5
|
-
@generator = Sequel::Schema::Generator.new(SchemaDummyDatabase.new
|
5
|
+
@generator = Sequel::Schema::Generator.new(SchemaDummyDatabase.new) do
|
6
6
|
string :title
|
7
7
|
column :body, :text
|
8
8
|
foreign_key :parent_id
|
@@ -10,7 +10,7 @@ describe Sequel::Schema::Generator do
|
|
10
10
|
index :title
|
11
11
|
index [:title, :body]
|
12
12
|
end
|
13
|
-
@
|
13
|
+
@columns, @indexes = @generator.create_info
|
14
14
|
end
|
15
15
|
|
16
16
|
{:name => :id, :primary_key => true}.each do |column, expected|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.4
|
4
|
+
version: 0.4.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2007-12-
|
12
|
+
date: 2007-12-19 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|