dm-migrations 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/lib/dm-migrations/version.rb +1 -1
- data/lib/migration.rb +34 -11
- data/lib/sql/table_creator.rb +29 -4
- data/spec/integration/sql_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
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",
|
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(
|
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
|
data/lib/migration.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
gem 'dm-core', '=0.9.
|
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
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
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
|
data/lib/sql/table_creator.rb
CHANGED
@@ -21,7 +21,28 @@ module SQL
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_sql
|
24
|
-
|
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
|
-
|
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
|
-
|
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},
|
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,
|
11
|
+
column :name, 'varchar(50)'
|
12
12
|
column :long_string, String, :size => 200
|
13
13
|
end
|
14
14
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
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-
|
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:
|