dm-migrations 1.1.0.rc2 → 1.1.0.rc3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source 'http://rubygems.org'
5
5
  SOURCE = ENV.fetch('SOURCE', :git).to_sym
6
6
  REPO_POSTFIX = SOURCE == :path ? '' : '.git'
7
7
  DATAMAPPER = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/datamapper'
8
- DM_VERSION = '~> 1.1.0.rc2'
8
+ DM_VERSION = '~> 1.1.0.rc3'
9
9
  DO_VERSION = '~> 0.10.2'
10
10
  DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
11
11
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0.rc2
1
+ 1.1.0.rc3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dm-migrations}
8
- s.version = "1.1.0.rc2"
8
+ s.version = "1.1.0.rc3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Paul Sadauskas"]
12
- s.date = %q{2011-03-01}
12
+ s.date = %q{2011-03-10}
13
13
  s.description = %q{DataMapper plugin for writing and speccing migrations}
14
14
  s.email = %q{psadauskas [a] gmail [d] com}
15
15
  s.extra_rdoc_files = [
@@ -76,7 +76,7 @@ Gem::Specification.new do |s|
76
76
  s.homepage = %q{http://github.com/datamapper/dm-migrations}
77
77
  s.require_paths = ["lib"]
78
78
  s.rubyforge_project = %q{datamapper}
79
- s.rubygems_version = %q{1.5.2}
79
+ s.rubygems_version = %q{1.6.2}
80
80
  s.summary = %q{DataMapper plugin for writing and speccing migrations}
81
81
  s.test_files = [
82
82
  "examples/sample_migration.rb",
@@ -104,18 +104,18 @@ Gem::Specification.new do |s|
104
104
  s.specification_version = 3
105
105
 
106
106
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
107
- s.add_runtime_dependency(%q<dm-core>, ["~> 1.1.0.rc2"])
107
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.1.0.rc3"])
108
108
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
109
109
  s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
110
110
  s.add_development_dependency(%q<rspec>, ["~> 1.3.1"])
111
111
  else
112
- s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc2"])
112
+ s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc3"])
113
113
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
114
114
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
115
115
  s.add_dependency(%q<rspec>, ["~> 1.3.1"])
116
116
  end
117
117
  else
118
- s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc2"])
118
+ s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc3"])
119
119
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
120
120
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
121
121
  s.add_dependency(%q<rspec>, ["~> 1.3.1"])
@@ -15,7 +15,7 @@ module DataMapper
15
15
  #
16
16
  # @api semipublic
17
17
  def storage_exists?(storage_name)
18
- statement = <<-SQL.compress_lines
18
+ statement = DataMapper::Ext::String.compress_lines(<<-SQL)
19
19
  SELECT COUNT(*)
20
20
  FROM "information_schema"."tables"
21
21
  WHERE "table_type" = 'BASE TABLE'
@@ -38,7 +38,7 @@ module DataMapper
38
38
  #
39
39
  # @api semipublic
40
40
  def field_exists?(storage_name, column_name)
41
- statement = <<-SQL.compress_lines
41
+ statement = DataMapper::Ext::String.compress_lines(<<-SQL)
42
42
  SELECT COUNT(*)
43
43
  FROM "information_schema"."columns"
44
44
  WHERE "table_schema" = ?
@@ -139,7 +139,7 @@ module DataMapper
139
139
 
140
140
  # @api private
141
141
  def create_table_statement(connection, model, properties)
142
- statement = <<-SQL.compress_lines
142
+ statement = DataMapper::Ext::String.compress_lines(<<-SQL)
143
143
  CREATE TABLE #{quote_name(model.storage_name(name))}
144
144
  (#{properties.map { |property| property_schema_statement(connection, property_schema_hash(property)) }.join(', ')},
145
145
  PRIMARY KEY(#{ properties.key.map { |property| quote_name(property.field) }.join(', ')}))
@@ -172,7 +172,7 @@ module DataMapper
172
172
  def create_index_statement(model, index_name, fields)
173
173
  table_name = model.storage_name(name)
174
174
 
175
- <<-SQL.compress_lines
175
+ DataMapper::Ext::String.compress_lines(<<-SQL)
176
176
  CREATE INDEX #{quote_name("index_#{table_name}_#{index_name}")} ON
177
177
  #{quote_name(table_name)} (#{fields.map { |field| quote_name(field) }.join(', ')})
178
178
  SQL
@@ -186,7 +186,7 @@ module DataMapper
186
186
  unique_indexes = unique_indexes(model).reject { |index_name, fields| fields == key }
187
187
 
188
188
  unique_indexes.map do |index_name, fields|
189
- <<-SQL.compress_lines
189
+ DataMapper::Ext::String.compress_lines(<<-SQL)
190
190
  CREATE UNIQUE INDEX #{quote_name("unique_#{table_name}_#{index_name}")} ON
191
191
  #{quote_name(table_name)} (#{fields.map { |field| quote_name(field) }.join(', ')})
192
192
  SQL
@@ -15,7 +15,7 @@ module DataMapper
15
15
 
16
16
  # @api semipublic
17
17
  def storage_exists?(storage_name)
18
- statement = <<-SQL.compress_lines
18
+ statement = DataMapper::Ext::String.compress_lines(<<-SQL)
19
19
  SELECT COUNT(*)
20
20
  FROM all_tables
21
21
  WHERE owner = ?
@@ -28,7 +28,7 @@ module DataMapper
28
28
  # @api semipublic
29
29
  def sequence_exists?(sequence_name)
30
30
  return false unless sequence_name
31
- statement = <<-SQL.compress_lines
31
+ statement = DataMapper::Ext::String.compress_lines(<<-SQL)
32
32
  SELECT COUNT(*)
33
33
  FROM all_sequences
34
34
  WHERE sequence_owner = ?
@@ -40,7 +40,7 @@ module DataMapper
40
40
 
41
41
  # @api semipublic
42
42
  def field_exists?(storage_name, field_name)
43
- statement = <<-SQL.compress_lines
43
+ statement = DataMapper::Ext::String.compress_lines(<<-SQL)
44
44
  SELECT COUNT(*)
45
45
  FROM all_tab_columns
46
46
  WHERE owner = ?
@@ -53,7 +53,7 @@ module DataMapper
53
53
 
54
54
  # @api semipublic
55
55
  def storage_fields(storage_name)
56
- statement = <<-SQL.compress_lines
56
+ statement = DataMapper::Ext::String.compress_lines(<<-SQL)
57
57
  SELECT column_name
58
58
  FROM all_tab_columns
59
59
  WHERE owner = ?
@@ -176,13 +176,13 @@ module DataMapper
176
176
  sequence_name = quote_name(sequence_name)
177
177
  column_name = quote_name(serial.field)
178
178
 
179
- statements << <<-SQL.compress_lines
179
+ statements << DataMapper::Ext::String.compress_lines(<<-SQL)
180
180
  CREATE SEQUENCE #{sequence_name} NOCACHE
181
181
  SQL
182
182
 
183
183
  # create trigger only if custom sequence name was not specified
184
184
  unless serial.options[:sequence]
185
- statements << <<-SQL.compress_lines
185
+ statements << DataMapper::Ext::String.compress_lines(<<-SQL)
186
186
  CREATE OR REPLACE TRIGGER #{quote_name(default_trigger_name(table_name))}
187
187
  BEFORE INSERT ON #{quote_name(table_name)} FOR EACH ROW
188
188
  BEGIN
@@ -212,7 +212,7 @@ module DataMapper
212
212
  def reset_sequence_statement(model)
213
213
  if sequence_name = model_sequence_name(model)
214
214
  sequence_name = quote_name(sequence_name)
215
- <<-SQL.compress_lines
215
+ DataMapper::Ext::String.compress_lines(<<-SQL)
216
216
  DECLARE
217
217
  cval INTEGER;
218
218
  BEGIN
@@ -45,7 +45,7 @@ module DataMapper
45
45
 
46
46
  # @api private
47
47
  def create_table_statement(connection, model, properties)
48
- statement = <<-SQL.compress_lines
48
+ statement = DataMapper::Ext::String.compress_lines(<<-SQL)
49
49
  CREATE TABLE #{quote_name(model.storage_name(name))}
50
50
  (#{properties.map { |property| property_schema_statement(connection, property_schema_hash(property)) }.join(', ')}
51
51
  SQL
@@ -51,7 +51,7 @@ module DataMapper
51
51
 
52
52
  # @api private
53
53
  def create_table_statement(connection, model, properties)
54
- statement = <<-SQL.compress_lines
54
+ statement = DataMapper::Ext::String.compress_lines(<<-SQL)
55
55
  CREATE TABLE #{quote_name(model.storage_name(name))}
56
56
  (#{properties.map { |property| property_schema_statement(connection, property_schema_hash(property)) }.join(', ')}
57
57
  SQL
@@ -162,7 +162,7 @@ module DataMapper
162
162
 
163
163
  opts[:name] ||= "#{opts[:unique] ? 'unique_' : ''}index_#{table_name}_#{columns.join('_')}"
164
164
 
165
- execute <<-SQL.compress_lines
165
+ execute DataMapper::Ext::String.compress_lines(<<-SQL)
166
166
  CREATE #{opts[:unique] ? 'UNIQUE ' : '' }INDEX #{quote_column_name(opts[:name])} ON
167
167
  #{quote_table_name(table_name)} (#{columns.map { |c| quote_column_name(c) }.join(', ') })
168
168
  SQL
@@ -33,6 +33,10 @@ module SQL
33
33
  end
34
34
  end
35
35
 
36
+ def change_column_type_statement(name, column)
37
+ "ALTER TABLE #{quote_name(name)} MODIFY COLUMN #{column.to_sql}"
38
+ end
39
+
36
40
  class Table
37
41
  def initialize(adapter, table_name)
38
42
  @columns = []
@@ -36,6 +36,10 @@ module SQL
36
36
  ''
37
37
  end
38
38
 
39
+ def change_column_type_statement(name, column)
40
+ "ALTER TABLE #{quote_name(name)} ALTER COLUMN #{quote_name(name)} TYPE #{column.to_sql}"
41
+ end
42
+
39
43
  class Table < SQL::Table
40
44
  def initialize(adapter, table_name)
41
45
  @adapter, @name = adapter, table_name
@@ -27,6 +27,10 @@ module SQL
27
27
  true
28
28
  end
29
29
 
30
+ def change_column_type_statement(*args)
31
+ raise NotImplementedError
32
+ end
33
+
30
34
  class Table < SQL::Table
31
35
  def initialize(adapter, table_name)
32
36
  @columns = []
@@ -67,7 +67,7 @@ module SQL
67
67
  private
68
68
 
69
69
  def build_type(type_class)
70
- schema = { :name => @name, :quote_column_name => quoted_name }.merge(@opts)
70
+ schema = { :name => @name, :quote_column_name => quoted_name }
71
71
 
72
72
  [ :nullable, :nullable? ].each do |option|
73
73
  next if (value = schema.delete(option)).nil?
@@ -79,21 +79,23 @@ module SQL
79
79
  schema[:allow_nil] = !schema[:not_null]
80
80
  end
81
81
 
82
- schema[:length] ||= schema.delete(:size) if schema.key?(:size)
83
-
84
82
  if type_class.kind_of?(String)
85
83
  schema[:primitive] = type_class
86
84
  else
85
+ type_map = @adapter.class.type_map
87
86
  primitive = type_class.respond_to?(:primitive) ? type_class.primitive : type_class
88
- options = @adapter.class.type_map[primitive].dup
87
+ options = (type_map[type_class] || type_map[primitive])
89
88
 
90
- if type_class.respond_to?(:options) && type_class.options.kind_of?(options.class)
91
- options.update(type_class.options)
92
- end
89
+ schema.update(type_class.options) if type_class.respond_to?(:options)
90
+ schema.update(options)
93
91
 
94
- schema = options.update(schema)
92
+ schema.delete(:length) if type_class == DataMapper::Property::Text
95
93
  end
96
94
 
95
+ schema.update(@opts)
96
+
97
+ schema[:length] = schema.delete(:size) if schema.key?(:size)
98
+
97
99
  @adapter.send(:with_connection) do |connection|
98
100
  @adapter.property_schema_statement(connection, schema)
99
101
  end
@@ -1,5 +1,7 @@
1
1
  module SQL
2
2
  class TableModifier
3
+ extend DataMapper::Property::Lookup
4
+
3
5
  attr_accessor :table_name, :opts, :statements, :adapter
4
6
 
5
7
  def initialize(adapter, table_name, opts = {}, &block)
@@ -36,8 +38,8 @@ module SQL
36
38
  end
37
39
 
38
40
  def change_column(name, type, opts = {})
39
- # raise NotImplemented for SQLite3
40
- @statements << "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(name)} TYPE #{type}"
41
+ column = SQL::TableCreator::Column.new(@adapter, name, type, opts)
42
+ @statements << @adapter.change_column_type_statement(table_name, column)
41
43
  end
42
44
 
43
45
  def quote_column_name(name)
@@ -206,7 +206,8 @@ describe DataMapper::Migrations do
206
206
  @output.last.should =~ %r{\ACREATE TABLE `blog_articles` \(`id` #{Regexp.escape(statement)} NOT NULL, PRIMARY KEY\(`id`\)\) ENGINE = InnoDB CHARACTER SET [a-z\d]+ COLLATE (?:[a-z\d](?:_?[a-z\d]+)*)\z}
207
207
  end
208
208
 
209
- options.only(:min, :max).each do |key, value|
209
+ [ :min, :max ].each do |key|
210
+ next unless value = options[key]
210
211
  it "should allow the #{key} value #{value} to be stored" do
211
212
  pending_if "#{value} causes problem with JRuby 1.5.2 parser", RUBY_PLATFORM[/java/] && JRUBY_VERSION < '1.5.6' && value == -9223372036854775808 do
212
213
  lambda {
@@ -364,7 +365,8 @@ describe DataMapper::Migrations do
364
365
  @output[-2].should == "CREATE TABLE \"blog_articles\" (\"id\" #{statement} NOT NULL, PRIMARY KEY(\"id\"))"
365
366
  end
366
367
 
367
- options.only(:min, :max).each do |key, value|
368
+ [ :min, :max ].each do |key|
369
+ next unless value = options[key]
368
370
  it "should allow the #{key} value #{value} to be stored" do
369
371
  pending_if "#{value} causes problem with JRuby 1.5.2 parser", RUBY_PLATFORM =~ /java/ && value == -9223372036854775808 do
370
372
  lambda {
@@ -405,7 +407,8 @@ describe DataMapper::Migrations do
405
407
  @output[-2].should == "CREATE TABLE \"blog_articles\" (\"id\" #{statement} NOT NULL, PRIMARY KEY(\"id\"))"
406
408
  end
407
409
 
408
- options.only(:min, :max).each do |key, value|
410
+ [ :min, :max ].each do |key|
411
+ next unless value = options[key]
409
412
  it "should allow the #{key} value #{value} to be stored" do
410
413
  lambda {
411
414
  resource = @model.create(@property => value)
@@ -526,7 +529,8 @@ describe DataMapper::Migrations do
526
529
  @output.last.should == "CREATE TABLE \"blog_articles\" (\"id\" #{statement} NOT NULL, PRIMARY KEY(\"id\"))"
527
530
  end
528
531
 
529
- options.only(:min, :max).each do |key, value|
532
+ [ :min, :max ].each do |key|
533
+ next unless value = options[key]
530
534
  it "should allow the #{key} value #{value} to be stored" do
531
535
  pending_if "#{value} causes problem with JRuby 1.5.2 parser", RUBY_PLATFORM =~ /java/ && value == -9223372036854775808 do
532
536
  lambda {
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dm-migrations
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.1.0.rc2
5
+ version: 1.1.0.rc3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paul Sadauskas
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-01 00:00:00 -08:00
13
+ date: 2011-03-10 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 1.1.0.rc2
23
+ version: 1.1.0.rc3
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: *id001
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  requirements: []
147
147
 
148
148
  rubyforge_project: datamapper
149
- rubygems_version: 1.5.2
149
+ rubygems_version: 1.6.2
150
150
  signing_key:
151
151
  specification_version: 3
152
152
  summary: DataMapper plugin for writing and speccing migrations