migrant 1.2.5 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -34
- data/VERSION +1 -1
- data/lib/dsl/data_type.rb +6 -3
- data/lib/dsl/data_types/primitives.rb +10 -10
- data/lib/dsl/data_types/semantic.rb +1 -1
- data/migrant.gemspec +1 -2
- data/test/rails_app/app/models/customer.rb +1 -1
- data/test/test_data_schema.rb +4 -0
- metadata +25 -36
data/Rakefile
CHANGED
@@ -8,40 +8,6 @@ rescue Bundler::BundlerError => e
|
|
8
8
|
exit e.status_code
|
9
9
|
end
|
10
10
|
require 'rake'
|
11
|
-
|
12
|
-
begin
|
13
|
-
require 'jeweler'
|
14
|
-
Jeweler::Tasks.new do |gem|
|
15
|
-
gem.name = "migrant"
|
16
|
-
gem.summary = %Q{All the fun of ActiveRecord, without writing your migrations, and a dash of mocking.}
|
17
|
-
gem.description = %Q{Easier schema management for Rails that compliments your domain model.}
|
18
|
-
gem.email = "101pascal@gmail.com"
|
19
|
-
gem.homepage = "http://github.com/pascalh1011/migrant"
|
20
|
-
gem.authors = ["Pascal Houliston"]
|
21
|
-
gem.version = File.read('VERSION')
|
22
|
-
|
23
|
-
gem.add_runtime_dependency "rails", ">= 3.0.0"
|
24
|
-
gem.add_runtime_dependency "faker"
|
25
|
-
gem.add_runtime_dependency "term-ansicolor"
|
26
|
-
|
27
|
-
gem.add_development_dependency "thoughtbot-shoulda"
|
28
|
-
gem.add_development_dependency "ansi"
|
29
|
-
gem.add_development_dependency "jeweler"
|
30
|
-
gem.add_development_dependency "turn"
|
31
|
-
gem.add_development_dependency "sqlite3"
|
32
|
-
gem.add_development_dependency "simplecov"
|
33
|
-
gem.add_development_dependency "terminal-table"
|
34
|
-
gem.add_development_dependency "term-ansicolor"
|
35
|
-
gem.add_development_dependency "rake", "0.8.7" # Until API gets sorted
|
36
|
-
|
37
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
38
|
-
end
|
39
|
-
Jeweler::GemcutterTasks.new
|
40
|
-
|
41
|
-
rescue LoadError
|
42
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
43
|
-
end
|
44
|
-
|
45
11
|
require 'rake/testtask'
|
46
12
|
Rake::TestTask.new(:test) do |test|
|
47
13
|
test.libs << 'lib' << 'test'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.7
|
data/lib/dsl/data_type.rb
CHANGED
@@ -18,8 +18,12 @@ module DataType
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# Default is 'ye good ol varchar(255)
|
21
|
+
def column_defaults
|
22
|
+
{ :type => :string }
|
23
|
+
end
|
24
|
+
|
21
25
|
def column
|
22
|
-
|
26
|
+
column_defaults.merge(@options)
|
23
27
|
end
|
24
28
|
|
25
29
|
def ==(compared_column)
|
@@ -48,13 +52,12 @@ module DataType
|
|
48
52
|
# Provide the details of a previously column, or simply nil to create a new column
|
49
53
|
def structure_changes_from(current_structure = nil)
|
50
54
|
new_structure = column
|
51
|
-
|
55
|
+
|
52
56
|
if current_structure
|
53
57
|
# General RDBMS data loss scenarios
|
54
58
|
raise DataType::DangerousMigration if (new_structure[:type] != :text && [:string, :text].include?(current_structure[:type]) && new_structure[:type] != current_structure[:type])
|
55
59
|
|
56
60
|
if new_structure[:limit] && current_structure[:limit].to_i != new_structure[:limit].to_i ||
|
57
|
-
new_structure[:default] && current_structure[:default].to_s != new_structure[:default].to_s ||
|
58
61
|
new_structure[:type] != current_structure[:type]
|
59
62
|
column
|
60
63
|
else
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataType
|
2
2
|
# Boolean
|
3
3
|
class TrueClass < Base
|
4
|
-
def
|
4
|
+
def column_defaults
|
5
5
|
{:type => :boolean}
|
6
6
|
end
|
7
7
|
|
@@ -22,7 +22,7 @@ module DataType
|
|
22
22
|
|
23
23
|
# Datetime
|
24
24
|
class Date < Base
|
25
|
-
def
|
25
|
+
def column_defaults
|
26
26
|
{:type => :datetime}
|
27
27
|
end
|
28
28
|
|
@@ -35,7 +35,7 @@ module DataType
|
|
35
35
|
|
36
36
|
# Integers
|
37
37
|
class Fixnum < Base
|
38
|
-
def
|
38
|
+
def column_defaults
|
39
39
|
{:type => :integer}.tap do |options|
|
40
40
|
options.merge!(:limit => @value.size) if @value > 2147483647 # 32-bit limit. Not checking size here because a 64-bit OS always has at least 8 byte size
|
41
41
|
end
|
@@ -47,13 +47,13 @@ module DataType
|
|
47
47
|
end
|
48
48
|
|
49
49
|
class Bignum < Fixnum
|
50
|
-
def
|
50
|
+
def column_defaults
|
51
51
|
{:type => :integer, :limit => ((@value.size > 8)? @value.size : 8) }
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
class Float < Base
|
56
|
-
def
|
56
|
+
def column_defaults
|
57
57
|
{:type => :float}
|
58
58
|
end
|
59
59
|
|
@@ -64,7 +64,7 @@ module DataType
|
|
64
64
|
|
65
65
|
# Range (0..10)
|
66
66
|
class Range < Base
|
67
|
-
def
|
67
|
+
def column_defaults
|
68
68
|
definition = {:type => :integer}
|
69
69
|
definition[:limit] = @value.max.to_s.length if @value.respond_to?(:max)
|
70
70
|
definition
|
@@ -78,22 +78,22 @@ module DataType
|
|
78
78
|
@value ||= ''
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
81
|
+
def column_defaults
|
82
82
|
if @value.match(/[\d,]+\.\d{2}$/)
|
83
|
-
return Currency.new(@options).
|
83
|
+
return Currency.new(@options).column_defaults
|
84
84
|
else
|
85
85
|
return @value.match(/[\r\n\t]/)? { :type => :text }.merge(@options) : super
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
def mock
|
90
|
-
@value || ((self.
|
90
|
+
@value || ((self.column_defaults[:type] == :text)? self.class.long_text_mock : self.class.default_mock )
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
94
|
# Symbol (defaults, specified by user)
|
95
95
|
class Symbol < Base
|
96
|
-
def
|
96
|
+
def column_defaults
|
97
97
|
# Just construct whatever the user wants
|
98
98
|
{:type => @value || :string }.merge(@options)
|
99
99
|
end
|
data/migrant.gemspec
CHANGED
@@ -23,13 +23,12 @@ Gem::Specification.new do |s|
|
|
23
23
|
|
24
24
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
25
25
|
s.add_development_dependency(%q<ansi>, [">= 0"])
|
26
|
-
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
27
26
|
s.add_development_dependency(%q<turn>, [">= 0"])
|
28
27
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
29
28
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
30
29
|
s.add_development_dependency(%q<terminal-table>, [">= 0"])
|
31
30
|
s.add_development_dependency(%q<term-ansicolor>, [">= 0"])
|
32
|
-
s.add_development_dependency(%q<rake>, ["0.8.7"])
|
31
|
+
s.add_development_dependency(%q<rake>, [">= 0.8.7"])
|
33
32
|
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
34
33
|
s.add_dependency(%q<faker>, [">= 0"])
|
35
34
|
s.add_dependency(%q<term-ansicolor>, [">= 0"])
|
data/test/test_data_schema.rb
CHANGED
@@ -46,6 +46,10 @@ class TestDataSchema < Test::Unit::TestCase
|
|
46
46
|
assert_schema(Business, :address, :type => :text)
|
47
47
|
end
|
48
48
|
|
49
|
+
should "pass on any options provided in a structure block" do
|
50
|
+
assert_schema(User, :average_rating, :type => :float, :default => 0.0)
|
51
|
+
end
|
52
|
+
|
49
53
|
should "generate a boolean column when a true or false is given" do
|
50
54
|
assert_schema(Business, :verified, :type => :boolean)
|
51
55
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: migrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-05-23 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thoughtbot-shoulda
|
16
|
-
requirement: &
|
16
|
+
requirement: &24516100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *24516100
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: ansi
|
27
|
-
requirement: &
|
27
|
+
requirement: &24515620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,21 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: jeweler
|
38
|
-
requirement: &18280140 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ! '>='
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0'
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *18280140
|
35
|
+
version_requirements: *24515620
|
47
36
|
- !ruby/object:Gem::Dependency
|
48
37
|
name: turn
|
49
|
-
requirement: &
|
38
|
+
requirement: &24515140 !ruby/object:Gem::Requirement
|
50
39
|
none: false
|
51
40
|
requirements:
|
52
41
|
- - ! '>='
|
@@ -54,10 +43,10 @@ dependencies:
|
|
54
43
|
version: '0'
|
55
44
|
type: :development
|
56
45
|
prerelease: false
|
57
|
-
version_requirements: *
|
46
|
+
version_requirements: *24515140
|
58
47
|
- !ruby/object:Gem::Dependency
|
59
48
|
name: sqlite3
|
60
|
-
requirement: &
|
49
|
+
requirement: &24514660 !ruby/object:Gem::Requirement
|
61
50
|
none: false
|
62
51
|
requirements:
|
63
52
|
- - ! '>='
|
@@ -65,10 +54,10 @@ dependencies:
|
|
65
54
|
version: '0'
|
66
55
|
type: :development
|
67
56
|
prerelease: false
|
68
|
-
version_requirements: *
|
57
|
+
version_requirements: *24514660
|
69
58
|
- !ruby/object:Gem::Dependency
|
70
59
|
name: simplecov
|
71
|
-
requirement: &
|
60
|
+
requirement: &24514180 !ruby/object:Gem::Requirement
|
72
61
|
none: false
|
73
62
|
requirements:
|
74
63
|
- - ! '>='
|
@@ -76,10 +65,10 @@ dependencies:
|
|
76
65
|
version: '0'
|
77
66
|
type: :development
|
78
67
|
prerelease: false
|
79
|
-
version_requirements: *
|
68
|
+
version_requirements: *24514180
|
80
69
|
- !ruby/object:Gem::Dependency
|
81
70
|
name: terminal-table
|
82
|
-
requirement: &
|
71
|
+
requirement: &24513700 !ruby/object:Gem::Requirement
|
83
72
|
none: false
|
84
73
|
requirements:
|
85
74
|
- - ! '>='
|
@@ -87,10 +76,10 @@ dependencies:
|
|
87
76
|
version: '0'
|
88
77
|
type: :development
|
89
78
|
prerelease: false
|
90
|
-
version_requirements: *
|
79
|
+
version_requirements: *24513700
|
91
80
|
- !ruby/object:Gem::Dependency
|
92
81
|
name: term-ansicolor
|
93
|
-
requirement: &
|
82
|
+
requirement: &24513220 !ruby/object:Gem::Requirement
|
94
83
|
none: false
|
95
84
|
requirements:
|
96
85
|
- - ! '>='
|
@@ -98,21 +87,21 @@ dependencies:
|
|
98
87
|
version: '0'
|
99
88
|
type: :development
|
100
89
|
prerelease: false
|
101
|
-
version_requirements: *
|
90
|
+
version_requirements: *24513220
|
102
91
|
- !ruby/object:Gem::Dependency
|
103
92
|
name: rake
|
104
|
-
requirement: &
|
93
|
+
requirement: &24512740 !ruby/object:Gem::Requirement
|
105
94
|
none: false
|
106
95
|
requirements:
|
107
|
-
- -
|
96
|
+
- - ! '>='
|
108
97
|
- !ruby/object:Gem::Version
|
109
98
|
version: 0.8.7
|
110
99
|
type: :development
|
111
100
|
prerelease: false
|
112
|
-
version_requirements: *
|
101
|
+
version_requirements: *24512740
|
113
102
|
- !ruby/object:Gem::Dependency
|
114
103
|
name: rails
|
115
|
-
requirement: &
|
104
|
+
requirement: &24512260 !ruby/object:Gem::Requirement
|
116
105
|
none: false
|
117
106
|
requirements:
|
118
107
|
- - ! '>='
|
@@ -120,10 +109,10 @@ dependencies:
|
|
120
109
|
version: 3.0.0
|
121
110
|
type: :runtime
|
122
111
|
prerelease: false
|
123
|
-
version_requirements: *
|
112
|
+
version_requirements: *24512260
|
124
113
|
- !ruby/object:Gem::Dependency
|
125
114
|
name: faker
|
126
|
-
requirement: &
|
115
|
+
requirement: &24511780 !ruby/object:Gem::Requirement
|
127
116
|
none: false
|
128
117
|
requirements:
|
129
118
|
- - ! '>='
|
@@ -131,10 +120,10 @@ dependencies:
|
|
131
120
|
version: '0'
|
132
121
|
type: :runtime
|
133
122
|
prerelease: false
|
134
|
-
version_requirements: *
|
123
|
+
version_requirements: *24511780
|
135
124
|
- !ruby/object:Gem::Dependency
|
136
125
|
name: term-ansicolor
|
137
|
-
requirement: &
|
126
|
+
requirement: &24511300 !ruby/object:Gem::Requirement
|
138
127
|
none: false
|
139
128
|
requirements:
|
140
129
|
- - ! '>='
|
@@ -142,7 +131,7 @@ dependencies:
|
|
142
131
|
version: '0'
|
143
132
|
type: :runtime
|
144
133
|
prerelease: false
|
145
|
-
version_requirements: *
|
134
|
+
version_requirements: *24511300
|
146
135
|
description: Easier schema management for Rails that compliments your domain model.
|
147
136
|
email: 101pascal@gmail.com
|
148
137
|
executables: []
|
@@ -253,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
253
242
|
version: '0'
|
254
243
|
requirements: []
|
255
244
|
rubyforge_project:
|
256
|
-
rubygems_version: 1.8.
|
245
|
+
rubygems_version: 1.8.6
|
257
246
|
signing_key:
|
258
247
|
specification_version: 3
|
259
248
|
summary: All the fun of ActiveRecord, without writing your migrations, and a dash
|