dm-migrations 1.1.0 → 1.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,26 +5,26 @@ 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'
9
- DO_VERSION = '~> 0.10.2'
8
+ DM_VERSION = '~> 1.2.0.rc1'
9
+ DO_VERSION = '~> 0.10.6'
10
10
  DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
11
11
 
12
12
  gem 'dm-core', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-core#{REPO_POSTFIX}"
13
13
 
14
14
  group :development do
15
15
 
16
- gem 'jeweler', '~> 1.5.2'
17
- gem 'rake', '~> 0.8.7'
18
- gem 'rspec', '~> 1.3.1'
16
+ gem 'jeweler', '~> 1.6.4'
17
+ gem 'rake', '~> 0.9.2'
18
+ gem 'rspec', '~> 1.3.2'
19
19
 
20
20
  end
21
21
 
22
22
  platforms :mri_18 do
23
23
  group :quality do
24
24
 
25
- gem 'rcov', '~> 0.9.9'
26
- gem 'yard', '~> 0.6'
27
- gem 'yardstick', '~> 0.2'
25
+ gem 'rcov', '~> 0.9.10'
26
+ gem 'yard', '~> 0.7.2'
27
+ gem 'yardstick', '~> 0.4'
28
28
 
29
29
  end
30
30
  end
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- gem 'jeweler', '~> 1.5.2'
5
+ gem 'jeweler', '~> 1.6.4'
6
6
  require 'jeweler'
7
7
 
8
8
  Jeweler::Tasks.new do |gem|
@@ -21,5 +21,5 @@ begin
21
21
 
22
22
  FileList['tasks/**/*.rake'].each { |task| import task }
23
23
  rescue LoadError
24
- puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.5.2'
24
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.6.4'
25
25
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0.rc1
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{dm-migrations}
8
- s.version = "1.1.0"
7
+ s.name = "dm-migrations"
8
+ s.version = "1.2.0.rc1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
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-16}
13
- s.description = %q{DataMapper plugin for writing and speccing migrations}
14
- s.email = %q{psadauskas [a] gmail [d] com}
12
+ s.date = "2011-09-09"
13
+ s.description = "DataMapper plugin for writing and speccing migrations"
14
+ s.email = "psadauskas [a] gmail [d] com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "db/migrations/2_add_dob_to_people.rb",
27
27
  "db/migrations/config.rb",
28
28
  "dm-migrations.gemspec",
29
+ "examples/Rakefile",
29
30
  "examples/sample_migration.rb",
30
31
  "examples/sample_migration_spec.rb",
31
32
  "lib/dm-migrations.rb",
@@ -73,52 +74,31 @@ Gem::Specification.new do |s|
73
74
  "tasks/yard.rake",
74
75
  "tasks/yardstick.rake"
75
76
  ]
76
- s.homepage = %q{http://github.com/datamapper/dm-migrations}
77
+ s.homepage = "http://github.com/datamapper/dm-migrations"
77
78
  s.require_paths = ["lib"]
78
- s.rubyforge_project = %q{datamapper}
79
- s.rubygems_version = %q{1.6.2}
80
- s.summary = %q{DataMapper plugin for writing and speccing migrations}
81
- s.test_files = [
82
- "examples/sample_migration.rb",
83
- "examples/sample_migration_spec.rb",
84
- "spec/integration/auto_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"
101
- ]
79
+ s.rubyforge_project = "datamapper"
80
+ s.rubygems_version = "1.8.10"
81
+ s.summary = "DataMapper plugin for writing and speccing migrations"
102
82
 
103
83
  if s.respond_to? :specification_version then
104
84
  s.specification_version = 3
105
85
 
106
86
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
107
- s.add_runtime_dependency(%q<dm-core>, ["~> 1.1.0"])
108
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
109
- s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
110
- s.add_development_dependency(%q<rspec>, ["~> 1.3.1"])
87
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.2.0.rc1"])
88
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
89
+ s.add_development_dependency(%q<rake>, ["~> 0.9.2"])
90
+ s.add_development_dependency(%q<rspec>, ["~> 1.3.2"])
111
91
  else
112
- s.add_dependency(%q<dm-core>, ["~> 1.1.0"])
113
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
114
- s.add_dependency(%q<rake>, ["~> 0.8.7"])
115
- s.add_dependency(%q<rspec>, ["~> 1.3.1"])
92
+ s.add_dependency(%q<dm-core>, ["~> 1.2.0.rc1"])
93
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
94
+ s.add_dependency(%q<rake>, ["~> 0.9.2"])
95
+ s.add_dependency(%q<rspec>, ["~> 1.3.2"])
116
96
  end
117
97
  else
118
- s.add_dependency(%q<dm-core>, ["~> 1.1.0"])
119
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
120
- s.add_dependency(%q<rake>, ["~> 0.8.7"])
121
- s.add_dependency(%q<rspec>, ["~> 1.3.1"])
98
+ s.add_dependency(%q<dm-core>, ["~> 1.2.0.rc1"])
99
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
100
+ s.add_dependency(%q<rake>, ["~> 0.9.2"])
101
+ s.add_dependency(%q<rspec>, ["~> 1.3.2"])
122
102
  end
123
103
  end
124
104
 
@@ -0,0 +1,144 @@
1
+ # Sample tasks using dm-migrations
2
+ # Roughly following Rails conventions, and mostly based on Padrino's dm:* tasks
3
+ #
4
+ # Cf. https://github.com/padrino/padrino-framework/blob/master/padrino-gen/lib/padrino-gen/padrino-tasks/datamapper.rb
5
+ # https://github.com/datamapper/dm-rails/blob/master/lib/dm-rails/railties/database.rake
6
+ #
7
+
8
+ require 'rake'
9
+
10
+ # replace this with however your app configures DataMapper repositor(ies)
11
+ task :environment do
12
+ require File.expand_path('boot', File.dirname(__FILE__))
13
+ end
14
+
15
+ namespace :db do
16
+
17
+ namespace :auto do
18
+
19
+ desc "Perform auto-migration (reset your db data)"
20
+ task :migrate => :environment do |t, _|
21
+ puts "=> Auto-migrating"
22
+ ::DataMapper.auto_migrate!
23
+ puts "<= #{t.name} done"
24
+ end
25
+
26
+ desc "Perform non destructive auto-migration"
27
+ task :upgrade => :environment do
28
+ puts "=> Auto-upgrading"
29
+ ::DataMapper.auto_upgrade!
30
+ puts "<= #{t.name} done"
31
+ end
32
+
33
+ end
34
+
35
+ desc "Run all pending migrations, or up to specified migration"
36
+ task :migrate, [:version] => :load_migrations do |t, args|
37
+ if vers = args[:version] || ENV['VERSION']
38
+ puts "=> Migrating up to version #{vers}"
39
+ migrate_up!(vers)
40
+ else
41
+ puts "=> Migrating up"
42
+ migrate_up!
43
+ end
44
+ puts "<= #{t.name} done"
45
+ end
46
+
47
+ desc "Rollback down to specified migration, or rollback last STEP=x migrations (default 1)"
48
+ task :rollback, [:version] => :load_migrations do |t, args|
49
+ if vers = args[:version] || ENV['VERSION']
50
+ puts "=> Rolling back down to migration #{vers}"
51
+ migrate_down!(vers)
52
+ else
53
+ step = ENV['STEP'].to_i || 1
54
+ applied = migrations.delete_if {|m| m.needs_up?}.sort # note this is N queries as currently implemented
55
+ target = applied[-1 * step] || applied[0]
56
+ if target
57
+ puts "=> Rolling back #{step} step(s)"
58
+ migrate_down!(target.position - 1)
59
+ else
60
+ warn "No migrations to rollback: #{step} step(s)"
61
+ end
62
+ end
63
+ puts "<= #{t.name} done"
64
+ end
65
+
66
+ desc "List migrations descending, showing which have been applied"
67
+ task :migrations => :load_migrations do
68
+ puts migrations.sort.reverse.map {|m| "#{m.position} #{m.name} #{m.needs_up? ? '' : 'APPLIED'}"}
69
+ end
70
+
71
+ task :load_migrations => :environment do
72
+ require 'dm-migrations/migration_runner'
73
+ FileList['db/migrate/*.rb'].each do |migration|
74
+ load migration
75
+ end
76
+ end
77
+
78
+
79
+ desc "Create the database"
80
+ task :create, [:repository] => :environment do |t, args|
81
+ repo = args[:repository] || ENV['REPOSITORY'] || :default
82
+ config = DataMapper.repository(repo).adapter.options.symbolize_keys
83
+ user, password, host = config[:user], config[:password], config[:host]
84
+ database = config[:database] || config[:path].sub(/\//, "")
85
+ charset = config[:charset] || ENV['CHARSET'] || 'utf8'
86
+ collation = config[:collation] || ENV['COLLATION'] || 'utf8_unicode_ci'
87
+ puts "=> Creating database '#{database}'"
88
+
89
+ case config[:adapter]
90
+ when 'postgres'
91
+ system("createdb", "-E", charset, "-h", host, "-U", user, database)
92
+ when 'mysql'
93
+ query = [
94
+ "mysql", "--user=#{user}", (password.blank? ? '' : "--password=#{password}"), (%w[127.0.0.1 localhost].include?(host) ? '-e' : "--host=#{host} -e"),
95
+ "CREATE DATABASE #{database} DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}".inspect
96
+ ]
97
+ system(query.compact.join(" "))
98
+ when 'sqlite3'
99
+ DataMapper.setup(DataMapper.repository.name, config)
100
+ else
101
+ raise "Adapter #{config[:adapter]} not supported for creating databases yet."
102
+ end
103
+ puts "<= #{t.name} done"
104
+ end
105
+
106
+ desc "Drop the database"
107
+ task :drop, [:repository] => :environment do |t, args|
108
+ repo = args[:repository] || ENV['REPOSITORY'] || :default
109
+ config = DataMapper.repository(repo).adapter.options.symbolize_keys
110
+ user, password, host = config[:user], config[:password], config[:host]
111
+ database = config[:database] || config[:path].sub(/\//, "")
112
+ puts "=> Dropping database '#{database}'"
113
+ case config[:adapter]
114
+ when 'postgres'
115
+ system("dropdb", "-h", host, "-U", user, database)
116
+ when 'mysql'
117
+ query = [
118
+ "mysql", "--user=#{user}", (password.blank? ? '' : "--password=#{password}"), (%w[127.0.0.1 localhost].include?(host) ? '-e' : "--host=#{host} -e"),
119
+ "DROP DATABASE IF EXISTS #{database}".inspect
120
+ ]
121
+ system(query.compact.join(" "))
122
+ when 'sqlite3'
123
+ File.delete(config[:path]) if File.exist?(config[:path])
124
+ else
125
+ raise "Adapter #{config[:adapter]} not supported for dropping databases yet."
126
+ end
127
+ puts "<= #{t.name} done"
128
+ end
129
+
130
+ desc 'Load the seed data from db/seeds.rb'
131
+ task :seed => :environment do |t, _|
132
+ puts "=> Loading seed data"
133
+ seed_file = File.expand_path('db/seeds.rb', File.dirname(__FILE__))
134
+ load(seed_file) if File.exist?(seed_file)
135
+ puts "<= #{t.name} done"
136
+ end
137
+
138
+ desc "Drop the database, migrate from scratch and initialize with the seed data"
139
+ task :reset => [:drop, :setup]
140
+
141
+ desc "Create the database, migrate and initialize with the seed data"
142
+ task :setup => [:create, :migrate, :seed]
143
+
144
+ end
@@ -41,7 +41,7 @@ end
41
41
  # property :id, Serial
42
42
  # property :name, String, :size => 50
43
43
  # property :age, Integer
44
- # property :dob, DateTime, :default => Time.now
44
+ # property :dob, DateTime, :default => proc { Time.now }
45
45
  #
46
46
  # end
47
47
  #
@@ -269,11 +269,11 @@ module DataMapper
269
269
  #
270
270
  # @api private
271
271
  def type_map
272
- length = Property::String::DEFAULT_LENGTH
273
- precision = Property::Numeric::DEFAULT_PRECISION
274
- scale = Property::Decimal::DEFAULT_SCALE
272
+ length = Property::String.length
273
+ precision = Property::Numeric.precision
274
+ scale = Property::Decimal.scale
275
275
 
276
- @type_map ||= {
276
+ {
277
277
  Property::Binary => { :primitive => 'BLOB' },
278
278
  Object => { :primitive => 'TEXT' },
279
279
  Integer => { :primitive => 'INTEGER' },
@@ -31,7 +31,14 @@ 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
34
+ # Allows for specification of the default storage engine to use when creating tables via
35
+ # migrations. Defaults to DEFAULT_ENGINE.
36
+ #
37
+ # adapter = DataMapper.setup(:default, 'mysql://localhost/foo')
38
+ # adapter.storage_engine = 'MyISAM'
39
+ #
40
+ # @api public
41
+ attr_accessor :storage_engine
35
42
 
36
43
  # @api private
37
44
  def supports_serial?
@@ -51,7 +58,7 @@ module DataMapper
51
58
 
52
59
  # @api private
53
60
  def create_table_statement(connection, model, properties)
54
- "#{super} ENGINE = #{DEFAULT_ENGINE} CHARACTER SET #{character_set} COLLATE #{collation}"
61
+ "#{super} ENGINE = #{storage_engine} CHARACTER SET #{character_set} COLLATE #{collation}"
55
62
  end
56
63
 
57
64
  # @api private
@@ -84,6 +91,13 @@ module DataMapper
84
91
  statement
85
92
  end
86
93
 
94
+ # @api private
95
+ def storage_engine
96
+ # Don't pull the default engine via show_variable for backwards compat where it was hard
97
+ # coded to InnoDB
98
+ @storage_engine ||= DEFAULT_ENGINE
99
+ end
100
+
87
101
  # @api private
88
102
  def character_set
89
103
  @character_set ||= show_variable('character_set_connection') || DEFAULT_CHARACTER_SET
@@ -97,7 +111,7 @@ module DataMapper
97
111
  # @api private
98
112
  def show_variable(name)
99
113
  result = select('SHOW VARIABLES LIKE ?', name).first
100
- result ? result.send(VALUE_METHOD).freeze : nil
114
+ result ? result.value.freeze : nil
101
115
  end
102
116
 
103
117
  private
@@ -273,7 +287,7 @@ module DataMapper
273
287
  #
274
288
  # @api private
275
289
  def type_map
276
- @type_map ||= super.merge(
290
+ super.merge(
277
291
  DateTime => { :primitive => 'DATETIME' },
278
292
  Time => { :primitive => 'DATETIME' }
279
293
  ).freeze
@@ -278,11 +278,11 @@ module DataMapper
278
278
  #
279
279
  # @api private
280
280
  def type_map
281
- length = Property::String::DEFAULT_LENGTH
282
- precision = Property::Numeric::DEFAULT_PRECISION
283
- scale = Property::Decimal::DEFAULT_SCALE
281
+ length = Property::String.length
282
+ precision = Property::Numeric.precision
283
+ scale = Property::Decimal.scale
284
284
 
285
- @type_map ||= {
285
+ {
286
286
  Integer => { :primitive => 'NUMBER', :precision => precision, :scale => 0 },
287
287
  String => { :primitive => 'VARCHAR2', :length => length },
288
288
  Class => { :primitive => 'VARCHAR2', :length => length },
@@ -143,10 +143,10 @@ module DataMapper
143
143
  #
144
144
  # @api private
145
145
  def type_map
146
- precision = Property::Numeric::DEFAULT_PRECISION
147
- scale = Property::Decimal::DEFAULT_SCALE
146
+ precision = Property::Numeric.precision
147
+ scale = Property::Decimal.scale
148
148
 
149
- @type_map ||= super.merge(
149
+ super.merge(
150
150
  Property::Binary => { :primitive => 'BYTEA' },
151
151
  BigDecimal => { :primitive => 'NUMERIC', :precision => precision, :scale => scale },
152
152
  Float => { :primitive => 'DOUBLE PRECISION' }
@@ -87,7 +87,7 @@ module DataMapper
87
87
  #
88
88
  # @api private
89
89
  def type_map
90
- @type_map ||= super.merge(Class => { :primitive => 'VARCHAR' }).freeze
90
+ super.merge(Class => { :primitive => 'VARCHAR' }).freeze
91
91
  end
92
92
  end
93
93
 
@@ -158,16 +158,16 @@ module DataMapper
158
158
  #
159
159
  # @api private
160
160
  def type_map
161
- length = Property::String::DEFAULT_LENGTH
162
- precision = Property::Numeric::DEFAULT_PRECISION
163
- scale = Property::Decimal::DEFAULT_SCALE
164
-
165
- @type_map ||= super.merge(
166
- DateTime => { :primitive => 'DATETIME' },
167
- Date => { :primitive => 'SMALLDATETIME' },
168
- Time => { :primitive => 'SMALLDATETIME' },
169
- TrueClass => { :primitive => 'BIT', },
170
- Property::Text => { :primitive => 'NVARCHAR', :length => 'max' }
161
+ length = Property::String.length
162
+ precision = Property::Numeric.precision
163
+ scale = Property::Decimal.scale
164
+
165
+ super.merge(
166
+ DateTime => { :primitive => 'DATETIME' },
167
+ Date => { :primitive => 'SMALLDATETIME' },
168
+ Time => { :primitive => 'SMALLDATETIME' },
169
+ TrueClass => { :primitive => 'BIT', },
170
+ Property::Text => { :primitive => 'NVARCHAR', :length => 'max' }
171
171
  ).freeze
172
172
  end
173
173
  end
@@ -41,8 +41,10 @@ module DataMapper
41
41
 
42
42
  # @api private
43
43
  def repository_execute(method, repository_name)
44
- DataMapper::Model.descendants.each do |model|
45
- model.send(method, repository_name || model.default_repository_name)
44
+ models = DataMapper::Model.descendants
45
+ models = models.select { |m| m.default_repository_name == repository_name } if repository_name
46
+ models.each do |model|
47
+ model.send(method, model.default_repository_name)
46
48
  end
47
49
  end
48
50
  end
@@ -21,8 +21,12 @@ module SQL
21
21
  true
22
22
  end
23
23
 
24
- def table_options
25
- " ENGINE = InnoDB CHARACTER SET #{character_set} COLLATE #{collation}"
24
+ def table_options(opts)
25
+ opt_engine = opts[:storage_engine] || storage_engine
26
+ opt_char_set = opts[:character_set] || character_set
27
+ opt_collation = opts[:collation] || collation
28
+
29
+ " ENGINE = #{opt_engine} CHARACTER SET #{opt_char_set} COLLATE #{opt_collation}"
26
30
  end
27
31
 
28
32
  def property_schema_statement(connection, schema)
@@ -32,12 +32,12 @@ module SQL
32
32
  statement
33
33
  end
34
34
 
35
- def table_options
35
+ def table_options(opts)
36
36
  ''
37
37
  end
38
38
 
39
39
  def change_column_type_statement(name, column)
40
- "ALTER TABLE #{quote_name(name)} ALTER COLUMN #{quote_name(name)} TYPE #{column.to_sql}"
40
+ "ALTER TABLE #{quote_name(name)} ALTER COLUMN #{column.to_sql}"
41
41
  end
42
42
 
43
43
  class Table < SQL::Table
@@ -19,7 +19,7 @@ module SQL
19
19
  # do nothing, sqlite will automatically create the database file
20
20
  end
21
21
 
22
- def table_options
22
+ def table_options(opts)
23
23
  ''
24
24
  end
25
25
 
@@ -26,7 +26,7 @@ module SQL
26
26
  end
27
27
 
28
28
  def to_sql
29
- "CREATE TABLE #{quoted_table_name} (#{@columns.map{ |c| c.to_sql }.join(', ')})#{@adapter.table_options}"
29
+ "CREATE TABLE #{quoted_table_name} (#{@columns.map{ |c| c.to_sql }.join(', ')})#{@adapter.table_options(@opts)}"
30
30
  end
31
31
 
32
32
  # A helper for using the native NOW() SQL function in a default
@@ -49,5 +49,9 @@ module SQL
49
49
  def quoted_table_name
50
50
  @adapter.send(:quote_name, table_name)
51
51
  end
52
+
53
+ def to_sql
54
+ @statements.join(';')
55
+ end
52
56
  end
53
57
  end
@@ -368,7 +368,7 @@ describe DataMapper::Migrations do
368
368
  [ :min, :max ].each do |key|
369
369
  next unless value = options[key]
370
370
  it "should allow the #{key} value #{value} to be stored" do
371
- pending_if "#{value} causes problem with JRuby 1.5.2 parser", RUBY_PLATFORM =~ /java/ && value == -9223372036854775808 do
371
+ pending_if "#{value} causes problem with the JRuby < 1.6 parser", RUBY_PLATFORM =~ /java/ && JRUBY_VERSION < '1.6' && value == -9223372036854775808 do
372
372
  lambda {
373
373
  resource = @model.create(@property => value)
374
374
  @model.first(@property => value).should eql(resource)
@@ -14,6 +14,14 @@ describe "A Migration" do
14
14
  @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
15
15
  end
16
16
 
17
+ before do
18
+ $stderr, @original = StringIO.new, $stderr
19
+ end
20
+
21
+ after do
22
+ $stderr = @original
23
+ end
24
+
17
25
  it "should have a postition attribute" do
18
26
  @migration.should respond_to(:position)
19
27
 
@@ -42,6 +50,11 @@ describe "A Migration" do
42
50
  m.instance_variable_get(:@repository).should == :legacy
43
51
  end
44
52
 
53
+ it "warns when :database is used" do
54
+ m = DataMapper::Migration.new(2, :create_legacy_table, :database => :legacy) {}
55
+ $stderr.string.chomp.should == 'Using the :database option with migrations is deprecated, use :repository instead'
56
+ end
57
+
45
58
  it "should have a verbose option" do
46
59
  m = DataMapper::Migration.new(2, :create_dogs_table, :verbose => false) {}
47
60
  m.instance_variable_get(:@verbose).should == false
@@ -70,6 +70,34 @@ describe "SQL generation" do
70
70
  #can't get an exact == comparison here because character set and collation may differ per connection
71
71
  @creator.to_sql.should match(/^CREATE TABLE `people` \(`id` SERIAL PRIMARY KEY, `name` VARCHAR\(50\) NOT NULL, `long_string` VARCHAR\(200\)\) ENGINE = InnoDB CHARACTER SET \w+ COLLATE \w+\z/)
72
72
  end
73
+
74
+ it "should allow for custom table creation options for MySQL" do
75
+ opts = {
76
+ :storage_engine => 'MyISAM',
77
+ :character_set => 'big5',
78
+ :collation => 'big5_chinese_ci',
79
+ }
80
+
81
+ creator = DataMapper::Migration::TableCreator.new(@adapter, :people, opts) do
82
+ column :id, DataMapper::Property::Serial
83
+ end
84
+
85
+ creator.to_sql.should match(/^CREATE TABLE `people` \(`id` SERIAL PRIMARY KEY\) ENGINE = MyISAM CHARACTER SET big5 COLLATE big5_chinese_ci\z/)
86
+ end
87
+
88
+ it "should respect default storage engine types specified by the MySQL adapter" do
89
+ adapter = DataMapper::Spec.adapter
90
+ adapter.extend(SQL::Mysql)
91
+
92
+ adapter.storage_engine = 'MyISAM'
93
+
94
+ creator = DataMapper::Migration::TableCreator.new(adapter, :people) do
95
+ column :id, DataMapper::Property::Serial
96
+ end
97
+
98
+ creator.to_sql.should match(/^CREATE TABLE `people` \(`id` SERIAL PRIMARY KEY\) ENGINE = MyISAM CHARACTER SET \w+ COLLATE \w+\z/)
99
+ end
100
+
73
101
  when :postgres
74
102
  it "should output a CREATE TABLE statement when sent #to_sql" do
75
103
  @creator.to_sql.should == %q{CREATE TABLE "people" ("id" SERIAL PRIMARY KEY, "name" VARCHAR(50) NOT NULL, "long_string" VARCHAR(200))}
@@ -79,17 +107,49 @@ describe "SQL generation" do
79
107
  @creator.to_sql.should == %q{CREATE TABLE "people" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50) NOT NULL, "long_string" VARCHAR(200))}
80
108
  end
81
109
  end
110
+
111
+ context 'when the default string length is modified' do
112
+ before do
113
+ @original = DataMapper::Property::String.length
114
+ DataMapper::Property::String.length(255)
115
+
116
+ @creator = DataMapper::Migration::TableCreator.new(@adapter, :people) do
117
+ column :string, String
118
+ end
119
+ end
120
+
121
+ after do
122
+ DataMapper::Property::String.length(@original)
123
+ end
124
+
125
+ it 'uses the new length for the character column' do
126
+ @creator.to_sql.should match(/CHAR\(255\)/)
127
+ end
128
+ end
82
129
  end
83
130
 
84
131
  describe DataMapper::Migration, "#modify_table helper" do
85
132
  before do
86
133
  @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
134
+
87
135
  end
88
136
 
89
137
  it "should have a #modify_table helper" do
90
138
  @migration.should respond_to(:modify_table)
91
139
  end
92
140
 
141
+ case DataMapper::Spec.adapter_name.to_sym
142
+ when :postgres
143
+ before do
144
+ @modifier = DataMapper::Migration::TableModifier.new(@adapter, :people) do
145
+ change_column :name, 'VARCHAR(200)'
146
+ end
147
+ end
148
+
149
+ it "should alter the column" do
150
+ @modifier.to_sql.should == %q{ALTER TABLE "people" ALTER COLUMN "name" VARCHAR(200)}
151
+ end
152
+ end
93
153
  end
94
154
 
95
155
  describe DataMapper::Migration, "other helpers" do
metadata CHANGED
@@ -1,8 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-migrations
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.1.0
4
+ hash: 15424023
5
+ prerelease: 6
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 0
10
+ - rc
11
+ - 1
12
+ version: 1.2.0.rc1
6
13
  platform: ruby
7
14
  authors:
8
15
  - Paul Sadauskas
@@ -10,53 +17,74 @@ autorequire:
10
17
  bindir: bin
11
18
  cert_chain: []
12
19
 
13
- date: 2011-03-16 00:00:00 -07:00
14
- default_executable:
20
+ date: 2011-09-09 00:00:00 Z
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
- name: dm-core
18
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ type: :runtime
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
19
25
  none: false
20
26
  requirements:
21
27
  - - ~>
22
28
  - !ruby/object:Gem::Version
23
- version: 1.1.0
24
- type: :runtime
29
+ hash: 15424023
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 0
34
+ - rc
35
+ - 1
36
+ version: 1.2.0.rc1
25
37
  prerelease: false
26
- version_requirements: *id001
38
+ requirement: *id001
39
+ name: dm-core
27
40
  - !ruby/object:Gem::Dependency
28
- name: jeweler
29
- requirement: &id002 !ruby/object:Gem::Requirement
41
+ type: :development
42
+ version_requirements: &id002 !ruby/object:Gem::Requirement
30
43
  none: false
31
44
  requirements:
32
45
  - - ~>
33
46
  - !ruby/object:Gem::Version
34
- version: 1.5.2
35
- type: :development
47
+ hash: 7
48
+ segments:
49
+ - 1
50
+ - 6
51
+ - 4
52
+ version: 1.6.4
36
53
  prerelease: false
37
- version_requirements: *id002
54
+ requirement: *id002
55
+ name: jeweler
38
56
  - !ruby/object:Gem::Dependency
39
- name: rake
40
- requirement: &id003 !ruby/object:Gem::Requirement
57
+ type: :development
58
+ version_requirements: &id003 !ruby/object:Gem::Requirement
41
59
  none: false
42
60
  requirements:
43
61
  - - ~>
44
62
  - !ruby/object:Gem::Version
45
- version: 0.8.7
46
- type: :development
63
+ hash: 63
64
+ segments:
65
+ - 0
66
+ - 9
67
+ - 2
68
+ version: 0.9.2
47
69
  prerelease: false
48
- version_requirements: *id003
70
+ requirement: *id003
71
+ name: rake
49
72
  - !ruby/object:Gem::Dependency
50
- name: rspec
51
- requirement: &id004 !ruby/object:Gem::Requirement
73
+ type: :development
74
+ version_requirements: &id004 !ruby/object:Gem::Requirement
52
75
  none: false
53
76
  requirements:
54
77
  - - ~>
55
78
  - !ruby/object:Gem::Version
56
- version: 1.3.1
57
- type: :development
79
+ hash: 31
80
+ segments:
81
+ - 1
82
+ - 3
83
+ - 2
84
+ version: 1.3.2
58
85
  prerelease: false
59
- version_requirements: *id004
86
+ requirement: *id004
87
+ name: rspec
60
88
  description: DataMapper plugin for writing and speccing migrations
61
89
  email: psadauskas [a] gmail [d] com
62
90
  executables: []
@@ -76,6 +104,7 @@ files:
76
104
  - db/migrations/2_add_dob_to_people.rb
77
105
  - db/migrations/config.rb
78
106
  - dm-migrations.gemspec
107
+ - examples/Rakefile
79
108
  - examples/sample_migration.rb
80
109
  - examples/sample_migration_spec.rb
81
110
  - lib/dm-migrations.rb
@@ -122,7 +151,6 @@ files:
122
151
  - tasks/spec.rake
123
152
  - tasks/yard.rake
124
153
  - tasks/yardstick.rake
125
- has_rdoc: true
126
154
  homepage: http://github.com/datamapper/dm-migrations
127
155
  licenses: []
128
156
 
@@ -136,37 +164,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
164
  requirements:
137
165
  - - ">="
138
166
  - !ruby/object:Gem::Version
167
+ hash: 3
168
+ segments:
169
+ - 0
139
170
  version: "0"
140
171
  required_rubygems_version: !ruby/object:Gem::Requirement
141
172
  none: false
142
173
  requirements:
143
- - - ">="
174
+ - - ">"
144
175
  - !ruby/object:Gem::Version
145
- version: "0"
176
+ hash: 25
177
+ segments:
178
+ - 1
179
+ - 3
180
+ - 1
181
+ version: 1.3.1
146
182
  requirements: []
147
183
 
148
184
  rubyforge_project: datamapper
149
- rubygems_version: 1.6.2
185
+ rubygems_version: 1.8.10
150
186
  signing_key:
151
187
  specification_version: 3
152
188
  summary: DataMapper plugin for writing and speccing migrations
153
- test_files:
154
- - examples/sample_migration.rb
155
- - examples/sample_migration_spec.rb
156
- - spec/integration/auto_migration_spec.rb
157
- - spec/integration/auto_upgrade_spec.rb
158
- - spec/integration/migration_runner_spec.rb
159
- - spec/integration/migration_spec.rb
160
- - spec/integration/sql_spec.rb
161
- - spec/isolated/require_after_setup_spec.rb
162
- - spec/isolated/require_before_setup_spec.rb
163
- - spec/isolated/require_spec.rb
164
- - spec/spec_helper.rb
165
- - spec/unit/migration_spec.rb
166
- - spec/unit/sql/column_spec.rb
167
- - spec/unit/sql/postgres_spec.rb
168
- - spec/unit/sql/sqlite_extensions_spec.rb
169
- - spec/unit/sql/table_creator_spec.rb
170
- - spec/unit/sql/table_modifier_spec.rb
171
- - spec/unit/sql/table_spec.rb
172
- - spec/unit/sql_spec.rb
189
+ test_files: []
190
+