dm-migrations 1.0.2 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +24 -92
- data/LICENSE +1 -1
- data/README.rdoc +36 -0
- data/Rakefile +2 -6
- data/VERSION +1 -1
- data/dm-migrations.gemspec +97 -90
- data/lib/dm-migrations/adapters/dm-do-adapter.rb +20 -6
- data/lib/dm-migrations/adapters/dm-mysql-adapter.rb +3 -1
- data/lib/dm-migrations/adapters/dm-oracle-adapter.rb +6 -0
- data/lib/dm-migrations/migration_runner.rb +1 -1
- data/lib/dm-migrations/sql/sqlite.rb +3 -1
- data/spec/integration/auto_migration_spec.rb +4 -4
- data/spec/integration/auto_upgrade_spec.rb +40 -0
- data/spec/integration/migration_runner_spec.rb +3 -3
- data/spec/integration/sql_spec.rb +1 -1
- data/spec/unit/sql/postgres_spec.rb +2 -2
- data/spec/unit/sql/sqlite_extensions_spec.rb +1 -1
- data/tasks/spec.rake +0 -3
- metadata +64 -37
- data/.gitignore +0 -37
- data/tasks/ci.rake +0 -1
- data/tasks/local_gemfile.rake +0 -16
- data/tasks/metrics.rake +0 -36
data/Gemfile
CHANGED
@@ -1,110 +1,42 @@
|
|
1
|
-
|
2
|
-
# recommended to create a local Gemfile and use this instead of the git
|
3
|
-
# sources. This will make sure that you are developing against your
|
4
|
-
# other local datamapper sources that you currently work on. Gemfile.local
|
5
|
-
# will behave identically to the standard Gemfile apart from the fact that
|
6
|
-
# it fetches the datamapper gems from local paths. This means that you can use
|
7
|
-
# the same environment variables, like ADAPTER(S) or PLUGIN(S) when running
|
8
|
-
# bundle commands. Gemfile.local is added to .gitignore, so you don't need to
|
9
|
-
# worry about accidentally checking local development paths into git.
|
10
|
-
# In order to create a local Gemfile, all you need to do is run:
|
11
|
-
#
|
12
|
-
# bundle exec rake local_gemfile
|
13
|
-
#
|
14
|
-
# This will give you a Gemfile.local file that points to your local clones of
|
15
|
-
# the various datamapper gems. It's assumed that all datamapper repo clones
|
16
|
-
# reside in the same directory. You can use the Gemfile.local like so for
|
17
|
-
# running any bundle command:
|
18
|
-
#
|
19
|
-
# BUNDLE_GEMFILE=Gemfile.local bundle foo
|
20
|
-
#
|
21
|
-
# You can also specify which adapter(s) should be part of the bundle by setting
|
22
|
-
# an environment variable. This of course also works when using the Gemfile.local
|
23
|
-
#
|
24
|
-
# bundle foo # dm-sqlite-adapter
|
25
|
-
# ADAPTER=mysql bundle foo # dm-mysql-adapter
|
26
|
-
# ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter and dm-mysql-adapter
|
27
|
-
#
|
28
|
-
# Of course you can also use the ADAPTER(S) variable when using the Gemfile.local
|
29
|
-
# and running specs against selected adapters.
|
30
|
-
#
|
31
|
-
# For easily working with adapters supported on your machine, it's recommended
|
32
|
-
# that you first install all adapters that you are planning to use or work on
|
33
|
-
# by doing something like
|
34
|
-
#
|
35
|
-
# ADAPTERS=sqlite,mysql,postgres bundle install
|
36
|
-
#
|
37
|
-
# This will clone the various repositories and make them available to bundler.
|
38
|
-
# Once you have them installed you can easily switch between adapters for the
|
39
|
-
# various development tasks. Running something like
|
40
|
-
#
|
41
|
-
# ADAPTER=mysql bundle exec rake spec
|
42
|
-
#
|
43
|
-
# will make sure that the dm-mysql-adapter is part of the bundle, and will be used
|
44
|
-
# when running the specs.
|
45
|
-
#
|
46
|
-
# You can also specify which plugin(s) should be part of the bundle by setting
|
47
|
-
# an environment variable. This also works when using the Gemfile.local
|
48
|
-
#
|
49
|
-
# bundle foo # dm-migrations
|
50
|
-
# PLUGINS=dm-validations bundle foo # dm-migrations and dm-validations
|
51
|
-
# PLUGINS=dm-validations,dm-types bundle foo # dm-migrations, dm-validations and dm-types
|
52
|
-
#
|
53
|
-
# Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run specs
|
54
|
-
# for certain adapter/plugin combinations.
|
55
|
-
#
|
56
|
-
# Finally, to speed up running specs and other tasks, it's recommended to run
|
57
|
-
#
|
58
|
-
# bundle lock
|
59
|
-
#
|
60
|
-
# after running 'bundle install' for the first time. This will make 'bundle exec' run
|
61
|
-
# a lot faster compared to the unlocked version. With an unlocked bundle you would
|
62
|
-
# typically just run 'bundle install' from time to time to fetch the latest sources from
|
63
|
-
# upstream. When you locked your bundle, you need to run
|
64
|
-
#
|
65
|
-
# bundle install --relock
|
66
|
-
#
|
67
|
-
# to make sure to fetch the latest updates and then lock the bundle again. Gemfile.lock
|
68
|
-
# is added to the .gitignore file, so you don't need to worry about accidentally checking
|
69
|
-
# it into version control.
|
1
|
+
require 'pathname'
|
70
2
|
|
71
3
|
source 'http://rubygems.org'
|
72
4
|
|
73
|
-
|
74
|
-
|
5
|
+
SOURCE = ENV.fetch('SOURCE', :git).to_sym
|
6
|
+
REPO_POSTFIX = SOURCE == :path ? '' : '.git'
|
7
|
+
DATAMAPPER = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/datamapper'
|
8
|
+
DM_VERSION = '~> 1.1.0.rc1'
|
75
9
|
|
76
|
-
group :runtime do
|
10
|
+
group :runtime do
|
77
11
|
|
78
12
|
if ENV['EXTLIB']
|
79
|
-
gem 'extlib',
|
13
|
+
gem 'extlib', '~> 0.9.15', SOURCE => "#{DATAMAPPER}/extlib#{REPO_POSTFIX}", :require => nil
|
80
14
|
else
|
81
|
-
gem 'activesupport', '~> 3.0.
|
15
|
+
gem 'activesupport', '~> 3.0.4', :require => nil
|
16
|
+
gem 'i18n', '~> 0.5.0'
|
82
17
|
end
|
83
18
|
|
84
|
-
gem 'dm-core', DM_VERSION,
|
19
|
+
gem 'dm-core', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-core#{REPO_POSTFIX}"
|
85
20
|
|
86
21
|
end
|
87
22
|
|
88
|
-
group
|
23
|
+
group :development do
|
89
24
|
|
90
|
-
gem '
|
91
|
-
gem '
|
92
|
-
gem '
|
25
|
+
gem 'jeweler', '~> 1.5.2'
|
26
|
+
gem 'rake', '~> 0.8.7'
|
27
|
+
gem 'rspec', '~> 1.3.1'
|
93
28
|
|
94
29
|
end
|
95
30
|
|
96
|
-
group :quality do
|
31
|
+
group :quality do
|
97
32
|
|
98
|
-
gem '
|
99
|
-
gem '
|
100
|
-
gem '
|
101
|
-
gem 'roodi', '~> 2.1'
|
102
|
-
gem 'yard', '~> 0.5'
|
103
|
-
gem 'yardstick', '~> 0.1'
|
33
|
+
gem 'rcov', '~> 0.9.9', :platforms => :mri_18
|
34
|
+
gem 'yard', '~> 0.6'
|
35
|
+
gem 'yardstick', '~> 0.2'
|
104
36
|
|
105
37
|
end
|
106
38
|
|
107
|
-
group :datamapper do
|
39
|
+
group :datamapper do
|
108
40
|
|
109
41
|
adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
|
110
42
|
adapters = adapters.to_s.tr(',', ' ').split.uniq - %w[ in_memory ]
|
@@ -114,27 +46,27 @@ group :datamapper do # We need this because we want to pin these dependencies to
|
|
114
46
|
|
115
47
|
if (do_adapters = DM_DO_ADAPTERS & adapters).any?
|
116
48
|
options = {}
|
117
|
-
options[:git] = "#{DATAMAPPER}/do
|
49
|
+
options[:git] = "#{DATAMAPPER}/do#{REPO_POSTFIX}" if ENV['DO_GIT'] == 'true'
|
118
50
|
|
119
|
-
gem 'data_objects',
|
51
|
+
gem 'data_objects', DO_VERSION, options.dup
|
120
52
|
|
121
53
|
do_adapters.each do |adapter|
|
122
54
|
adapter = 'sqlite3' if adapter == 'sqlite'
|
123
55
|
gem "do_#{adapter}", DO_VERSION, options.dup
|
124
56
|
end
|
125
57
|
|
126
|
-
gem 'dm-do-adapter', DM_VERSION,
|
58
|
+
gem 'dm-do-adapter', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-do-adapter#{REPO_POSTFIX}"
|
127
59
|
end
|
128
60
|
|
129
61
|
adapters.each do |adapter|
|
130
|
-
gem "dm-#{adapter}-adapter", DM_VERSION,
|
62
|
+
gem "dm-#{adapter}-adapter", DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-#{adapter}-adapter#{REPO_POSTFIX}"
|
131
63
|
end
|
132
64
|
|
133
65
|
plugins = ENV['PLUGINS'] || ENV['PLUGIN']
|
134
66
|
plugins = plugins.to_s.tr(',', ' ').split.uniq
|
135
67
|
|
136
68
|
plugins.each do |plugin|
|
137
|
-
gem plugin, DM_VERSION,
|
69
|
+
gem plugin, DM_VERSION, SOURCE => "#{DATAMAPPER}/#{plugin}#{REPO_POSTFIX}"
|
138
70
|
end
|
139
71
|
|
140
72
|
end
|
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,3 +1,39 @@
|
|
1
1
|
= dm-migrations
|
2
2
|
|
3
3
|
DataMapper plugin for writing and specing migrations.
|
4
|
+
|
5
|
+
== Example
|
6
|
+
|
7
|
+
require 'dm-migrations/migration_runner'
|
8
|
+
|
9
|
+
DataMapper.setup(:default, "sqlite3::memory")
|
10
|
+
|
11
|
+
DataMapper::Logger.new(STDOUT, :debug)
|
12
|
+
DataMapper.logger.debug( "Starting Migration" )
|
13
|
+
|
14
|
+
migration 1, :create_people_table do
|
15
|
+
up do
|
16
|
+
create_table :people do
|
17
|
+
column :id, Integer, :serial => true
|
18
|
+
column :desc, String
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
down do
|
23
|
+
drop_table :people
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
migration 2, :make_desc_text do
|
28
|
+
up do
|
29
|
+
modify_table :people do
|
30
|
+
# You currently have to use the underlying DB type here, rather than
|
31
|
+
# a DataMapper type
|
32
|
+
change_column :desc, 'text'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
migrate_up!
|
38
|
+
|
39
|
+
For more, see the examples directory.
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
|
4
4
|
begin
|
5
|
-
gem 'jeweler', '~> 1.
|
5
|
+
gem 'jeweler', '~> 1.5.2'
|
6
6
|
require 'jeweler'
|
7
7
|
|
8
8
|
Jeweler::Tasks.new do |gem|
|
@@ -15,15 +15,11 @@ begin
|
|
15
15
|
gem.has_rdoc = 'yard'
|
16
16
|
|
17
17
|
gem.rubyforge_project = 'datamapper'
|
18
|
-
|
19
|
-
gem.add_dependency 'dm-core', '~> 1.0.2'
|
20
|
-
|
21
|
-
gem.add_development_dependency 'rspec', '~> 1.3'
|
22
18
|
end
|
23
19
|
|
24
20
|
Jeweler::GemcutterTasks.new
|
25
21
|
|
26
22
|
FileList['tasks/**/*.rake'].each { |task| import task }
|
27
23
|
rescue LoadError
|
28
|
-
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
24
|
+
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.5.2'
|
29
25
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.1.0.rc1
|
data/dm-migrations.gemspec
CHANGED
@@ -1,123 +1,130 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-migrations}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.1.0.rc1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
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{
|
12
|
+
s.date = %q{2011-02-28}
|
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 = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
"tasks/spec.rake",
|
76
|
-
"tasks/yard.rake",
|
77
|
-
"tasks/yardstick.rake"
|
20
|
+
"Gemfile",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"db/migrations/1_create_people_table.rb",
|
26
|
+
"db/migrations/2_add_dob_to_people.rb",
|
27
|
+
"db/migrations/config.rb",
|
28
|
+
"dm-migrations.gemspec",
|
29
|
+
"examples/sample_migration.rb",
|
30
|
+
"examples/sample_migration_spec.rb",
|
31
|
+
"lib/dm-migrations.rb",
|
32
|
+
"lib/dm-migrations/adapters/dm-do-adapter.rb",
|
33
|
+
"lib/dm-migrations/adapters/dm-mysql-adapter.rb",
|
34
|
+
"lib/dm-migrations/adapters/dm-oracle-adapter.rb",
|
35
|
+
"lib/dm-migrations/adapters/dm-postgres-adapter.rb",
|
36
|
+
"lib/dm-migrations/adapters/dm-sqlite-adapter.rb",
|
37
|
+
"lib/dm-migrations/adapters/dm-sqlserver-adapter.rb",
|
38
|
+
"lib/dm-migrations/adapters/dm-yaml-adapter.rb",
|
39
|
+
"lib/dm-migrations/auto_migration.rb",
|
40
|
+
"lib/dm-migrations/exceptions/duplicate_migration.rb",
|
41
|
+
"lib/dm-migrations/migration.rb",
|
42
|
+
"lib/dm-migrations/migration_runner.rb",
|
43
|
+
"lib/dm-migrations/sql.rb",
|
44
|
+
"lib/dm-migrations/sql/column.rb",
|
45
|
+
"lib/dm-migrations/sql/mysql.rb",
|
46
|
+
"lib/dm-migrations/sql/postgres.rb",
|
47
|
+
"lib/dm-migrations/sql/sqlite.rb",
|
48
|
+
"lib/dm-migrations/sql/table.rb",
|
49
|
+
"lib/dm-migrations/sql/table_creator.rb",
|
50
|
+
"lib/dm-migrations/sql/table_modifier.rb",
|
51
|
+
"lib/spec/example/migration_example_group.rb",
|
52
|
+
"lib/spec/matchers/migration_matchers.rb",
|
53
|
+
"spec/integration/auto_migration_spec.rb",
|
54
|
+
"spec/integration/auto_upgrade_spec.rb",
|
55
|
+
"spec/integration/migration_runner_spec.rb",
|
56
|
+
"spec/integration/migration_spec.rb",
|
57
|
+
"spec/integration/sql_spec.rb",
|
58
|
+
"spec/isolated/require_after_setup_spec.rb",
|
59
|
+
"spec/isolated/require_before_setup_spec.rb",
|
60
|
+
"spec/isolated/require_spec.rb",
|
61
|
+
"spec/rcov.opts",
|
62
|
+
"spec/spec.opts",
|
63
|
+
"spec/spec_helper.rb",
|
64
|
+
"spec/unit/migration_spec.rb",
|
65
|
+
"spec/unit/sql/column_spec.rb",
|
66
|
+
"spec/unit/sql/postgres_spec.rb",
|
67
|
+
"spec/unit/sql/sqlite_extensions_spec.rb",
|
68
|
+
"spec/unit/sql/table_creator_spec.rb",
|
69
|
+
"spec/unit/sql/table_modifier_spec.rb",
|
70
|
+
"spec/unit/sql/table_spec.rb",
|
71
|
+
"spec/unit/sql_spec.rb",
|
72
|
+
"tasks/spec.rake",
|
73
|
+
"tasks/yard.rake",
|
74
|
+
"tasks/yardstick.rake"
|
78
75
|
]
|
79
|
-
s.has_rdoc = %q{yard}
|
80
76
|
s.homepage = %q{http://github.com/datamapper/dm-migrations}
|
81
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
82
77
|
s.require_paths = ["lib"]
|
83
78
|
s.rubyforge_project = %q{datamapper}
|
84
|
-
s.rubygems_version = %q{1.
|
79
|
+
s.rubygems_version = %q{1.5.2}
|
85
80
|
s.summary = %q{DataMapper plugin for writing and speccing migrations}
|
86
81
|
s.test_files = [
|
82
|
+
"examples/sample_migration.rb",
|
83
|
+
"examples/sample_migration_spec.rb",
|
87
84
|
"spec/integration/auto_migration_spec.rb",
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
"examples/sample_migration_spec.rb"
|
85
|
+
"spec/integration/auto_upgrade_spec.rb",
|
86
|
+
"spec/integration/migration_runner_spec.rb",
|
87
|
+
"spec/integration/migration_spec.rb",
|
88
|
+
"spec/integration/sql_spec.rb",
|
89
|
+
"spec/isolated/require_after_setup_spec.rb",
|
90
|
+
"spec/isolated/require_before_setup_spec.rb",
|
91
|
+
"spec/isolated/require_spec.rb",
|
92
|
+
"spec/spec_helper.rb",
|
93
|
+
"spec/unit/migration_spec.rb",
|
94
|
+
"spec/unit/sql/column_spec.rb",
|
95
|
+
"spec/unit/sql/postgres_spec.rb",
|
96
|
+
"spec/unit/sql/sqlite_extensions_spec.rb",
|
97
|
+
"spec/unit/sql/table_creator_spec.rb",
|
98
|
+
"spec/unit/sql/table_modifier_spec.rb",
|
99
|
+
"spec/unit/sql/table_spec.rb",
|
100
|
+
"spec/unit/sql_spec.rb"
|
105
101
|
]
|
106
102
|
|
107
103
|
if s.respond_to? :specification_version then
|
108
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
109
104
|
s.specification_version = 3
|
110
105
|
|
111
106
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
112
|
-
s.add_runtime_dependency(%q<
|
113
|
-
s.
|
107
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.4"])
|
108
|
+
s.add_runtime_dependency(%q<i18n>, ["~> 0.5.0"])
|
109
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 1.1.0.rc1"])
|
110
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
111
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
112
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3.1"])
|
114
113
|
else
|
115
|
-
s.add_dependency(%q<
|
116
|
-
s.add_dependency(%q<
|
114
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
|
115
|
+
s.add_dependency(%q<i18n>, ["~> 0.5.0"])
|
116
|
+
s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc1"])
|
117
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
118
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
119
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.1"])
|
117
120
|
end
|
118
121
|
else
|
119
|
-
s.add_dependency(%q<
|
120
|
-
s.add_dependency(%q<
|
122
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
|
123
|
+
s.add_dependency(%q<i18n>, ["~> 0.5.0"])
|
124
|
+
s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc1"])
|
125
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
126
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
127
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.1"])
|
121
128
|
end
|
122
129
|
end
|
123
130
|
|
@@ -69,6 +69,14 @@ module DataMapper
|
|
69
69
|
command = connection.create_command(statement)
|
70
70
|
command.execute_non_query
|
71
71
|
|
72
|
+
# For simple :index => true columns, add an appropriate index.
|
73
|
+
# Upgrading doesn't know how to deal with complex indexes yet.
|
74
|
+
if property.options[:index] === true
|
75
|
+
statement = create_index_statement(model, property.name, [property.field])
|
76
|
+
command = connection.create_command(statement)
|
77
|
+
command.execute_non_query
|
78
|
+
end
|
79
|
+
|
72
80
|
property
|
73
81
|
end.compact
|
74
82
|
end
|
@@ -156,13 +164,20 @@ module DataMapper
|
|
156
164
|
table_name = model.storage_name(name)
|
157
165
|
|
158
166
|
indexes(model).map do |index_name, fields|
|
159
|
-
|
160
|
-
CREATE INDEX #{quote_name("index_#{table_name}_#{index_name}")} ON
|
161
|
-
#{quote_name(table_name)} (#{fields.map { |field| quote_name(field) }.join(', ')})
|
162
|
-
SQL
|
167
|
+
create_index_statement(model, index_name, fields)
|
163
168
|
end
|
164
169
|
end
|
165
170
|
|
171
|
+
# @api private
|
172
|
+
def create_index_statement(model, index_name, fields)
|
173
|
+
table_name = model.storage_name(name)
|
174
|
+
|
175
|
+
<<-SQL.compress_lines
|
176
|
+
CREATE INDEX #{quote_name("index_#{table_name}_#{index_name}")} ON
|
177
|
+
#{quote_name(table_name)} (#{fields.map { |field| quote_name(field) }.join(', ')})
|
178
|
+
SQL
|
179
|
+
end
|
180
|
+
|
166
181
|
# @api private
|
167
182
|
def create_unique_index_statements(model)
|
168
183
|
name = self.name
|
@@ -181,10 +196,9 @@ module DataMapper
|
|
181
196
|
# @api private
|
182
197
|
def property_schema_hash(property)
|
183
198
|
primitive = property.primitive
|
184
|
-
type = property.type
|
185
199
|
type_map = self.class.type_map
|
186
200
|
|
187
|
-
schema = (type_map[property.class] || type_map[primitive]
|
201
|
+
schema = (type_map[property.class] || type_map[primitive]).merge(:name => property.field)
|
188
202
|
|
189
203
|
schema_primitive = schema[:primitive]
|
190
204
|
|
@@ -31,6 +31,8 @@ module DataMapper
|
|
31
31
|
module SQL #:nodoc:
|
32
32
|
# private ## This cannot be private for current migrations
|
33
33
|
|
34
|
+
VALUE_METHOD = RUBY_PLATFORM[/java/] ? :variable_value : :value
|
35
|
+
|
34
36
|
# @api private
|
35
37
|
def supports_serial?
|
36
38
|
true
|
@@ -95,7 +97,7 @@ module DataMapper
|
|
95
97
|
# @api private
|
96
98
|
def show_variable(name)
|
97
99
|
result = select('SHOW VARIABLES LIKE ?', name).first
|
98
|
-
result ? result.
|
100
|
+
result ? result.send(VALUE_METHOD).freeze : nil
|
99
101
|
end
|
100
102
|
|
101
103
|
private
|
@@ -63,6 +63,12 @@ module DataMapper
|
|
63
63
|
select(statement, schema_name, oracle_upcase(storage_name))
|
64
64
|
end
|
65
65
|
|
66
|
+
def drop_table_statement(model)
|
67
|
+
table_name = quote_name(model.storage_name(name))
|
68
|
+
"DROP TABLE #{table_name} CASCADE CONSTRAINTS"
|
69
|
+
end
|
70
|
+
|
71
|
+
|
66
72
|
# @api semipublic
|
67
73
|
def create_model_storage(model)
|
68
74
|
name = self.name
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'dm-migrations/sql/table'
|
2
2
|
|
3
|
+
require 'fileutils'
|
4
|
+
|
3
5
|
module SQL
|
4
6
|
module Sqlite
|
5
7
|
|
@@ -13,7 +15,7 @@ module SQL
|
|
13
15
|
|
14
16
|
def recreate_database
|
15
17
|
DataMapper.logger.info "Dropping #{@uri.path}"
|
16
|
-
|
18
|
+
FileUtils.rm_f(@uri.path)
|
17
19
|
# do nothing, sqlite will automatically create the database file
|
18
20
|
end
|
19
21
|
|
@@ -208,10 +208,10 @@ describe DataMapper::Migrations do
|
|
208
208
|
|
209
209
|
options.only(:min, :max).each do |key, value|
|
210
210
|
it "should allow the #{key} value #{value} to be stored" do
|
211
|
-
pending_if "#{value} causes problem with JRuby 1.5.2 parser",
|
211
|
+
pending_if "#{value} causes problem with JRuby 1.5.2 parser", RUBY_PLATFORM[/java/] && JRUBY_VERSION < '1.5.6' && value == -9223372036854775808 do
|
212
212
|
lambda {
|
213
213
|
resource = @model.create(@property => value)
|
214
|
-
@model.first(@property => value).should
|
214
|
+
@model.first(@property => value).should == resource
|
215
215
|
}.should_not raise_error
|
216
216
|
end
|
217
217
|
end
|
@@ -366,7 +366,7 @@ describe DataMapper::Migrations do
|
|
366
366
|
|
367
367
|
options.only(:min, :max).each do |key, value|
|
368
368
|
it "should allow the #{key} value #{value} to be stored" do
|
369
|
-
pending_if "#{value} causes problem with JRuby 1.5.2 parser",
|
369
|
+
pending_if "#{value} causes problem with JRuby 1.5.2 parser", RUBY_PLATFORM =~ /java/ && value == -9223372036854775808 do
|
370
370
|
lambda {
|
371
371
|
resource = @model.create(@property => value)
|
372
372
|
@model.first(@property => value).should eql(resource)
|
@@ -528,7 +528,7 @@ describe DataMapper::Migrations do
|
|
528
528
|
|
529
529
|
options.only(:min, :max).each do |key, value|
|
530
530
|
it "should allow the #{key} value #{value} to be stored" do
|
531
|
-
pending_if "#{value} causes problem with JRuby 1.5.2 parser",
|
531
|
+
pending_if "#{value} causes problem with JRuby 1.5.2 parser", RUBY_PLATFORM =~ /java/ && value == -9223372036854775808 do
|
532
532
|
lambda {
|
533
533
|
resource = @model.create(@property => value)
|
534
534
|
@model.first(@property => value).should eql(resource)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'dm-migrations/auto_migration'
|
4
|
+
|
5
|
+
describe DataMapper::Migrations do
|
6
|
+
def capture_log(mod)
|
7
|
+
original, mod.logger = mod.logger, DataObjects::Logger.new(@log = StringIO.new, :debug)
|
8
|
+
yield
|
9
|
+
ensure
|
10
|
+
@log.rewind
|
11
|
+
@output = @log.readlines.map do |line|
|
12
|
+
line.chomp.gsub(/\A.+?~ \(\d+\.?\d*\)\s+/, '')
|
13
|
+
end
|
14
|
+
|
15
|
+
mod.logger = original
|
16
|
+
end
|
17
|
+
|
18
|
+
supported_by :postgres do
|
19
|
+
before :all do
|
20
|
+
module ::Blog
|
21
|
+
class Article
|
22
|
+
include DataMapper::Resource
|
23
|
+
|
24
|
+
property :id, Serial
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
@model = ::Blog::Article
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#auto_upgrade' do
|
32
|
+
it 'should create an index' do
|
33
|
+
@model.auto_migrate!
|
34
|
+
@property = @model.property(:name, String, :index => true)
|
35
|
+
@response = capture_log(DataObjects::Postgres) { @model.auto_upgrade! }
|
36
|
+
@output[-2].should == "CREATE INDEX \"index_blog_articles_name\" ON \"blog_articles\" (\"name\")"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -12,7 +12,7 @@ describe 'The migration runner' do
|
|
12
12
|
describe 'empty migration runner' do
|
13
13
|
it "should return an empty array if no migrations have been defined" do
|
14
14
|
migrations.should be_kind_of(Array)
|
15
|
-
migrations.should
|
15
|
+
migrations.size.should == 0
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -32,7 +32,7 @@ describe 'The migration runner' do
|
|
32
32
|
|
33
33
|
it 'should create a new migration object, and add it to the list of migrations' do
|
34
34
|
migrations.should be_kind_of(Array)
|
35
|
-
migrations.should
|
35
|
+
migrations.size.should == 1
|
36
36
|
migrations.first.name.should == "create_people_table"
|
37
37
|
end
|
38
38
|
|
@@ -40,7 +40,7 @@ describe 'The migration runner' do
|
|
40
40
|
migration( 2, :add_dob_to_people) { }
|
41
41
|
migration( 2, :add_favorite_pet_to_people) { }
|
42
42
|
migration( 3, :add_something_else_to_people) { }
|
43
|
-
migrations.should
|
43
|
+
migrations.size.should == 4
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should raise an error on adding with a duplicated name' do
|
@@ -46,7 +46,7 @@ describe "SQL generation" do
|
|
46
46
|
|
47
47
|
it "should have an array of columns" do
|
48
48
|
@creator.instance_eval("@columns").should be_kind_of(Array)
|
49
|
-
@creator.instance_eval("@columns").should
|
49
|
+
@creator.instance_eval("@columns").size.should == 3
|
50
50
|
@creator.instance_eval("@columns").first.should be_kind_of(DataMapper::Migration::TableCreator::Column)
|
51
51
|
end
|
52
52
|
|
@@ -19,7 +19,7 @@ describe "Postgres Extensions" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should create a table object from the name' do
|
22
|
-
table = mock('
|
22
|
+
table = mock('Postgres Table')
|
23
23
|
SQL::Postgres::Table.should_receive(:new).with(@pe, 'users').and_return(table)
|
24
24
|
|
25
25
|
@pe.table('users').should == table
|
@@ -46,7 +46,7 @@ describe "Postgres Extensions" do
|
|
46
46
|
SQL::Postgres::Table.new(@adapter, 'users')
|
47
47
|
end
|
48
48
|
|
49
|
-
it 'should create
|
49
|
+
it 'should create Postgres Column objects from the returned column structs' do
|
50
50
|
SQL::Postgres::Column.should_receive(:new).with(@cs1).and_return(@col1)
|
51
51
|
SQL::Postgres::Column.should_receive(:new).with(@cs2).and_return(@col2)
|
52
52
|
SQL::Postgres::Table.new(@adapter, 'users')
|
data/tasks/spec.rake
CHANGED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
version: 1.0.2
|
4
|
+
prerelease: 6
|
5
|
+
version: 1.1.0.rc1
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Paul Sadauskas
|
@@ -14,38 +10,75 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-02-28 00:00:00 -08:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
22
|
-
prerelease: false
|
17
|
+
name: activesupport
|
23
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
19
|
none: false
|
25
20
|
requirements:
|
26
21
|
- - ~>
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 1
|
30
|
-
- 0
|
31
|
-
- 2
|
32
|
-
version: 1.0.2
|
23
|
+
version: 3.0.4
|
33
24
|
type: :runtime
|
25
|
+
prerelease: false
|
34
26
|
version_requirements: *id001
|
35
27
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
37
|
-
prerelease: false
|
28
|
+
name: i18n
|
38
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
30
|
none: false
|
40
31
|
requirements:
|
41
32
|
- - ~>
|
42
33
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
version: "1.3"
|
47
|
-
type: :development
|
34
|
+
version: 0.5.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
48
37
|
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: dm-core
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.1.0.rc1
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: jeweler
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.5.2
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rake
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.8.7
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rspec
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.3.1
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
49
82
|
description: DataMapper plugin for writing and speccing migrations
|
50
83
|
email: psadauskas [a] gmail [d] com
|
51
84
|
executables: []
|
@@ -56,7 +89,6 @@ extra_rdoc_files:
|
|
56
89
|
- LICENSE
|
57
90
|
- README.rdoc
|
58
91
|
files:
|
59
|
-
- .gitignore
|
60
92
|
- Gemfile
|
61
93
|
- LICENSE
|
62
94
|
- README.rdoc
|
@@ -91,6 +123,7 @@ files:
|
|
91
123
|
- lib/spec/example/migration_example_group.rb
|
92
124
|
- lib/spec/matchers/migration_matchers.rb
|
93
125
|
- spec/integration/auto_migration_spec.rb
|
126
|
+
- spec/integration/auto_upgrade_spec.rb
|
94
127
|
- spec/integration/migration_runner_spec.rb
|
95
128
|
- spec/integration/migration_spec.rb
|
96
129
|
- spec/integration/sql_spec.rb
|
@@ -108,19 +141,16 @@ files:
|
|
108
141
|
- spec/unit/sql/table_modifier_spec.rb
|
109
142
|
- spec/unit/sql/table_spec.rb
|
110
143
|
- spec/unit/sql_spec.rb
|
111
|
-
- tasks/ci.rake
|
112
|
-
- tasks/local_gemfile.rake
|
113
|
-
- tasks/metrics.rake
|
114
144
|
- tasks/spec.rake
|
115
145
|
- tasks/yard.rake
|
116
146
|
- tasks/yardstick.rake
|
117
|
-
has_rdoc:
|
147
|
+
has_rdoc: true
|
118
148
|
homepage: http://github.com/datamapper/dm-migrations
|
119
149
|
licenses: []
|
120
150
|
|
121
151
|
post_install_message:
|
122
|
-
rdoc_options:
|
123
|
-
|
152
|
+
rdoc_options: []
|
153
|
+
|
124
154
|
require_paths:
|
125
155
|
- lib
|
126
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -128,26 +158,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
158
|
requirements:
|
129
159
|
- - ">="
|
130
160
|
- !ruby/object:Gem::Version
|
131
|
-
segments:
|
132
|
-
- 0
|
133
161
|
version: "0"
|
134
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
163
|
none: false
|
136
164
|
requirements:
|
137
|
-
- - "
|
165
|
+
- - ">"
|
138
166
|
- !ruby/object:Gem::Version
|
139
|
-
|
140
|
-
- 0
|
141
|
-
version: "0"
|
167
|
+
version: 1.3.1
|
142
168
|
requirements: []
|
143
169
|
|
144
170
|
rubyforge_project: datamapper
|
145
|
-
rubygems_version: 1.
|
171
|
+
rubygems_version: 1.5.2
|
146
172
|
signing_key:
|
147
173
|
specification_version: 3
|
148
174
|
summary: DataMapper plugin for writing and speccing migrations
|
149
175
|
test_files:
|
176
|
+
- examples/sample_migration.rb
|
177
|
+
- examples/sample_migration_spec.rb
|
150
178
|
- spec/integration/auto_migration_spec.rb
|
179
|
+
- spec/integration/auto_upgrade_spec.rb
|
151
180
|
- spec/integration/migration_runner_spec.rb
|
152
181
|
- spec/integration/migration_spec.rb
|
153
182
|
- spec/integration/sql_spec.rb
|
@@ -163,5 +192,3 @@ test_files:
|
|
163
192
|
- spec/unit/sql/table_modifier_spec.rb
|
164
193
|
- spec/unit/sql/table_spec.rb
|
165
194
|
- spec/unit/sql_spec.rb
|
166
|
-
- examples/sample_migration.rb
|
167
|
-
- examples/sample_migration_spec.rb
|
data/.gitignore
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
## MAC OS
|
2
|
-
.DS_Store
|
3
|
-
|
4
|
-
## TEXTMATE
|
5
|
-
*.tmproj
|
6
|
-
tmtags
|
7
|
-
|
8
|
-
## EMACS
|
9
|
-
*~
|
10
|
-
\#*
|
11
|
-
.\#*
|
12
|
-
|
13
|
-
## VIM
|
14
|
-
*.swp
|
15
|
-
|
16
|
-
## Rubinius
|
17
|
-
*.rbc
|
18
|
-
|
19
|
-
## PROJECT::GENERAL
|
20
|
-
*.gem
|
21
|
-
coverage
|
22
|
-
rdoc
|
23
|
-
pkg
|
24
|
-
tmp
|
25
|
-
doc
|
26
|
-
log
|
27
|
-
.yardoc
|
28
|
-
measurements
|
29
|
-
|
30
|
-
## BUNDLER
|
31
|
-
.bundle
|
32
|
-
Gemfile.local
|
33
|
-
Gemfile.lock
|
34
|
-
Gemfile.local.lock
|
35
|
-
|
36
|
-
## PROJECT::SPECIFIC
|
37
|
-
spec/db/
|
data/tasks/ci.rake
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
task :ci => [ :verify_measurements, 'metrics:all' ]
|
data/tasks/local_gemfile.rake
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
desc "Support bundling from local source code (allows BUNDLE_GEMFILE=Gemfile.local bundle foo)"
|
2
|
-
task :local_gemfile do |t|
|
3
|
-
|
4
|
-
root = Pathname(__FILE__).dirname.parent
|
5
|
-
datamapper = root.parent
|
6
|
-
|
7
|
-
root.join('Gemfile.local').open('w') do |f|
|
8
|
-
root.join('Gemfile').open.each do |line|
|
9
|
-
line.sub!(/DATAMAPPER = 'git:\/\/github.com\/datamapper'/, "DATAMAPPER = '#{datamapper}'")
|
10
|
-
line.sub!(/:git => \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/, ':path => "#{DATAMAPPER}/\1"')
|
11
|
-
line.sub!(/do_options\[:git\] = \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/, 'do_options[:path] = "#{DATAMAPPER}/\1"')
|
12
|
-
f.puts line
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
data/tasks/metrics.rake
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'metric_fu'
|
3
|
-
rescue LoadError
|
4
|
-
namespace :metrics do
|
5
|
-
task :all do
|
6
|
-
abort 'metric_fu is not available. In order to run metrics:all, you must: gem install metric_fu'
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
begin
|
12
|
-
require 'reek/adapters/rake_task'
|
13
|
-
|
14
|
-
Reek::RakeTask.new do |t|
|
15
|
-
t.fail_on_error = true
|
16
|
-
t.verbose = false
|
17
|
-
t.source_files = 'lib/**/*.rb'
|
18
|
-
end
|
19
|
-
rescue LoadError
|
20
|
-
task :reek do
|
21
|
-
abort 'Reek is not available. In order to run reek, you must: gem install reek'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
begin
|
26
|
-
require 'roodi'
|
27
|
-
require 'roodi_task'
|
28
|
-
|
29
|
-
RoodiTask.new do |t|
|
30
|
-
t.verbose = false
|
31
|
-
end
|
32
|
-
rescue LoadError
|
33
|
-
task :roodi do
|
34
|
-
abort 'Roodi is not available. In order to run roodi, you must: gem install roodi'
|
35
|
-
end
|
36
|
-
end
|