dm-migrations 0.9.5 → 0.9.6

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/Rakefile CHANGED
@@ -10,7 +10,7 @@ AUTHOR = "Paul Sadauskas"
10
10
  EMAIL = "psadauskas@gmail.com"
11
11
  GEM_NAME = "dm-migrations"
12
12
  GEM_VERSION = DataMapper::Migration::VERSION
13
- GEM_DEPENDENCIES = [["dm-core", GEM_VERSION]]
13
+ GEM_DEPENDENCIES = [["dm-core", '>0.9.5']]
14
14
  GEM_CLEAN = ["log", "pkg"]
15
15
  GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO ] }
16
16
 
@@ -45,7 +45,7 @@ end
45
45
  desc 'Run specifications'
46
46
  Spec::Rake::SpecTask.new(:spec) do |t|
47
47
  t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
48
- t.spec_files = Pathname.glob(Pathname.new(__FILE__).dirname + 'spec/**/*_spec.rb')
48
+ t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
49
49
 
50
50
  begin
51
51
  t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  class Migration
3
- VERSION = "0.9.5"
3
+ VERSION = "0.9.6"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- gem 'dm-core', '=0.9.5'
2
+ gem 'dm-core', '=0.9.6'
3
3
  require 'dm-core'
4
4
  require 'benchmark'
5
5
  require File.dirname(__FILE__) + '/sql'
@@ -53,12 +53,12 @@ module DataMapper
53
53
  def perform_up
54
54
  result = nil
55
55
  if needs_up?
56
- # DataMapper.database.adapter.transaction do
57
- say_with_time "== Performing Up Migration ##{position}: #{name}", 0 do
58
- result = @up_action.call
56
+ database.transaction.commit do
57
+ say_with_time "== Performing Up Migration ##{position}: #{name}", 0 do
58
+ result = @up_action.call
59
+ end
60
+ update_migration_info(:up)
59
61
  end
60
- update_migration_info(:up)
61
- # end
62
62
  end
63
63
  result
64
64
  end
@@ -67,12 +67,12 @@ module DataMapper
67
67
  def perform_down
68
68
  result = nil
69
69
  if needs_down?
70
- # DataMapper.database.adapter.transaction do
71
- say_with_time "== Performing Down Migration ##{position}: #{name}", 0 do
72
- result = @down_action.call
70
+ database.transaction.commit do
71
+ say_with_time "== Performing Down Migration ##{position}: #{name}", 0 do
72
+ result = @down_action.call
73
+ end
74
+ update_migration_info(:down)
73
75
  end
74
- update_migration_info(:down)
75
- # end
76
76
  end
77
77
  result
78
78
  end
@@ -98,6 +98,22 @@ module DataMapper
98
98
  end
99
99
  end
100
100
 
101
+ def create_index(table_name, *columns_and_options)
102
+ if columns_and_options.last.is_a?(Hash)
103
+ opts = columns_and_options.pop
104
+ else
105
+ opts = {}
106
+ end
107
+ columns = columns_and_options.flatten
108
+
109
+ opts[:name] ||= "#{opts[:unique] ? 'unique_' : ''}index_#{table_name}_#{columns.join('_')}"
110
+
111
+ execute <<-SQL.compress_lines
112
+ CREATE #{opts[:unique] ? 'UNIQUE ' : '' }INDEX #{quote_column_name(opts[:name])} ON
113
+ #{quote_table_name(table_name)} (#{columns.map { |c| quote_column_name(c) }.join(', ') })
114
+ SQL
115
+ end
116
+
101
117
  # Orders migrations by position, so we know what order to run them in.
102
118
  # First order by postition, then by name, so at least the order is predictable.
103
119
  def <=> other
@@ -186,5 +202,12 @@ module DataMapper
186
202
  @migration_name_column ||= @adapter.send(:quote_column_name, 'migration_name')
187
203
  end
188
204
 
205
+ def quote_table_name(table_name)
206
+ @adapter.send(:quote_table_name, table_name.to_s)
207
+ end
208
+
209
+ def quote_column_name(column_name)
210
+ @adapter.send(:quote_column_name, column_name.to_s)
211
+ end
189
212
  end
190
213
  end
@@ -21,7 +21,28 @@ module SQL
21
21
  end
22
22
 
23
23
  def to_sql
24
- "CREATE TABLE #{quoted_table_name} (#{@columns.map{ |c| c.to_sql }.join(', ')})"
24
+ "CREATE TABLE #{quoted_table_name} (#{@columns.map{ |c| c.to_sql }.join(', ')})"
25
+ end
26
+
27
+ # A helper for using the native NOW() SQL function in a default
28
+ def now
29
+ SqlExpr.new('NOW()')
30
+ end
31
+
32
+ # A helper for using the native UUID() SQL function in a default
33
+ def uuid
34
+ SqlExpr.new('UUID()')
35
+ end
36
+
37
+ class SqlExpr
38
+ attr_accessor :sql
39
+ def initialize(sql)
40
+ @sql = sql
41
+ end
42
+
43
+ def to_s
44
+ @sql.to_s
45
+ end
25
46
  end
26
47
 
27
48
  class Column
@@ -37,13 +58,17 @@ module SQL
37
58
  def build_type(type_class)
38
59
  schema = {:name => @name, :quote_column_name => quoted_name}.merge(@opts)
39
60
  schema[:serial?] ||= schema[:serial]
40
- schema[:nullable?] ||= schema[:nullable]
41
- schema = @adapter.class.type_map[type_class].merge(schema)
61
+ schema[:nullable?] ||= schema[:nullable] || !schema[:not_null]
62
+ if type_class.is_a?(String)
63
+ schema[:primitive] = type_class
64
+ else
65
+ schema = @adapter.class.type_map[type_class].merge(schema)
66
+ end
42
67
  @adapter.property_schema_statement(schema)
43
68
  end
44
69
 
45
70
  def to_sql
46
- type
71
+ type
47
72
  end
48
73
 
49
74
  def quoted_name
@@ -3,12 +3,12 @@ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
3
 
4
4
  [:sqlite3, :mysql, :postgres].each do |adapter|
5
5
  next unless eval("HAS_#{adapter.to_s.upcase}")
6
- describe "Using Adapter #{adapter}, " do
6
+ describe "Using Adapter #{adapter}," do
7
7
  describe DataMapper::Migration, "#create_table helper" do
8
8
  before do
9
9
  @creator = DataMapper::Migration::TableCreator.new(repository(adapter).adapter, :people) do
10
10
  column :id, Integer, :serial => true
11
- column :name, String
11
+ column :name, 'varchar(50)'
12
12
  column :long_string, String, :size => 200
13
13
  end
14
14
  end
@@ -11,7 +11,7 @@ def load_driver(name, default_uri)
11
11
  lib = "do_#{name}"
12
12
 
13
13
  begin
14
- gem lib, '=0.9.5'
14
+ gem lib, '>=0.9.5'
15
15
  require lib
16
16
  DataMapper.setup(name, default_uri)
17
17
  DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Sadauskas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-26 00:00:00 -05:00
12
+ date: 2008-10-12 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -18,7 +18,7 @@ dependencies:
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - "="
21
+ - - ">"
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.9.5
24
24
  version: