dbdiff 0.1.0 → 0.2.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.
@@ -0,0 +1,8 @@
1
+ CREATE TABLE authors (
2
+ `id` int(11) NOT NULL auto_increment,
3
+ `name` char(60) NOT NULL,
4
+ `address` char(60) NULL,
5
+ PRIMARY KEY (`id`)
6
+ ) ENGINE=innodb DEFAULT CHARSET=latin1;
7
+
8
+ CREATE PROCEDURE simpleproc (OUT param1 INT) BEGIN SELECT COUNT(*) INTO param1 FROM authors; END;
@@ -0,0 +1 @@
1
+
@@ -3,5 +3,8 @@ require 'test_table'
3
3
  require 'test_row'
4
4
  require 'test_foreign_key'
5
5
  require 'test_key'
6
+ require 'test_procedure'
7
+ require 'test_function'
8
+ require 'test_trigger'
6
9
  require 'test_column'
7
10
  require 'test_dbdiff'
@@ -38,7 +38,7 @@ class TestDbDiff < Test::Unit::TestCase
38
38
  def apply_sql(dbh, database, sql)
39
39
 
40
40
  dbh.select_db(database)
41
- sql.split(";").each do |q|
41
+ sql.split(/;$/).each do |q|
42
42
  q.strip!
43
43
  next unless q.length > 0
44
44
  dbh.query(q)
@@ -47,8 +47,14 @@ class TestDbDiff < Test::Unit::TestCase
47
47
 
48
48
  def process_diff
49
49
 
50
+ logger =Logger.new('out.log')
51
+ logger.level = Logger::DEBUG
52
+
50
53
  dbdiff = DbDiff.new( {:host => '127.0.0.1', :password => nil, :user => 'root', :name => SOURCE_DB},
51
- {:host => '127.0.0.1', :password => nil, :user => 'root', :name => TARGET_DB}, :tables => ['authors'])
54
+ {:host => '127.0.0.1', :password => nil, :user => 'root', :name => TARGET_DB},
55
+ :replicate_tables => ['authors'],
56
+ :logger => logger
57
+ )
52
58
 
53
59
  dbdiff.dry_run = false
54
60
  dbdiff.diff
@@ -62,7 +68,7 @@ class TestDbDiff < Test::Unit::TestCase
62
68
  assert(dbdiff.target.deltas.size == 0)
63
69
 
64
70
  dbdiff = DbDiff.new( {:host => '127.0.0.1', :password => nil, :user => 'root', :name => SOURCE_DB},
65
- {:host => '127.0.0.1', :password => nil, :user => 'root', :name => TARGET_DB}, :tables => %w(authors))
71
+ {:host => '127.0.0.1', :password => nil, :user => 'root', :name => TARGET_DB}, :replicate_tables => %w(authors))
66
72
 
67
73
  dbdiff.diff
68
74
 
@@ -73,14 +79,16 @@ class TestDbDiff < Test::Unit::TestCase
73
79
  def run_diff(dbh, dir)
74
80
  source = File.open("./test/" + dir + "/source.sql").read
75
81
  target = File.open("./test/" + dir + "/target.sql").read
82
+ #return unless dir == 'procedure'
76
83
 
77
- #puts "processing #{dir}"
84
+ #
85
+ # puts "processing #{dir}"
78
86
 
79
87
  prep_databases(dbh, source, target)
80
88
 
81
89
  process_diff
82
90
 
83
- # puts "processing opposite #{dir}"
91
+ # puts "processing opposite #{dir}"
84
92
 
85
93
  prep_databases(dbh, target, source)
86
94
 
@@ -0,0 +1,69 @@
1
+ require 'dbdiff'
2
+ require 'test/unit'
3
+
4
+ class TestFunction < Test::Unit::TestCase
5
+
6
+ def test_load
7
+ f = DbDiff::Function.new(
8
+ 'name' => 'my_func',
9
+ 'body' => %q|return concat('hello, ', s , '!')|,
10
+ 'param_list' => 's char(20)',
11
+ 'type' => 'FUNCTION',
12
+ 'returns' => 'char(50)'
13
+ )
14
+
15
+ assert(f.definition == %q|return concat('hello, ', s , '!')|)
16
+ assert(f.param_list == 's char(20)')
17
+ assert(f.routine_type == 'FUNCTION')
18
+ assert(f.name == 'my_func')
19
+ assert(f.returns == 'char(50)')
20
+
21
+ end
22
+
23
+
24
+
25
+ def test_not_equal
26
+ f1 = DbDiff::Function.new(
27
+ 'name' => 'my_func',
28
+ 'body' => %q|return concat('hello, ', s , '!')|,
29
+ 'param_list' => 's char(20)',
30
+ 'type' => 'FUNCTION',
31
+ 'returns' => 'char(50)'
32
+ )
33
+
34
+ f2 = DbDiff::Function.new(
35
+ 'name' => 'my_func2',
36
+ 'body' => %q|return concat('hello, ', s , '!')|,
37
+ 'param_list' => 's char(20)',
38
+ 'type' => 'FUNCTION',
39
+ 'returns' => 'char(50)'
40
+ )
41
+
42
+ assert(f1 != f2)
43
+
44
+ end
45
+
46
+
47
+ def test_equal
48
+
49
+ f1 = DbDiff::Function.new(
50
+ 'name' => 'my_func',
51
+ 'body' => %q|return concat('hello, ', s , '!')|,
52
+ 'param_list' => 's char(20)',
53
+ 'type' => 'FUNCTION',
54
+ 'returns' => 'char(50)'
55
+ )
56
+
57
+ f2 = DbDiff::Function.new(
58
+ 'name' => 'my_func',
59
+ 'body' => %q|return concat('hello, ', s , '!')|,
60
+ 'param_list' => 's char(20)',
61
+ 'type' => 'FUNCTION',
62
+ 'returns' => 'char(50)'
63
+ )
64
+
65
+ assert(f1 == f2)
66
+ end
67
+
68
+ end
69
+
@@ -0,0 +1,64 @@
1
+ require 'dbdiff'
2
+ require 'test/unit'
3
+
4
+ class TestProcedure < Test::Unit::TestCase
5
+
6
+ def test_load
7
+ p = DbDiff::Procedure.new(
8
+ 'name' => 'simpleproc',
9
+ 'body' => %q(BEGIN SELECT COUNT(*) INTO param1 FROM authors2; END),
10
+ 'param_list' => 'OUT param1 INT',
11
+ 'type' => 'PROCEDURE'
12
+ )
13
+
14
+ assert(p.definition == %q|BEGIN SELECT COUNT(*) INTO param1 FROM authors2; END|)
15
+ assert(p.param_list == 'OUT param1 INT')
16
+ assert(p.routine_type == 'PROCEDURE')
17
+ assert(p.name == 'simpleproc')
18
+ assert(p.returns == nil)
19
+
20
+ end
21
+
22
+
23
+
24
+ def test_not_equal
25
+
26
+ p1 = DbDiff::Procedure.new(
27
+ 'name' => 'simpleproc',
28
+ 'body' => %q|BEGIN SELECT COUNT(*) INTO param1 FROM authors2; END|,
29
+ 'param_list' => 'OUT param1 INT',
30
+ 'type' => 'PROCEDURE'
31
+ )
32
+
33
+ p2 = DbDiff::Procedure.new(
34
+ 'name' => 'simpleproc2',
35
+ 'body' => %q|BEGIN SELECT COUNT(*) INTO param1 FROM authors2; END|,
36
+ 'param_list' => 'OUT param1 INT',
37
+ 'type' => 'PROCEDURE'
38
+ )
39
+
40
+ assert(p1 != p2)
41
+
42
+ end
43
+
44
+
45
+ def test_equal
46
+ p1 = DbDiff::Procedure.new(
47
+ 'name' => 'simpleproc',
48
+ 'body' => %q|BEGIN SELECT COUNT(*) INTO param1 FROM authors2; END|,
49
+ 'param_list' => 'OUT param1 INT',
50
+ 'type' => 'PROCEDURE'
51
+ )
52
+
53
+ p2 = DbDiff::Procedure.new(
54
+ 'name' => 'simpleproc',
55
+ 'body' => %q|BEGIN SELECT COUNT(*) INTO param1 FROM authors2; END|,
56
+ 'param_list' => 'OUT param1 INT',
57
+ 'type' => 'PROCEDURE'
58
+ )
59
+
60
+ assert(p1 == p2)
61
+ end
62
+
63
+ end
64
+
@@ -6,13 +6,14 @@ class TestRow < Test::Unit::TestCase
6
6
  def test_load
7
7
 
8
8
  t = DbDiff::Table.new( 'ENGINE' => 'InnoDB', 'TABLE_COLLATION' => 'latin1', 'TABLE_NAME' => 'mytable')
9
- t.keys << DbDiff::Key.new(t.name,
9
+ t.keys << DbDiff::Key.new(t.name,
10
10
  'Key_name' => 'PRIMARY',
11
11
  'Seq_in_index' => '1',
12
12
  'Column_name' => 'id',
13
13
  'Non_unique' => '0'
14
14
  )
15
15
 
16
+
16
17
  row = DbDiff::Row.new(
17
18
  t,
18
19
  'id' => '1',
@@ -28,13 +29,15 @@ class TestRow < Test::Unit::TestCase
28
29
 
29
30
 
30
31
  def test_not_equal
31
- t = DbDiff::Table.new( 'ENGINE' => 'InnoDB', 'TABLE_COLLATION' => 'latin1', 'TABLE_NAME' => 'mytable')
32
- t.keys << DbDiff::Key.new(t.name,
33
- 'Key_name' => 'PRIMARY',
34
- 'Seq_in_index' => '1',
35
- 'Column_name' => 'id',
36
- 'Non_unique' => '0'
37
- )
32
+ t = DbDiff::Table.new( 'ENGINE' => 'InnoDB', 'TABLE_COLLATION' => 'latin1', 'TABLE_NAME' => 'mytable')
33
+ t.keys << DbDiff::Key.new(t.name,
34
+ 'Key_name' => 'PRIMARY',
35
+ 'Seq_in_index' => '1',
36
+ 'Column_name' => 'id',
37
+ 'Non_unique' => '0'
38
+ )
39
+
40
+
38
41
 
39
42
  r1 = DbDiff::Row.new(
40
43
  t,
@@ -54,15 +57,48 @@ class TestRow < Test::Unit::TestCase
54
57
 
55
58
  end
56
59
 
60
+ def test_equal_dates
61
+ t = DbDiff::Table.new( 'ENGINE' => 'InnoDB', 'TABLE_COLLATION' => 'latin1', 'TABLE_NAME' => 'mytable')
62
+ t.keys << DbDiff::Key.new(t.name,
63
+ 'Key_name' => 'PRIMARY',
64
+ 'Seq_in_index' => '1',
65
+ 'Column_name' => 'id',
66
+ 'Non_unique' => '0'
67
+ )
68
+
69
+
70
+
71
+ r1 = DbDiff::Row.new(
72
+ t,
73
+ 'id' => '1',
74
+ 'name' => 'foo',
75
+ 'address' => 'blah',
76
+ 'created_on' => '2006-08-01 11:11:11',
77
+ 'updated_on' => '2006-08-02 11:11:11'
78
+ )
79
+
80
+ r2 = DbDiff::Row.new(
81
+ t,
82
+ 'id' => '1',
83
+ 'name' => 'foo',
84
+ 'address' => 'blah',
85
+ 'created_on' => '2006-08-08 11:11:11',
86
+ 'updated_on' => '2006-08-08 11:11:11'
87
+ )
88
+
89
+ assert(r1 == r2)
90
+ end
91
+
57
92
  def test_equal
58
93
  t = DbDiff::Table.new( 'ENGINE' => 'InnoDB', 'TABLE_COLLATION' => 'latin1', 'TABLE_NAME' => 'mytable')
59
- t.keys << DbDiff::Key.new(t.name,
94
+ t.keys << DbDiff::Key.new(t.name,
60
95
  'Key_name' => 'PRIMARY',
61
96
  'Seq_in_index' => '1',
62
97
  'Column_name' => 'id',
63
98
  'Non_unique' => '0'
64
99
  )
65
100
 
101
+
66
102
  r1 = DbDiff::Row.new(
67
103
  t,
68
104
  'id' => '1',
@@ -0,0 +1,68 @@
1
+ require 'dbdiff'
2
+ require 'test/unit'
3
+
4
+ class TestTrigger < Test::Unit::TestCase
5
+
6
+ def test_load
7
+ t = DbDiff::Trigger.new(
8
+ 'TRIGGER_NAME' => 'my_trig',
9
+ 'EVENT_OBJECT_TABLE' => 'authors',
10
+ 'ACTION_STATEMENT' => 'BEGIN INSERT INTO blah SET id = NEW.id; END',
11
+ 'ACTION_TIMING' => 'BEFORE',
12
+ 'EVENT_MANIPULATION' => 'INSERT'
13
+ )
14
+
15
+ assert(t.table_name == 'authors')
16
+
17
+ assert(t.definition == 'BEGIN INSERT INTO blah SET id = NEW.id; END')
18
+ assert(t.timing == 'BEFORE')
19
+ assert(t.event == 'INSERT')
20
+
21
+ end
22
+
23
+
24
+
25
+ def test_not_equal
26
+ t1 = DbDiff::Trigger.new(
27
+ 'TRIGGER_NAME' => 'my_trig',
28
+ 'EVENT_OBJECT_TABLE' => 'authors',
29
+ 'ACTION_STATMENT' => 'BEGIN INSERT INTO blah SET id = NEW.id; END',
30
+ 'ACTION_TIMING' => 'BEFORE',
31
+ 'EVENT_MANIPULATION' => 'INSERT'
32
+ )
33
+
34
+ t2 = DbDiff::Trigger.new(
35
+ 'TRIGGER_NAME' => 'my_trig2',
36
+ 'EVENT_OBJECT_TABLE' => 'authors',
37
+ 'ACTION_STATMENT' => 'BEGIN INSERT INTO blah SET id = NEW.id; END',
38
+ 'ACTION_TIMING' => 'BEFORE',
39
+ 'EVENT_MANIPULATION' => 'INSERT'
40
+ )
41
+
42
+ assert(t1 != t2)
43
+
44
+ end
45
+
46
+
47
+ def test_equal
48
+ t1 = DbDiff::Trigger.new(
49
+ 'TRIGGER_NAME' => 'my_trig',
50
+ 'EVENT_OBJECT_TABLE' => 'authors',
51
+ 'ACTION_STATMENT' => 'BEGIN INSERT INTO blah SET id = NEW.id; END',
52
+ 'ACTION_TIMING' => 'BEFORE',
53
+ 'EVENT_MANIPULATION' => 'INSERT'
54
+ )
55
+
56
+ t2 = DbDiff::Trigger.new(
57
+ 'TRIGGER_NAME' => 'my_trig',
58
+ 'EVENT_OBJECT_TABLE' => 'authors',
59
+ 'ACTION_STATMENT' => 'BEGIN INSERT INTO blah SET id = NEW.id; END',
60
+ 'ACTION_TIMING' => 'BEFORE',
61
+ 'EVENT_MANIPULATION' => 'INSERT'
62
+ )
63
+
64
+ assert(t1 == t2)
65
+ end
66
+
67
+ end
68
+
@@ -0,0 +1,9 @@
1
+ CREATE TABLE authors (
2
+ `id` int(11) NOT NULL auto_increment,
3
+ `name` char(60) NOT NULL,
4
+ `address` char(60) NULL,
5
+ PRIMARY KEY (`id`)
6
+ ) ENGINE=innodb DEFAULT CHARSET=latin1;
7
+
8
+ create trigger my_auth BEFORE INSERT on authors FOR EACH ROW BEGIN SET NEW.name = 'fOO'; END;
9
+
@@ -0,0 +1,7 @@
1
+ CREATE TABLE authors (
2
+ `id` int(11) NOT NULL auto_increment,
3
+ `name` char(60) NOT NULL,
4
+ `address` char(60) NULL,
5
+ PRIMARY KEY (`id`)
6
+ ) ENGINE=innodb DEFAULT CHARSET=latin1;
7
+
@@ -0,0 +1,7 @@
1
+ CREATE TABLE authors (
2
+ `id` int(11) NOT NULL auto_increment,
3
+ `name` char(60) NOT NULL,
4
+ PRIMARY KEY (`id`)
5
+ ) ENGINE=innodb DEFAULT CHARSET=latin1;
6
+
7
+ CREATE VIEW authors_v as (SELECT * FROM authors);
@@ -0,0 +1,9 @@
1
+ CREATE TABLE authors (
2
+ `id` int(11) NOT NULL auto_increment,
3
+ `name` char(60) NOT NULL,
4
+ PRIMARY KEY (`id`)
5
+ ) ENGINE=innodb DEFAULT CHARSET=latin1;
6
+
7
+
8
+
9
+
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: dbdiff
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2006-09-10 00:00:00 -07:00
6
+ version: 0.2.0
7
+ date: 2006-09-19 00:00:00 -07:00
8
8
  summary: DbDiff performs diffs between two databases and applies changes
9
9
  require_paths:
10
10
  - lib
@@ -31,6 +31,7 @@ authors:
31
31
  files:
32
32
  - test/column
33
33
  - test/multi_unique_key
34
+ - test/procedure
34
35
  - test/test_row.rb
35
36
  - test/multi_key
36
37
  - test/test_key.rb
@@ -38,27 +39,39 @@ files:
38
39
  - test/suite.rb
39
40
  - test/test_column.rb
40
41
  - test/unique_key
42
+ - test/test_procedure.rb
41
43
  - test/table_fk2
42
44
  - test/table_fk
43
45
  - test/modify_key_fk
46
+ - test/view
44
47
  - test/test_dbdiff.rb
45
48
  - test/test_table.rb
46
49
  - test/modify_table
47
50
  - test/ai_column
48
51
  - test/modify_column
52
+ - test/modify_view
53
+ - test/test_function.rb
54
+ - test/trigger
49
55
  - test/fk
50
56
  - test/modify_key_fk_ref
51
57
  - test/change_pk
52
58
  - test/key
53
59
  - test/row
54
60
  - test/table
61
+ - test/test_trigger.rb
62
+ - test/modify_function
63
+ - test/modify_procedure
55
64
  - test/test_foreign_key.rb
56
65
  - test/modify_fk
66
+ - test/modify_trigger
67
+ - test/function
57
68
  - test/modify_row
58
69
  - test/column/source.sql
59
70
  - test/column/target.sql
60
71
  - test/multi_unique_key/source.sql
61
72
  - test/multi_unique_key/target.sql
73
+ - test/procedure/source.sql
74
+ - test/procedure/target.sql
62
75
  - test/multi_key/source.sql
63
76
  - test/multi_key/target.sql
64
77
  - test/multi_fk/source.sql
@@ -71,12 +84,18 @@ files:
71
84
  - test/table_fk/target.sql
72
85
  - test/modify_key_fk/source.sql
73
86
  - test/modify_key_fk/target.sql
87
+ - test/view/source.sql
88
+ - test/view/target.sql
74
89
  - test/modify_table/source.sql
75
90
  - test/modify_table/target.sql
76
91
  - test/ai_column/source.sql
77
92
  - test/ai_column/target.sql
78
93
  - test/modify_column/source.sql
79
94
  - test/modify_column/target.sql
95
+ - test/modify_view/source.sql
96
+ - test/modify_view/target.sql
97
+ - test/trigger/source.sql
98
+ - test/trigger/target.sql
80
99
  - test/fk/source.sql
81
100
  - test/fk/target.sql
82
101
  - test/modify_key_fk_ref/source.sql
@@ -89,8 +108,16 @@ files:
89
108
  - test/row/target.sql
90
109
  - test/table/source.sql
91
110
  - test/table/target.sql
111
+ - test/modify_function/source.sql
112
+ - test/modify_function/target.sql
113
+ - test/modify_procedure/source.sql
114
+ - test/modify_procedure/target.sql
92
115
  - test/modify_fk/source.sql
93
116
  - test/modify_fk/target.sql
117
+ - test/modify_trigger/source.sql
118
+ - test/modify_trigger/target.sql
119
+ - test/function/source.sql
120
+ - test/function/target.sql
94
121
  - test/modify_row/source.sql
95
122
  - test/modify_row/target.sql
96
123
  - lib/dbdiff.rb
@@ -98,14 +125,21 @@ files:
98
125
  - lib/dbdiff/key.rb
99
126
  - lib/dbdiff/row.rb
100
127
  - lib/dbdiff/foreign_key.rb
128
+ - lib/dbdiff/dbdiff_version.rb
101
129
  - lib/dbdiff/database.rb
102
130
  - lib/dbdiff/column.rb
131
+ - lib/dbdiff/routine.rb
103
132
  - lib/dbdiff/delta.rb
104
133
  - lib/dbdiff/table_element.rb
134
+ - lib/dbdiff/function.rb
135
+ - lib/dbdiff/procedure.rb
105
136
  - lib/dbdiff/table.rb
137
+ - lib/dbdiff/view.rb
138
+ - lib/dbdiff/trigger.rb
106
139
  - README
107
140
  - CHANGELOG
108
141
  - LICENSE
142
+ - COPYING
109
143
  test_files: []
110
144
 
111
145
  rdoc_options:
@@ -117,6 +151,7 @@ extra_rdoc_files:
117
151
  - README
118
152
  - CHANGELOG
119
153
  - LICENSE
154
+ - COPYING
120
155
  executables: []
121
156
 
122
157
  extensions: []