dm-hibernate-migrations 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/lib/dm-migrations.rb +3 -0
  2. data/lib/dm-migrations/adapters/dm-do-adapter.rb +284 -0
  3. data/lib/dm-migrations/adapters/dm-mysql-adapter.rb +283 -0
  4. data/lib/dm-migrations/adapters/dm-oracle-adapter.rb +321 -0
  5. data/lib/dm-migrations/adapters/dm-postgres-adapter.rb +159 -0
  6. data/lib/dm-migrations/adapters/dm-sqlite-adapter.rb +96 -0
  7. data/lib/dm-migrations/adapters/dm-sqlserver-adapter.rb +177 -0
  8. data/lib/dm-migrations/adapters/dm-yaml-adapter.rb +23 -0
  9. data/lib/dm-migrations/auto_migration.rb +237 -0
  10. data/lib/dm-migrations/migration.rb +217 -0
  11. data/lib/dm-migrations/migration_runner.rb +85 -0
  12. data/lib/dm-migrations/sql.rb +5 -0
  13. data/lib/dm-migrations/sql/column.rb +5 -0
  14. data/lib/dm-migrations/sql/mysql.rb +53 -0
  15. data/lib/dm-migrations/sql/postgres.rb +78 -0
  16. data/lib/dm-migrations/sql/sqlite.rb +45 -0
  17. data/lib/dm-migrations/sql/table.rb +15 -0
  18. data/lib/dm-migrations/sql/table_creator.rb +102 -0
  19. data/lib/dm-migrations/sql/table_modifier.rb +51 -0
  20. data/lib/spec/example/migration_example_group.rb +73 -0
  21. data/lib/spec/matchers/migration_matchers.rb +106 -0
  22. data/spec/integration/auto_migration_spec.rb +506 -0
  23. data/spec/integration/migration_runner_spec.rb +89 -0
  24. data/spec/integration/migration_spec.rb +138 -0
  25. data/spec/integration/sql_spec.rb +190 -0
  26. data/spec/isolated/require_after_setup_spec.rb +30 -0
  27. data/spec/isolated/require_before_setup_spec.rb +30 -0
  28. data/spec/isolated/require_spec.rb +25 -0
  29. data/spec/rcov.opts +6 -0
  30. data/spec/spec.opts +4 -0
  31. data/spec/spec_helper.rb +16 -0
  32. data/spec/unit/migration_spec.rb +453 -0
  33. data/spec/unit/sql/column_spec.rb +14 -0
  34. data/spec/unit/sql/postgres_spec.rb +97 -0
  35. data/spec/unit/sql/sqlite_extensions_spec.rb +108 -0
  36. data/spec/unit/sql/table_creator_spec.rb +94 -0
  37. data/spec/unit/sql/table_modifier_spec.rb +49 -0
  38. data/spec/unit/sql/table_spec.rb +28 -0
  39. data/spec/unit/sql_spec.rb +7 -0
  40. metadata +157 -0
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe SQL::Column do
4
+ before do
5
+ @column = SQL::Column.new
6
+ end
7
+
8
+ %w{name type not_null default_value primary_key unique}.each do |meth|
9
+ it "should have a ##{meth} attribute" do
10
+ @column.should respond_to(meth.intern)
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ # a dummy class to include the module into
4
+ class PostgresExtension
5
+ include SQL::Postgres
6
+ end
7
+
8
+ describe "Postgres Extensions" do
9
+ before do
10
+ @pe = PostgresExtension.new
11
+ end
12
+
13
+ it 'should support schema-level transactions' do
14
+ @pe.supports_schema_transactions?.should be(true)
15
+ end
16
+
17
+ it 'should support the serial column attribute' do
18
+ @pe.supports_serial?.should be(true)
19
+ end
20
+
21
+ it 'should create a table object from the name' do
22
+ table = mock('SQLite3 Table')
23
+ SQL::Postgres::Table.should_receive(:new).with(@pe, 'users').and_return(table)
24
+
25
+ @pe.table('users').should == table
26
+ end
27
+
28
+ describe 'recreating the database' do
29
+ end
30
+
31
+ describe 'Table' do
32
+ before do
33
+ @cs1 = mock('Column Struct')
34
+ @cs2 = mock('Column Struct')
35
+ @adapter = mock('adapter', :select => [])
36
+ @adapter.stub!(:query_table).with('users').and_return([@cs1, @cs2])
37
+
38
+ @col1 = mock('Postgres Column')
39
+ @col2 = mock('Postgres Column')
40
+ end
41
+
42
+ it 'should initialize columns by querying the table' do
43
+ SQL::Postgres::Column.should_receive(:new).with(@cs1).and_return(@col1)
44
+ SQL::Postgres::Column.should_receive(:new).with(@cs2).and_return(@col2)
45
+ @adapter.should_receive(:query_table).with('users').and_return([@cs1,@cs2])
46
+ SQL::Postgres::Table.new(@adapter, 'users')
47
+ end
48
+
49
+ it 'should create SQLite3 Column objects from the returned column structs' do
50
+ SQL::Postgres::Column.should_receive(:new).with(@cs1).and_return(@col1)
51
+ SQL::Postgres::Column.should_receive(:new).with(@cs2).and_return(@col2)
52
+ SQL::Postgres::Table.new(@adapter, 'users')
53
+ end
54
+
55
+ it 'should set the @columns to the looked-up columns' do
56
+ SQL::Postgres::Column.should_receive(:new).with(@cs1).and_return(@col1)
57
+ SQL::Postgres::Column.should_receive(:new).with(@cs2).and_return(@col2)
58
+ t = SQL::Postgres::Table.new(@adapter, 'users')
59
+ t.columns.should == [@col1, @col2]
60
+ end
61
+
62
+ describe '#query_column_constraints' do
63
+
64
+ end
65
+
66
+ end
67
+
68
+ describe 'Column' do
69
+ before do
70
+ @cs = mock('Struct',
71
+ :column_name => 'id',
72
+ :data_type => 'integer',
73
+ :column_default => 123,
74
+ :is_nullable => 'NO')
75
+ @c = SQL::Postgres::Column.new(@cs)
76
+ end
77
+
78
+ it 'should set the name from the column_name value' do
79
+ @c.name.should == 'id'
80
+ end
81
+
82
+ it 'should set the type from the data_type value' do
83
+ @c.type.should == 'integer'
84
+ end
85
+
86
+ it 'should set the default_value from the column_default value' do
87
+ @c.default_value.should == 123
88
+ end
89
+
90
+ it 'should set not_null based on the is_nullable value' do
91
+ @c.not_null.should == true
92
+ end
93
+
94
+ end
95
+
96
+
97
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ # a dummy class to include the module into
4
+ class SqliteExtension
5
+ include SQL::Sqlite
6
+ end
7
+
8
+ describe "SQLite3 Extensions" do
9
+ before do
10
+ @se = SqliteExtension.new
11
+ end
12
+
13
+ it 'should support schema-level transactions' do
14
+ @se.supports_schema_transactions?.should be(true)
15
+ end
16
+
17
+ it 'should support the serial column attribute' do
18
+ @se.supports_serial?.should be(true)
19
+ end
20
+
21
+ it 'should create a table object from the name' do
22
+ table = mock('SQLite3 Table')
23
+ SQL::Sqlite::Table.should_receive(:new).with(@se, 'users').and_return(table)
24
+
25
+ @se.table('users').should == table
26
+ end
27
+
28
+ describe 'recreating the database' do
29
+ before do
30
+ uri = mock('URI', :path => '/foo/bar.db')
31
+ @se.instance_variable_set('@uri', uri)
32
+ end
33
+
34
+ it 'should rm the db file' do
35
+ @se.should_receive(:system).with('rm /foo/bar.db')
36
+ @se.recreate_database
37
+ end
38
+
39
+ end
40
+
41
+ describe 'Table' do
42
+ before do
43
+ @cs1 = mock('Column Struct')
44
+ @cs2 = mock('Column Struct')
45
+ @adapter = mock('adapter')
46
+ @adapter.stub!(:table_info).with('users').and_return([@cs1, @cs2])
47
+
48
+ @col1 = mock('SQLite3 Column')
49
+ @col2 = mock('SQLite3 Column')
50
+ end
51
+
52
+ it 'should initialize columns by querying the table' do
53
+ SQL::Sqlite::Column.should_receive(:new).with(@cs1).and_return(@col1)
54
+ SQL::Sqlite::Column.should_receive(:new).with(@cs2).and_return(@col2)
55
+ @adapter.should_receive(:table_info).with('users').and_return([@cs1,@cs2])
56
+ SQL::Sqlite::Table.new(@adapter, 'users')
57
+ end
58
+
59
+ it 'should create SQLite3 Column objects from the returned column structs' do
60
+ SQL::Sqlite::Column.should_receive(:new).with(@cs1).and_return(@col1)
61
+ SQL::Sqlite::Column.should_receive(:new).with(@cs2).and_return(@col2)
62
+ SQL::Sqlite::Table.new(@adapter, 'users')
63
+ end
64
+
65
+ it 'should set the @columns to the looked-up columns' do
66
+ SQL::Sqlite::Column.should_receive(:new).with(@cs1).and_return(@col1)
67
+ SQL::Sqlite::Column.should_receive(:new).with(@cs2).and_return(@col2)
68
+ t = SQL::Sqlite::Table.new(@adapter, 'users')
69
+ t.columns.should == [ @col1, @col2 ]
70
+ end
71
+
72
+ end
73
+
74
+ describe 'Column' do
75
+ before do
76
+ @cs = mock('Struct',
77
+ :name => 'id',
78
+ :type => 'integer',
79
+ :dflt_value => 123,
80
+ :pk => true,
81
+ :notnull => 0)
82
+ @c = SQL::Sqlite::Column.new(@cs)
83
+ end
84
+
85
+ it 'should set the name from the name value' do
86
+ @c.name.should == 'id'
87
+ end
88
+
89
+ it 'should set the type from the type value' do
90
+ @c.type.should == 'integer'
91
+ end
92
+
93
+ it 'should set the default_value from the dflt_value value' do
94
+ @c.default_value.should == 123
95
+ end
96
+
97
+ it 'should set the primary_key from the pk value' do
98
+ @c.primary_key.should == true
99
+ end
100
+
101
+ it 'should set not_null based on the notnull value' do
102
+ @c.not_null.should == true
103
+ end
104
+
105
+ end
106
+
107
+
108
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'SQL module' do
4
+ describe 'TableCreator' do
5
+ before do
6
+ @adapter = mock('adapter')
7
+ @adapter.stub!(:quote_name).and_return(%{'users'})
8
+ @tc = SQL::TableCreator.new(@adapter, 'users') { }
9
+ end
10
+
11
+ describe 'initialization' do
12
+ it 'should set @adapter to the adapter' do
13
+ @tc.instance_variable_get("@adapter").should == @adapter
14
+ end
15
+
16
+ it 'should set @table_name to the stringified table name' do
17
+ @tc.instance_variable_get("@table_name").should == 'users'
18
+ end
19
+
20
+ it 'should set @opts to the options hash' do
21
+ @tc.instance_variable_get("@opts").should == {}
22
+ end
23
+
24
+ it 'should set @columns to an empty array' do
25
+ @tc.instance_variable_get("@columns").should == []
26
+ end
27
+
28
+ it 'should evaluate the given block' do
29
+ block = proc { column :foo, :bar }
30
+ col = mock('column')
31
+ SQL::TableCreator::Column.should_receive(:new).with(@adapter, :foo, :bar, {}).and_return(col)
32
+ tc = SQL::TableCreator.new(@adapter, 'users', {}, &block)
33
+ tc.instance_variable_get("@columns").should == [col]
34
+ end
35
+ end
36
+
37
+ it 'should have a table_name' do
38
+ @tc.should respond_to(:table_name)
39
+ @tc.table_name.should == 'users'
40
+ end
41
+
42
+ it 'should use the adapter to quote the table name' do
43
+ @adapter.should_receive(:quote_name).with('users').and_return(%{'users'})
44
+ @tc.quoted_table_name.should == %{'users'}
45
+ end
46
+
47
+ it 'should initialze a new column and add it to the list of columns' do
48
+ col = mock('column')
49
+ SQL::TableCreator::Column.should_receive(:new).with(@adapter, :foo, :bar, {}).and_return(col)
50
+ @tc.column(:foo, :bar)
51
+ @tc.instance_variable_get("@columns").should == [col]
52
+ end
53
+
54
+ it 'should output an SQL CREATE statement to build itself' do
55
+ @adapter.stub!(:table_options).and_return("")
56
+ @tc.to_sql.should ==
57
+ %{CREATE TABLE 'users' ()}
58
+ end
59
+
60
+ describe 'Column' do
61
+ before do
62
+ connection = mock('Connection')
63
+
64
+ @adapter.stub!(:quote_column_name).and_return(%{'id'})
65
+ @adapter.class.stub!(:type_map).and_return(Integer => {:type => 'int'})
66
+ @adapter.stub!(:property_schema_statement).and_return("SOME SQL")
67
+ @adapter.stub!(:with_connection).and_yield(connection)
68
+ @c = SQL::TableCreator::Column.new(@adapter, 'id', Integer, :serial => true)
69
+ end
70
+
71
+ describe 'initialization' do
72
+ it 'should set @adapter to the adapter' do
73
+ @c.instance_variable_get("@adapter").should == @adapter
74
+ end
75
+
76
+ it 'should set @name to the stringified name' do
77
+ @c.instance_variable_get("@name").should == 'id'
78
+ end
79
+
80
+ # TODO make this really the type, not this sql bullshit
81
+ it 'should set @type to the type' do
82
+ @c.instance_variable_get("@type").should == "SOME SQL"
83
+ end
84
+
85
+ it 'should set @opts to the options hash' do
86
+ @c.instance_variable_get("@opts").should == {:serial => true}
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'SQL module' do
4
+ describe 'TableModifier' do
5
+ before do
6
+ @adapter = mock('adapter')
7
+ @adapter.stub!(:quote_name).and_return(%{'users'})
8
+ @tc = SQL::TableModifier.new(@adapter, :users) { }
9
+ end
10
+
11
+ describe 'initialization' do
12
+ it 'should set @adapter to the adapter' do
13
+ @tc.instance_variable_get("@adapter").should == @adapter
14
+ end
15
+
16
+ it 'should set @table_name to the stringified table name' do
17
+ @tc.instance_variable_get("@table_name").should == 'users'
18
+ end
19
+
20
+ it 'should set @opts to the options hash' do
21
+ @tc.instance_variable_get("@opts").should == {}
22
+ end
23
+
24
+ it 'should set @statements to an empty array' do
25
+ @tc.instance_variable_get("@statements").should == []
26
+ end
27
+
28
+ it 'should evaluate the given block' do
29
+ block = proc { column :foo, :bar }
30
+ col = mock('column')
31
+ SQL::TableCreator::Column.should_receive(:new).with(@adapter, :foo, :bar, {}).and_return(col)
32
+ tc = SQL::TableCreator.new(@adapter, 'users', {}, &block)
33
+ tc.instance_variable_get("@columns").should == [col]
34
+ end
35
+ end
36
+
37
+ it 'should have a table_name' do
38
+ @tc.should respond_to(:table_name)
39
+ @tc.table_name.should == 'users'
40
+ end
41
+
42
+ it 'should use the adapter to quote the table name' do
43
+ @adapter.should_receive(:quote_name).with('users').and_return(%{'users'})
44
+ @tc.quoted_table_name.should == %{'users'}
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe SQL::Table do
4
+ before do
5
+ @table = SQL::Table.new
6
+ end
7
+
8
+ %w{name columns}.each do |meth|
9
+ it "should have a ##{meth} attribute" do
10
+ @table.should respond_to(meth.intern)
11
+ end
12
+ end
13
+
14
+ it 'should #to_s as the name' do
15
+ @table.name = "table_name"
16
+ @table.to_s.should == "table_name"
17
+ end
18
+
19
+ it 'should find a column by name' do
20
+ column_a = mock('column', :name => 'id')
21
+ column_b = mock('column', :name => 'login')
22
+ @table.columns = [column_a, column_b]
23
+
24
+ @table.column('id').should == column_a
25
+ end
26
+
27
+
28
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'SQL module' do
4
+
5
+ it 'doesnt really do anything'
6
+
7
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-hibernate-migrations
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Paul Sadauskas
13
+ - Kristian Meier
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-29 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: dm-core
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ version: 1.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: dm-sqlite-adapter
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 1
58
+ - 3
59
+ version: "1.3"
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: DataMapper plugin for writing and speccing migrations
63
+ email:
64
+ - psadauskas [a] gmail [d] com
65
+ - m.kristian@web.de
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - lib/dm-migrations.rb
74
+ - lib/dm-migrations/migration_runner.rb
75
+ - lib/dm-migrations/auto_migration.rb
76
+ - lib/dm-migrations/migration.rb
77
+ - lib/dm-migrations/sql.rb
78
+ - lib/dm-migrations/sql/table.rb
79
+ - lib/dm-migrations/sql/mysql.rb
80
+ - lib/dm-migrations/sql/table_creator.rb
81
+ - lib/dm-migrations/sql/table_modifier.rb
82
+ - lib/dm-migrations/sql/postgres.rb
83
+ - lib/dm-migrations/sql/sqlite.rb
84
+ - lib/dm-migrations/sql/column.rb
85
+ - lib/dm-migrations/adapters/dm-mysql-adapter.rb
86
+ - lib/dm-migrations/adapters/dm-yaml-adapter.rb
87
+ - lib/dm-migrations/adapters/dm-sqlserver-adapter.rb
88
+ - lib/dm-migrations/adapters/dm-do-adapter.rb
89
+ - lib/dm-migrations/adapters/dm-postgres-adapter.rb
90
+ - lib/dm-migrations/adapters/dm-sqlite-adapter.rb
91
+ - lib/dm-migrations/adapters/dm-oracle-adapter.rb
92
+ - lib/spec/matchers/migration_matchers.rb
93
+ - lib/spec/example/migration_example_group.rb
94
+ - spec/rcov.opts
95
+ - spec/spec_helper.rb
96
+ - spec/spec.opts
97
+ - spec/unit/migration_spec.rb
98
+ - spec/unit/sql_spec.rb
99
+ - spec/unit/sql/postgres_spec.rb
100
+ - spec/unit/sql/table_modifier_spec.rb
101
+ - spec/unit/sql/table_spec.rb
102
+ - spec/unit/sql/sqlite_extensions_spec.rb
103
+ - spec/unit/sql/column_spec.rb
104
+ - spec/unit/sql/table_creator_spec.rb
105
+ - spec/isolated/require_before_setup_spec.rb
106
+ - spec/isolated/require_spec.rb
107
+ - spec/isolated/require_after_setup_spec.rb
108
+ - spec/integration/auto_migration_spec.rb
109
+ - spec/integration/migration_runner_spec.rb
110
+ - spec/integration/migration_spec.rb
111
+ - spec/integration/sql_spec.rb
112
+ has_rdoc: true
113
+ homepage: http://github.com/datamapper/dm-migrations
114
+ licenses:
115
+ - MIT license
116
+ post_install_message:
117
+ rdoc_options: []
118
+
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ requirements: []
136
+
137
+ rubyforge_project:
138
+ rubygems_version: 1.3.6
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: DataMapper plugin for writing and speccing migrations
142
+ test_files:
143
+ - spec/unit/migration_spec.rb
144
+ - spec/unit/sql_spec.rb
145
+ - spec/unit/sql/postgres_spec.rb
146
+ - spec/unit/sql/table_modifier_spec.rb
147
+ - spec/unit/sql/table_spec.rb
148
+ - spec/unit/sql/sqlite_extensions_spec.rb
149
+ - spec/unit/sql/column_spec.rb
150
+ - spec/unit/sql/table_creator_spec.rb
151
+ - spec/isolated/require_before_setup_spec.rb
152
+ - spec/isolated/require_spec.rb
153
+ - spec/isolated/require_after_setup_spec.rb
154
+ - spec/integration/auto_migration_spec.rb
155
+ - spec/integration/migration_runner_spec.rb
156
+ - spec/integration/migration_spec.rb
157
+ - spec/integration/sql_spec.rb