dm-migrations 0.9.11 → 0.10.0

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.
Files changed (39) hide show
  1. data/{History.txt → History.rdoc} +4 -6
  2. data/Manifest.txt +12 -12
  3. data/{README.txt → README.rdoc} +0 -0
  4. data/Rakefile +2 -3
  5. data/db/migrations/1_create_people_table.rb +3 -3
  6. data/examples/sample_migration.rb +7 -10
  7. data/examples/sample_migration_spec.rb +6 -2
  8. data/lib/dm-migrations.rb +1 -1
  9. data/lib/{migration.rb → dm-migrations/migration.rb} +5 -7
  10. data/lib/{migration_runner.rb → dm-migrations/migration_runner.rb} +4 -4
  11. data/lib/dm-migrations/sql.rb +5 -0
  12. data/lib/{sql → dm-migrations/sql}/column.rb +0 -4
  13. data/lib/{sql → dm-migrations/sql}/mysql.rb +5 -8
  14. data/lib/{sql → dm-migrations/sql}/postgresql.rb +7 -11
  15. data/lib/{sql → dm-migrations/sql}/sqlite3.rb +3 -5
  16. data/lib/{sql → dm-migrations/sql}/table.rb +1 -5
  17. data/lib/{sql → dm-migrations/sql}/table_creator.rb +28 -15
  18. data/lib/{sql → dm-migrations/sql}/table_modifier.rb +2 -4
  19. data/lib/dm-migrations/version.rb +1 -1
  20. data/lib/spec/example/migration_example_group.rb +2 -2
  21. data/lib/spec/matchers/migration_matchers.rb +0 -1
  22. data/spec/integration/migration_runner_spec.rb +1 -2
  23. data/spec/integration/migration_spec.rb +1 -2
  24. data/spec/integration/sql_spec.rb +11 -7
  25. data/spec/spec.opts +1 -0
  26. data/spec/spec_helper.rb +10 -6
  27. data/spec/unit/migration_spec.rb +11 -14
  28. data/spec/unit/sql/column_spec.rb +1 -4
  29. data/spec/unit/sql/postgresql_spec.rb +1 -4
  30. data/spec/unit/sql/sqlite3_extensions_spec.rb +1 -4
  31. data/spec/unit/sql/table_creator_spec.rb +7 -7
  32. data/spec/unit/sql/table_modifier_spec.rb +3 -6
  33. data/spec/unit/sql/table_spec.rb +1 -4
  34. data/spec/unit/sql_spec.rb +1 -4
  35. data/tasks/db.rb +1 -1
  36. data/tasks/install.rb +1 -1
  37. data/tasks/spec.rb +4 -4
  38. metadata +24 -31
  39. data/lib/sql.rb +0 -10
@@ -1,12 +1,10 @@
1
- === 0.9.11 / 2009-03-29
2
-
3
- * 1 minor enhancement:
1
+ === 0.10.0 / 2009-10-15
4
2
 
5
- * Updated default MySQL engine to InnoDB
3
+ * Updated to work with dm-core 0.10.0
6
4
 
7
- * 1 bug fix:
5
+ === 0.9.11 / 2009-03-29
8
6
 
9
- * Fix :nullable for columns
7
+ * No changes this version
10
8
 
11
9
  === 0.9.10 / 2009-01-19
12
10
 
data/Manifest.txt CHANGED
@@ -1,7 +1,7 @@
1
- History.txt
1
+ History.rdoc
2
2
  LICENSE
3
3
  Manifest.txt
4
- README.txt
4
+ README.rdoc
5
5
  Rakefile
6
6
  TODO
7
7
  db/migrations/1_create_people_table.rb
@@ -10,19 +10,19 @@ db/migrations/config.rb
10
10
  examples/sample_migration.rb
11
11
  examples/sample_migration_spec.rb
12
12
  lib/dm-migrations.rb
13
+ lib/dm-migrations/migration.rb
14
+ lib/dm-migrations/migration_runner.rb
15
+ lib/dm-migrations/sql.rb
16
+ lib/dm-migrations/sql/column.rb
17
+ lib/dm-migrations/sql/mysql.rb
18
+ lib/dm-migrations/sql/postgresql.rb
19
+ lib/dm-migrations/sql/sqlite3.rb
20
+ lib/dm-migrations/sql/table.rb
21
+ lib/dm-migrations/sql/table_creator.rb
22
+ lib/dm-migrations/sql/table_modifier.rb
13
23
  lib/dm-migrations/version.rb
14
- lib/migration.rb
15
- lib/migration_runner.rb
16
24
  lib/spec/example/migration_example_group.rb
17
25
  lib/spec/matchers/migration_matchers.rb
18
- lib/sql.rb
19
- lib/sql/column.rb
20
- lib/sql/mysql.rb
21
- lib/sql/postgresql.rb
22
- lib/sql/sqlite3.rb
23
- lib/sql/table.rb
24
- lib/sql/table_creator.rb
25
- lib/sql/table_modifier.rb
26
26
  spec/integration/migration_runner_spec.rb
27
27
  spec/integration/migration_spec.rb
28
28
  spec/integration/sql_spec.rb
File without changes
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'pathname'
2
- require 'rubygems'
3
2
 
4
3
  ROOT = Pathname(__FILE__).dirname.expand_path
5
4
  JRUBY = RUBY_PLATFORM =~ /java/
@@ -14,10 +13,10 @@ GEM_NAME = 'dm-migrations'
14
13
  GEM_VERSION = DataMapper::Migration::VERSION
15
14
  GEM_DEPENDENCIES = [['dm-core', GEM_VERSION]]
16
15
  GEM_CLEAN = %w[ log pkg coverage ]
17
- GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO History.txt ] }
16
+ GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.rdoc LICENSE TODO History.rdoc ] }
18
17
 
19
18
  PROJECT_NAME = 'datamapper'
20
- PROJECT_URL = "http://github.com/sam/dm-more/tree/master/#{GEM_NAME}"
19
+ PROJECT_URL = "http://github.com/datamapper/dm-more/tree/master/#{GEM_NAME}"
21
20
  PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'DataMapper plugin for writing and speccing migrations'
22
21
 
23
22
  [ ROOT, ROOT.parent ].each do |dir|
@@ -1,9 +1,9 @@
1
1
  migration 1, :create_people_table do
2
2
  up do
3
3
  create_table :people do
4
- column :id, Integer, :serial => true
5
- column :name, String, :size => 50
6
- column :age, Integer
4
+ column :id, Integer, :serial => true
5
+ column :name, String, :size => 50
6
+ column :age, Integer
7
7
  end
8
8
  end
9
9
  down do
@@ -1,9 +1,6 @@
1
- require File.dirname(__FILE__) + '/../lib/migration_runner'
2
- require 'fileutils'
3
- FileUtils.touch(File.join(Dir.pwd, "migration_test.db"))
4
- # DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/migration_test.db")
5
- DataMapper.setup(:default, "postgres://localhost/migration_test")
6
- # DataMapper.setup(:default, "mysql://localhost/migration_test")
1
+ require 'dm-migrations/migration_runner'
2
+
3
+ DataMapper.setup(:default, "sqlite3::memory")
7
4
 
8
5
  DataMapper::Logger.new(STDOUT, :debug)
9
6
  DataMapper.logger.debug( "Starting Migration" )
@@ -11,9 +8,9 @@ DataMapper.logger.debug( "Starting Migration" )
11
8
  migration 1, :create_people_table do
12
9
  up do
13
10
  create_table :people do
14
- column :id, Integer, :serial => true
15
- column :name, String, :size => 50
16
- column :age, Integer
11
+ column :id, Integer, :serial => true
12
+ column :name, String, :size => 50
13
+ column :age, Integer
17
14
  end
18
15
  end
19
16
  down do
@@ -41,7 +38,7 @@ end
41
38
  # class Person
42
39
  # include DataMapper::Resource
43
40
  #
44
- # property :id, Integer, :serial => true
41
+ # property :id, Serial
45
42
  # property :name, String, :size => 50
46
43
  # property :age, Integer
47
44
  # property :dob, DateTime, :default => Time.now
@@ -1,5 +1,9 @@
1
- require File.dirname(__FILE__) + '/sample_migration'
2
- require File.dirname(__FILE__) + '/../lib/spec/example/migration_example_group'
1
+ require 'pathname'
2
+
3
+ dir = Pathname(__FILE__).dirname.expand_path
4
+
5
+ require dir + 'sample_migration'
6
+ require dir + '../lib/spec/example/migration_example_group'
3
7
 
4
8
  describe :create_people_table, :type => :migration do
5
9
 
data/lib/dm-migrations.rb CHANGED
@@ -1 +1 @@
1
- require File.dirname(__FILE__) + '/migration'
1
+ require 'dm-migrations/migration'
@@ -1,8 +1,6 @@
1
- require 'rubygems'
2
- gem 'dm-core', '0.9.11'
3
- require 'dm-core'
4
1
  require 'benchmark'
5
- require File.dirname(__FILE__) + '/sql'
2
+
3
+ require 'dm-migrations/sql'
6
4
 
7
5
  module DataMapper
8
6
  class DuplicateMigrationNameError < StandardError
@@ -91,7 +89,7 @@ module DataMapper
91
89
  end
92
90
 
93
91
  def drop_table(table_name, opts = {})
94
- execute "DROP TABLE #{@adapter.send(:quote_table_name, table_name.to_s)}"
92
+ execute "DROP TABLE #{@adapter.send(:quote_name, table_name.to_s)}"
95
93
  end
96
94
 
97
95
  def modify_table(table_name, opts = {}, &block)
@@ -206,12 +204,12 @@ module DataMapper
206
204
 
207
205
  def quote_table_name(table_name)
208
206
  # TODO: Fix this for 1.9 - can't use this hack to access a private method
209
- @adapter.send(:quote_table_name, table_name.to_s)
207
+ @adapter.send(:quote_name, table_name.to_s)
210
208
  end
211
209
 
212
210
  def quote_column_name(column_name)
213
211
  # TODO: Fix this for 1.9 - can't use this hack to access a private method
214
- @adapter.send(:quote_column_name, column_name.to_s)
212
+ @adapter.send(:quote_name, column_name.to_s)
215
213
  end
216
214
  end
217
215
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/migration'
1
+ require 'dm-migrations/migration'
2
2
 
3
3
  module DataMapper
4
4
  module MigrationRunner
@@ -26,9 +26,9 @@ module DataMapper
26
26
  # migration( 1, :create_people_table ) do
27
27
  # up do
28
28
  # create_table :people do
29
- # column :id, Integer, :serial => true
30
- # column :name, String, :size => 50
31
- # column :age, Integer
29
+ # column :id, Integer, :serial => true
30
+ # column :name, String, :size => 50
31
+ # column :age, Integer
32
32
  # end
33
33
  # end
34
34
  # down do
@@ -0,0 +1,5 @@
1
+ require 'dm-migrations/sql/table_creator'
2
+ require 'dm-migrations/sql/table_modifier'
3
+ require 'dm-migrations/sql/sqlite3'
4
+ require 'dm-migrations/sql/mysql'
5
+ require 'dm-migrations/sql/postgresql'
@@ -1,9 +1,5 @@
1
1
  module SQL
2
-
3
2
  class Column
4
-
5
3
  attr_accessor :name, :type, :not_null, :default_value, :primary_key, :unique
6
-
7
4
  end
8
-
9
5
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/table'
1
+ require 'dm-migrations/sql/table'
2
2
 
3
3
  module SQL
4
4
  module Mysql
@@ -21,14 +21,13 @@ module SQL
21
21
  true
22
22
  end
23
23
 
24
- def create_table_statement(quoted_table_name)
25
- "CREATE TABLE #{quoted_table_name} ENGINE = InnoDB CHARACTER SET #{character_set} COLLATE #{collation}"
24
+ def table_options
25
+ " ENGINE = InnoDB CHARACTER SET #{character_set} COLLATE #{collation}"
26
26
  end
27
27
 
28
- # TODO: move to dm-more/dm-migrations
29
- def property_schema_statement(schema)
28
+ def property_schema_statement(connection, schema)
30
29
  if supports_serial? && schema[:serial]
31
- statement = "#{schema[:quote_column_name]} serial PRIMARY KEY"
30
+ statement = "#{schema[:quote_column_name]} SERIAL PRIMARY KEY"
32
31
  else
33
32
  super
34
33
  end
@@ -50,7 +49,5 @@ module SQL
50
49
  @not_null = col_struct.notnull == 0
51
50
  end
52
51
  end
53
-
54
-
55
52
  end
56
53
  end
@@ -10,18 +10,18 @@ module SQL
10
10
  end
11
11
 
12
12
  def recreate_database
13
- execute "DROP SCHEMA IF EXISTS test CASCADE"
14
- execute "CREATE SCHEMA test"
15
- execute "SET search_path TO test"
13
+ execute 'DROP SCHEMA IF EXISTS test CASCADE'
14
+ execute 'CREATE SCHEMA test'
15
+ execute 'SET search_path TO test'
16
16
  end
17
17
 
18
18
  def supports_serial?
19
19
  true
20
20
  end
21
21
 
22
- def property_schema_statement(schema)
22
+ def property_schema_statement(connection, schema)
23
23
  if supports_serial? && schema[:serial]
24
- statement = "#{schema[:quote_column_name]} serial PRIMARY KEY"
24
+ statement = "#{schema[:quote_column_name]} SERIAL PRIMARY KEY"
25
25
  else
26
26
  statement = super
27
27
  if schema.has_key?(:sequence_name)
@@ -32,8 +32,8 @@ module SQL
32
32
  statement
33
33
  end
34
34
 
35
- def create_table_statement(quoted_table_name)
36
- "CREATE TABLE #{quoted_table_name}"
35
+ def table_options
36
+ ''
37
37
  end
38
38
 
39
39
  class Table < SQL::Table
@@ -64,9 +64,7 @@ module SQL
64
64
  end
65
65
  end
66
66
  end
67
-
68
67
  end
69
-
70
68
  end
71
69
 
72
70
  class Column < SQL::Column
@@ -75,8 +73,6 @@ module SQL
75
73
 
76
74
  @not_null = col_struct.is_nullable != "YES"
77
75
  end
78
-
79
76
  end
80
-
81
77
  end
82
78
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/table'
1
+ require 'dm-migrations/sql/table'
2
2
 
3
3
  module SQL
4
4
  module Sqlite3
@@ -17,8 +17,8 @@ module SQL
17
17
  # do nothing, sqlite will automatically create the database file
18
18
  end
19
19
 
20
- def create_table_statement(quoted_table_name)
21
- "CREATE TABLE #{quoted_table_name}"
20
+ def table_options
21
+ ''
22
22
  end
23
23
 
24
24
  def supports_serial?
@@ -41,7 +41,5 @@ module SQL
41
41
  @not_null = col_struct.notnull == 0
42
42
  end
43
43
  end
44
-
45
-
46
44
  end
47
45
  end
@@ -1,9 +1,7 @@
1
- require File.dirname(__FILE__) + '/column'
1
+ require 'dm-migrations/sql/column'
2
2
 
3
3
  module SQL
4
-
5
4
  class Table
6
-
7
5
  attr_accessor :name, :columns
8
6
 
9
7
  def to_s
@@ -13,7 +11,5 @@ module SQL
13
11
  def column(column_name)
14
12
  @columns.select { |c| c.name == column_name.to_s }.first
15
13
  end
16
-
17
14
  end
18
-
19
15
  end
@@ -13,7 +13,7 @@ module SQL
13
13
  end
14
14
 
15
15
  def quoted_table_name
16
- @adapter.send(:quote_table_name, table_name)
16
+ @adapter.send(:quote_name, table_name)
17
17
  end
18
18
 
19
19
  def column(name, type, opts = {})
@@ -21,7 +21,7 @@ module SQL
21
21
  end
22
22
 
23
23
  def to_sql
24
- "#{@adapter.create_table_statement(quoted_table_name)} (#{@columns.map{ |c| c.to_sql }.join(', ')})"
24
+ "CREATE TABLE #{quoted_table_name} (#{@columns.map{ |c| c.to_sql }.join(', ')})#{@adapter.table_options}"
25
25
  end
26
26
 
27
27
  # A helper for using the native NOW() SQL function in a default
@@ -55,29 +55,42 @@ module SQL
55
55
  @type = build_type(type)
56
56
  end
57
57
 
58
+ def to_sql
59
+ type
60
+ end
61
+
62
+ private
63
+
58
64
  def build_type(type_class)
59
- schema = {:name => @name, :quote_column_name => quoted_name}.merge(@opts)
60
- schema[:serial?] ||= schema[:serial]
61
- unless schema.has_key?(:nullable?)
62
- schema[:nullable?] = schema.has_key?(:nullable) ? schema[:nullable] : !schema[:not_null]
65
+ schema = { :name => @name, :quote_column_name => quoted_name }.merge(@opts)
66
+
67
+ unless schema.key?(:nullable)
68
+ schema[:nullable] = !schema[:not_null]
63
69
  end
64
- if type_class.is_a?(String)
70
+
71
+ schema[:length] ||= schema.delete(:size) if schema.key?(:size)
72
+
73
+ if type_class.kind_of?(String)
65
74
  schema[:primitive] = type_class
66
75
  else
67
- schema = @adapter.class.type_map[type_class].merge(schema)
76
+ primitive = type_class.respond_to?(:primitive) ? type_class.primitive : type_class
77
+ options = @adapter.class.type_map[primitive].dup
78
+
79
+ if type_class.respond_to?(:options)
80
+ options.update(type_class.options)
81
+ end
82
+
83
+ schema = options.update(schema)
68
84
  end
69
- @adapter.property_schema_statement(schema)
70
- end
71
85
 
72
- def to_sql
73
- type
86
+ @adapter.send(:with_connection) do |connection|
87
+ @adapter.property_schema_statement(connection, schema)
88
+ end
74
89
  end
75
90
 
76
91
  def quoted_name
77
- @adapter.send(:quote_column_name, name)
92
+ @adapter.send(:quote_name, name)
78
93
  end
79
94
  end
80
-
81
95
  end
82
-
83
96
  end
@@ -41,13 +41,11 @@ module SQL
41
41
  end
42
42
 
43
43
  def quote_column_name(name)
44
- @adapter.send(:quote_column_name, name.to_s)
44
+ @adapter.send(:quote_name, name.to_s)
45
45
  end
46
46
 
47
47
  def quoted_table_name
48
- @adapter.send(:quote_table_name, table_name)
48
+ @adapter.send(:quote_name, table_name)
49
49
  end
50
-
51
50
  end
52
-
53
51
  end
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  class Migration
3
- VERSION = '0.9.11'
3
+ VERSION = '0.10.0'.freeze
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
- require 'spec'
1
+ require 'spec/matchers/migration_matchers'
2
2
 
3
- require File.dirname(__FILE__) + '/../matchers/migration_matchers'
3
+ require 'spec'
4
4
 
5
5
  module Spec
6
6
  module Example
@@ -1,4 +1,3 @@
1
-
2
1
  module Spec
3
2
  module Matchers
4
3
  module Migration
@@ -1,5 +1,4 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
1
+ require 'spec_helper'
3
2
 
4
3
  ADAPTERS.each do |adapter|
5
4
  describe "Using Adapter #{adapter}, " do
@@ -1,5 +1,4 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
1
+ require 'spec_helper'
3
2
 
4
3
  ADAPTERS.each do |adapter|
5
4
  describe "Using Adapter #{adapter}, " do
@@ -1,8 +1,12 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
1
+ require 'spec_helper'
3
2
 
4
3
  ADAPTERS.each do |adapter|
5
4
  describe "Using Adapter #{adapter}," do
5
+
6
+ def repository(*args)
7
+ DataMapper.repository(*args)
8
+ end
9
+
6
10
  describe DataMapper::Migration, "#create_table helper" do
7
11
  before :all do
8
12
  case adapter
@@ -14,8 +18,8 @@ ADAPTERS.each do |adapter|
14
18
 
15
19
  before do
16
20
  @creator = DataMapper::Migration::TableCreator.new(repository(adapter).adapter, :people) do
17
- column :id, Integer, :serial => true
18
- column :name, 'varchar(50)', :nullable => false
21
+ column :id, DataMapper::Types::Serial
22
+ column :name, 'VARCHAR(50)', :nullable => false
19
23
  column :long_string, String, :size => 200
20
24
  end
21
25
  end
@@ -62,15 +66,15 @@ ADAPTERS.each do |adapter|
62
66
  when :mysql
63
67
  it "should create an InnoDB database for MySQL" do
64
68
  #can't get an exact == comparison here because character set and collation may differ per connection
65
- @creator.to_sql.should match(/^CREATE TABLE `people` ENGINE = InnoDB CHARACTER SET \w+ COLLATE \w+ \(`id` serial PRIMARY KEY, `name` varchar\(50\) NOT NULL, `long_string` VARCHAR\(200\)\)$/)
69
+ @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/)
66
70
  end
67
71
  when :postgres
68
72
  it "should output a CREATE TABLE statement when sent #to_sql" do
69
- @creator.to_sql.should == %q{CREATE TABLE "people" ("id" serial PRIMARY KEY, "name" varchar(50) NOT NULL, "long_string" VARCHAR(200))}
73
+ @creator.to_sql.should == %q{CREATE TABLE "people" ("id" SERIAL PRIMARY KEY, "name" VARCHAR(50) NOT NULL, "long_string" VARCHAR(200))}
70
74
  end
71
75
  when :sqlite3
72
76
  it "should output a CREATE TABLE statement when sent #to_sql" do
73
- @creator.to_sql.should == %q{CREATE TABLE "people" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" varchar(50) NOT NULL, "long_string" VARCHAR(200))}
77
+ @creator.to_sql.should == %q{CREATE TABLE "people" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50) NOT NULL, "long_string" VARCHAR(200))}
74
78
  end
75
79
  end
76
80
  end
data/spec/spec.opts CHANGED
@@ -1 +1,2 @@
1
1
  --colour
2
+ --loadby random
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,15 @@
1
- require 'pathname'
2
1
  require 'rubygems'
3
2
 
4
- gem 'rspec', '~>1.2'
5
- require 'spec'
3
+ # use local dm-core if running from a typical dev checkout.
4
+ lib = File.join('..', '..', 'dm-core', 'lib')
5
+ $LOAD_PATH.unshift(lib) if File.directory?(lib)
6
+ require 'dm-core'
6
7
 
7
- require Pathname(__FILE__).dirname.parent.expand_path + 'lib/dm-migrations'
8
- require Pathname(__FILE__).dirname.parent.expand_path + 'lib/migration_runner'
8
+ # Support running specs with 'rake spec' and 'spec'
9
+ $LOAD_PATH.unshift('lib') unless $LOAD_PATH.include?('lib')
10
+
11
+ require 'dm-migrations'
12
+ require 'dm-migrations/migration_runner'
9
13
 
10
14
  ADAPTERS = []
11
15
  def load_driver(name, default_uri)
@@ -20,7 +24,7 @@ def load_driver(name, default_uri)
20
24
  end
21
25
  end
22
26
 
23
- #ENV['ADAPTER'] ||= 'sqlite3'
27
+ ENV['ADAPTER'] ||= 'sqlite3'
24
28
 
25
29
  load_driver(:sqlite3, 'sqlite3::memory:')
26
30
  load_driver(:mysql, 'mysql://localhost/dm_core_test')
@@ -1,7 +1,4 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname + '../spec_helper'
3
-
4
- require Pathname(__FILE__).dirname + '../../lib/migration'
1
+ require 'spec_helper'
5
2
 
6
3
  describe 'Migration' do
7
4
 
@@ -214,12 +211,12 @@ describe 'Migration' do
214
211
 
215
212
  describe '#drop_table' do
216
213
  it 'should quote the table name' do
217
- @adapter.should_receive(:quote_table_name).with('users')
214
+ @adapter.should_receive(:quote_name).with('users')
218
215
  @m.drop_table :users
219
216
  end
220
217
 
221
218
  it 'should execute the DROP TABLE sql for the table' do
222
- @adapter.stub!(:quote_table_name).and_return("'users'")
219
+ @adapter.stub!(:quote_name).and_return("'users'")
223
220
  @m.should_receive(:execute).with(%{DROP TABLE 'users'})
224
221
  @m.drop_table :users
225
222
  end
@@ -326,21 +323,21 @@ describe 'Migration' do
326
323
  describe 'working with the migration_info table' do
327
324
  before do
328
325
  @adapter.stub!(:storage_exists?).and_return(true)
329
- @adapter.stub!(:quote_table_name).and_return(%{'users'})
330
- @adapter.stub!(:quote_column_name).and_return(%{'migration_name'})
326
+ # --- Please remove stubs ---
327
+ @adapter.stub!(:quote_name).and_return { |name| "'#{name}'" }
331
328
  end
332
329
 
333
330
  describe '#update_migration_info' do
334
331
  it 'should add a record of the migration' do
335
332
  @m.should_receive(:execute).with(
336
- %Q{INSERT INTO 'users' ('migration_name') VALUES ('do_nothing')}
333
+ %Q{INSERT INTO 'migration_info' ('migration_name') VALUES ('do_nothing')}
337
334
  )
338
335
  @m.update_migration_info(:up)
339
336
  end
340
337
 
341
338
  it 'should remove the record of the migration' do
342
339
  @m.should_receive(:execute).with(
343
- %Q{DELETE FROM 'users' WHERE 'migration_name' = 'do_nothing'}
340
+ %Q{DELETE FROM 'migration_info' WHERE 'migration_name' = 'do_nothing'}
344
341
  )
345
342
  @m.update_migration_info(:down)
346
343
  end
@@ -355,7 +352,7 @@ describe 'Migration' do
355
352
  it 'should create the migration info table' do
356
353
  @m.should_receive(:migration_info_table_exists?).and_return(false)
357
354
  @m.should_receive(:execute).with(
358
- %Q{CREATE TABLE 'users' ('migration_name' VARCHAR(255) UNIQUE)}
355
+ %Q{CREATE TABLE 'migration_info' ('migration_name' VARCHAR(255) UNIQUE)}
359
356
  )
360
357
  @m.create_migration_info_table_if_needed
361
358
  end
@@ -379,7 +376,7 @@ describe 'Migration' do
379
376
  describe '#migration_record' do
380
377
  it 'should query for the migration' do
381
378
  @adapter.should_receive(:query).with(
382
- %Q{SELECT 'migration_name' FROM 'users' WHERE 'migration_name' = 'do_nothing'}
379
+ %Q{SELECT 'migration_name' FROM 'migration_info' WHERE 'migration_name' = 'do_nothing'}
383
380
  )
384
381
  @m.migration_record
385
382
  end
@@ -429,12 +426,12 @@ describe 'Migration' do
429
426
  end
430
427
 
431
428
  it 'should have the adapter quote the migration_info table' do
432
- @adapter.should_receive(:quote_table_name).with('migration_info').and_return("'migration_info'")
429
+ @adapter.should_receive(:quote_name).with('migration_info').and_return("'migration_info'")
433
430
  @m.migration_info_table.should == "'migration_info'"
434
431
  end
435
432
 
436
433
  it 'should have a quoted migration_name_column' do
437
- @adapter.should_receive(:quote_column_name).with('migration_name').and_return("'migration_name'")
434
+ @adapter.should_receive(:quote_name).with('migration_name').and_return("'migration_name'")
438
435
  @m.migration_name_column.should == "'migration_name'"
439
436
  end
440
437
 
@@ -1,7 +1,4 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname + '../../spec_helper'
3
-
4
- require Pathname(__FILE__).dirname + '../../../lib/sql/column'
1
+ require 'spec_helper'
5
2
 
6
3
  describe SQL::Column do
7
4
  before do
@@ -1,7 +1,4 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname + '../../spec_helper'
3
-
4
- require Pathname(__FILE__).dirname + '../../../lib/sql/sqlite3'
1
+ require 'spec_helper'
5
2
 
6
3
  # a dummy class to include the module into
7
4
  class PostgresqlExtension
@@ -1,7 +1,4 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname + '../../spec_helper'
3
-
4
- require Pathname(__FILE__).dirname + '../../../lib/sql/sqlite3'
1
+ require 'spec_helper'
5
2
 
6
3
  # a dummy class to include the module into
7
4
  class Sqlite3Extension
@@ -1,13 +1,10 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname + '../../spec_helper'
3
-
4
- require Pathname(__FILE__).dirname + '../../../lib/sql/table_creator'
1
+ require 'spec_helper'
5
2
 
6
3
  describe 'SQL module' do
7
4
  describe 'TableCreator' do
8
5
  before do
9
6
  @adapter = mock('adapter')
10
- @adapter.stub!(:quote_table_name).and_return(%{'users'})
7
+ @adapter.stub!(:quote_name).and_return(%{'users'})
11
8
  @tc = SQL::TableCreator.new(@adapter, 'users') { }
12
9
  end
13
10
 
@@ -43,7 +40,7 @@ describe 'SQL module' do
43
40
  end
44
41
 
45
42
  it 'should use the adapter to quote the table name' do
46
- @adapter.should_receive(:quote_table_name).with('users').and_return(%{'users'})
43
+ @adapter.should_receive(:quote_name).with('users').and_return(%{'users'})
47
44
  @tc.quoted_table_name.should == %{'users'}
48
45
  end
49
46
 
@@ -55,16 +52,19 @@ describe 'SQL module' do
55
52
  end
56
53
 
57
54
  it 'should output an SQL CREATE statement to build itself' do
58
- @adapter.should_receive(:create_table_statement).with("'users'").and_return(%{CREATE TABLE 'users'})
55
+ @adapter.stub!(:table_options).and_return("")
59
56
  @tc.to_sql.should ==
60
57
  %{CREATE TABLE 'users' ()}
61
58
  end
62
59
 
63
60
  describe 'Column' do
64
61
  before do
62
+ connection = mock('Connection')
63
+
65
64
  @adapter.stub!(:quote_column_name).and_return(%{'id'})
66
65
  @adapter.class.stub!(:type_map).and_return(Integer => {:type => 'int'})
67
66
  @adapter.stub!(:property_schema_statement).and_return("SOME SQL")
67
+ @adapter.stub!(:with_connection).and_yield(connection)
68
68
  @c = SQL::TableCreator::Column.new(@adapter, 'id', Integer, :serial => true)
69
69
  end
70
70
 
@@ -1,13 +1,10 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname + '../../spec_helper'
3
-
4
- require Pathname(__FILE__).dirname + '../../../lib/sql/table_modifier'
1
+ require 'spec_helper'
5
2
 
6
3
  describe 'SQL module' do
7
4
  describe 'TableModifier' do
8
5
  before do
9
6
  @adapter = mock('adapter')
10
- @adapter.stub!(:quote_table_name).and_return(%{'users'})
7
+ @adapter.stub!(:quote_name).and_return(%{'users'})
11
8
  @tc = SQL::TableModifier.new(@adapter, :users) { }
12
9
  end
13
10
 
@@ -43,7 +40,7 @@ describe 'SQL module' do
43
40
  end
44
41
 
45
42
  it 'should use the adapter to quote the table name' do
46
- @adapter.should_receive(:quote_table_name).with('users').and_return(%{'users'})
43
+ @adapter.should_receive(:quote_name).with('users').and_return(%{'users'})
47
44
  @tc.quoted_table_name.should == %{'users'}
48
45
  end
49
46
 
@@ -1,7 +1,4 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname + '../../spec_helper'
3
-
4
- require Pathname(__FILE__).dirname + '../../../lib/sql/table'
1
+ require 'spec_helper'
5
2
 
6
3
  describe SQL::Table do
7
4
  before do
@@ -1,7 +1,4 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname + '../spec_helper'
3
-
4
- require Pathname(__FILE__).dirname + '../../lib/sql'
1
+ require 'spec_helper'
5
2
 
6
3
  describe 'SQL module' do
7
4
 
data/tasks/db.rb CHANGED
@@ -12,7 +12,7 @@ namespace :db do
12
12
  # set DIRECTION to migrate down
13
13
  desc "Run your system's migrations"
14
14
  task :migrate => [:setup_migration_dir] do
15
- require File.expand_path(File.join(File.dirname(__FILE__), "lib", "migration_runner.rb"))
15
+ require 'dm-migrations/migration_runner.rb'
16
16
  require File.expand_path(File.join(MIGRATION_DIR, "config.rb"))
17
17
 
18
18
  Dir[File.join(MIGRATION_DIR, "*.rb")].each { |file| require file }
data/tasks/install.rb CHANGED
@@ -4,7 +4,7 @@ end
4
4
 
5
5
  desc "Install #{GEM_NAME} #{GEM_VERSION}"
6
6
  task :install => [ :package ] do
7
- sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
7
+ sudo_gem "install pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
8
8
  end
9
9
 
10
10
  desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
data/tasks/spec.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  begin
2
- gem 'rspec', '~>1.2'
3
- require 'spec'
4
2
  require 'spec/rake/spectask'
5
3
 
6
4
  task :default => [ :spec ]
@@ -8,16 +6,18 @@ begin
8
6
  desc 'Run specifications'
9
7
  Spec::Rake::SpecTask.new(:spec) do |t|
10
8
  t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
11
- t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s).map { |f| f.to_s }
9
+ t.libs << 'lib' << 'spec' # needed for CI rake spec task, duplicated in spec_helper
12
10
 
13
11
  begin
14
- gem 'rcov', '~>0.8'
12
+ require 'rcov'
15
13
  t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
16
14
  t.rcov_opts << '--exclude' << 'spec'
17
15
  t.rcov_opts << '--text-summary'
18
16
  t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
19
17
  rescue LoadError
20
18
  # rcov not installed
19
+ rescue SyntaxError
20
+ # rcov syntax invalid
21
21
  end
22
22
  end
23
23
  rescue LoadError
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.11
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Sadauskas
@@ -9,19 +9,10 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-29 00:00:00 -07:00
12
+ date: 2009-09-16 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: dm-core
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - "="
22
- - !ruby/object:Gem::Version
23
- version: 0.9.11
24
- version:
14
+ dependencies: []
15
+
25
16
  description: DataMapper plugin for writing and speccing migrations
26
17
  email:
27
18
  - psadauskas [a] gmail [d] com
@@ -30,15 +21,15 @@ executables: []
30
21
  extensions: []
31
22
 
32
23
  extra_rdoc_files:
33
- - README.txt
24
+ - README.rdoc
34
25
  - LICENSE
35
26
  - TODO
36
- - History.txt
27
+ - History.rdoc
37
28
  files:
38
- - History.txt
29
+ - History.rdoc
39
30
  - LICENSE
40
31
  - Manifest.txt
41
- - README.txt
32
+ - README.rdoc
42
33
  - Rakefile
43
34
  - TODO
44
35
  - db/migrations/1_create_people_table.rb
@@ -47,19 +38,19 @@ files:
47
38
  - examples/sample_migration.rb
48
39
  - examples/sample_migration_spec.rb
49
40
  - lib/dm-migrations.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/postgresql.rb
47
+ - lib/dm-migrations/sql/sqlite3.rb
48
+ - lib/dm-migrations/sql/table.rb
49
+ - lib/dm-migrations/sql/table_creator.rb
50
+ - lib/dm-migrations/sql/table_modifier.rb
50
51
  - lib/dm-migrations/version.rb
51
- - lib/migration.rb
52
- - lib/migration_runner.rb
53
52
  - lib/spec/example/migration_example_group.rb
54
53
  - lib/spec/matchers/migration_matchers.rb
55
- - lib/sql.rb
56
- - lib/sql/column.rb
57
- - lib/sql/mysql.rb
58
- - lib/sql/postgresql.rb
59
- - lib/sql/sqlite3.rb
60
- - lib/sql/table.rb
61
- - lib/sql/table_creator.rb
62
- - lib/sql/table_modifier.rb
63
54
  - spec/integration/migration_runner_spec.rb
64
55
  - spec/integration/migration_spec.rb
65
56
  - spec/integration/sql_spec.rb
@@ -77,11 +68,13 @@ files:
77
68
  - tasks/install.rb
78
69
  - tasks/spec.rb
79
70
  has_rdoc: true
80
- homepage: http://github.com/sam/dm-more/tree/master/dm-migrations
71
+ homepage: http://github.com/datamapper/dm-more/tree/master/dm-migrations
72
+ licenses: []
73
+
81
74
  post_install_message:
82
75
  rdoc_options:
83
76
  - --main
84
- - README.txt
77
+ - README.rdoc
85
78
  require_paths:
86
79
  - lib
87
80
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -99,9 +92,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
92
  requirements: []
100
93
 
101
94
  rubyforge_project: datamapper
102
- rubygems_version: 1.3.1
95
+ rubygems_version: 1.3.5
103
96
  signing_key:
104
- specification_version: 2
97
+ specification_version: 3
105
98
  summary: DataMapper plugin for writing and speccing migrations
106
99
  test_files: []
107
100
 
data/lib/sql.rb DELETED
@@ -1,10 +0,0 @@
1
- require File.dirname(__FILE__) + '/sql/table_creator'
2
- require File.dirname(__FILE__) + '/sql/table_modifier'
3
-
4
- require File.dirname(__FILE__) + '/sql/sqlite3'
5
- require File.dirname(__FILE__) + '/sql/mysql'
6
- require File.dirname(__FILE__) + '/sql/postgresql'
7
-
8
- module SQL
9
-
10
- end