schema_transformer 0.3.0 → 0.3.1

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.
@@ -13,128 +13,128 @@ class SchemaTransformerTest < Test::Unit::TestCase
13
13
  File.delete(@transform_file) if File.exist?(@transform_file)
14
14
  end
15
15
 
16
- # def test_books_no_updated_at_no_data
17
- # @transformer = SchemaTransformer::Transform.new(@base, :batch_size => 10, :stagger => 0)
18
- # @conn.execute("delete from books")
19
- #
20
- # @transformer.expects(:gets).with(:table).returns("books")
21
- # @transformer.expects(:gets).with(:mod).returns("ADD COLUMN active tinyint(1) DEFAULT '0'")
22
- #
23
- # @transformer.generate
24
- # @transformer.gather_info("books")
25
- #
26
- # assert_table_exist("books")
27
- # assert_table_not_exist("books_st_temp")
28
- # @transformer.create
29
- # assert_table_exist("books_st_temp")
30
- #
31
- # @transformer.final_sync
32
- # end
33
- #
34
- # def test_books_no_updated_at_with_data
35
- # @transformer = SchemaTransformer::Transform.new(@base, :batch_size => 10, :stagger => 0)
36
- # @transformer.expects(:gets).with(:table).returns("books")
37
- # @transformer.expects(:gets).with(:mod).returns("ADD COLUMN active tinyint(1) DEFAULT '0'")
38
- #
39
- # @transformer.generate
40
- # @transformer.gather_info("books")
41
- #
42
- # assert_table_exist("books")
43
- # assert_table_not_exist("books_st_temp")
44
- # @transformer.create
45
- # assert_table_exist("books_st_temp")
46
- #
47
- # @transformer.final_sync
48
- # end
49
- #
50
- # def test_find_in_batches
51
- # i = 0
52
- # bounds = [[8, 17], [18, 27], [28,35]]
53
- # @transformer.find_in_batches("users", :start => 8, :batch_size => 10) do |batch|
54
- # # puts "batch #{batch.inspect}"
55
- # lower = batch.first
56
- # upper = batch.last
57
- # assert_equal bounds[i][0], lower
58
- # assert_equal bounds[i][1], upper
59
- # # puts("syncing over records #{lower} to #{upper}...")
60
- # i += 1
61
- # end
62
- # end
63
- #
64
- # def test_run_sync_black_box
65
- # @transformer.generate
66
- # c1 = count("users")
67
- # SchemaTransformer::Transform.run(:base => @base, :action => ["sync", "users"])
68
- # c2 = count("users_st_temp")
69
- # assert_equal c1, c2
70
- # end
71
- #
72
- # def test_run_sync_black_box_repeatedly
73
- # @transformer.generate
74
- # c1 = count("users")
75
- # # first run
76
- # SchemaTransformer::Transform.run(:base => @base, :action => ["sync", "users"])
77
- # assert_equal c1, count("users_st_temp")
78
- # @conn.execute("delete from users_st_temp order by id desc limit 10")
79
- # assert_equal c1, count("users_st_temp") + 10
80
- # # second run
81
- # SchemaTransformer::Transform.run(:base => @base, :action => ["sync", "users"])
82
- # assert_equal c1, count("users_st_temp")
83
- # end
84
- #
85
- # def test_run_switch_black_box
86
- # @transformer.generate
87
- # c1 = count("users")
88
- # SchemaTransformer::Transform.run(:base => @base, :action => ["sync", "users"])
89
- # c2 = count("users_st_temp")
90
- # assert_equal c1, c2
91
- # @conn.execute("delete from users_st_temp order by id desc limit 10")
92
- # assert_equal c1, count("users_st_temp") + 10
93
- #
94
- # # This is what Im testing
95
- # col1 = User.columns.size
96
- # SchemaTransformer::Transform.run(:base => @base, :action => ["switch", "users"])
97
- # User.reset_column_information
98
- # assert_equal col1 + 1, User.columns.size
99
- # assert_equal c1, count("users") # this is the new table
100
- # end
101
- #
102
- # def test_run_tranformations_white_box
103
- # @transformer.generate
104
- # @transformer.gather_info("users")
105
- #
106
- # assert_table_exist("users")
107
- # assert_table_not_exist("users_st_temp")
108
- # @transformer.create
109
- # assert_table_exist("users_st_temp")
110
- #
111
- # assert_equal 0, UsersStTemp.count
112
- # @transformer.sync
113
- # assert_equal User.count, UsersStTemp.count
114
- #
115
- # assert_table_exist("users")
116
- # @transformer.switch
117
- # assert_table_exist("users_st_trash")
118
- # assert_table_not_exist("users_st_temp")
119
- #
120
- # @transformer.cleanup
121
- # assert_table_exist("users")
122
- # assert_table_not_exist("users_st_trash")
123
- # assert_table_not_exist("users_st_temp")
124
- # end
125
- #
126
- # def test_generate_transformations
127
- # assert !File.exist?(@transform_file)
128
- # @transformer.generate
129
- # assert File.exist?(@transform_file)
130
- # data = JSON.parse(IO.read(@transform_file))
131
- # assert_equal "users", data["table"]
132
- # assert_match /ADD COLUMN/, data["mod"]
133
- #
134
- # @transformer.gather_info("users")
135
- # assert_equal "users", @transformer.instance_variable_get(:@table)
136
- # assert_match /ADD COLUMN/, @transformer.instance_variable_get(:@mod)
137
- # end
16
+ def test_books_no_updated_at_no_data
17
+ @transformer = SchemaTransformer::Transform.new(@base, :batch_size => 10, :stagger => 0)
18
+ @conn.execute("delete from books")
19
+
20
+ @transformer.expects(:gets).with(:table).returns("books")
21
+ @transformer.expects(:gets).with(:mod).returns("ADD COLUMN active tinyint(1) DEFAULT '0'")
22
+
23
+ @transformer.generate
24
+ @transformer.gather_info("books")
25
+
26
+ assert_table_exist("books")
27
+ assert_table_not_exist("books_st_temp")
28
+ @transformer.create
29
+ assert_table_exist("books_st_temp")
30
+
31
+ @transformer.final_sync
32
+ end
33
+
34
+ def test_books_no_updated_at_with_data
35
+ @transformer = SchemaTransformer::Transform.new(@base, :batch_size => 10, :stagger => 0)
36
+ @transformer.expects(:gets).with(:table).returns("books")
37
+ @transformer.expects(:gets).with(:mod).returns("ADD COLUMN active tinyint(1) DEFAULT '0'")
38
+
39
+ @transformer.generate
40
+ @transformer.gather_info("books")
41
+
42
+ assert_table_exist("books")
43
+ assert_table_not_exist("books_st_temp")
44
+ @transformer.create
45
+ assert_table_exist("books_st_temp")
46
+
47
+ @transformer.final_sync
48
+ end
49
+
50
+ def test_find_in_batches
51
+ i = 0
52
+ bounds = [[8, 17], [18, 27], [28,35]]
53
+ @transformer.find_in_batches("users", :start => 8, :batch_size => 10) do |batch|
54
+ # puts "batch #{batch.inspect}"
55
+ lower = batch.first
56
+ upper = batch.last
57
+ assert_equal bounds[i][0], lower
58
+ assert_equal bounds[i][1], upper
59
+ # puts("syncing over records #{lower} to #{upper}...")
60
+ i += 1
61
+ end
62
+ end
63
+
64
+ def test_run_sync_black_box
65
+ @transformer.generate
66
+ c1 = count("users")
67
+ SchemaTransformer::Transform.run(:base => @base, :action => ["sync", "users"])
68
+ c2 = count("users_st_temp")
69
+ assert_equal c1, c2
70
+ end
71
+
72
+ def test_run_sync_black_box_repeatedly
73
+ @transformer.generate
74
+ c1 = count("users")
75
+ # first run
76
+ SchemaTransformer::Transform.run(:base => @base, :action => ["sync", "users"])
77
+ assert_equal c1, count("users_st_temp")
78
+ @conn.execute("delete from users_st_temp order by id desc limit 10")
79
+ assert_equal c1, count("users_st_temp") + 10
80
+ # second run
81
+ SchemaTransformer::Transform.run(:base => @base, :action => ["sync", "users"])
82
+ assert_equal c1, count("users_st_temp")
83
+ end
84
+
85
+ def test_run_switch_black_box
86
+ @transformer.generate
87
+ c1 = count("users")
88
+ SchemaTransformer::Transform.run(:base => @base, :action => ["sync", "users"])
89
+ c2 = count("users_st_temp")
90
+ assert_equal c1, c2
91
+ @conn.execute("delete from users_st_temp order by id desc limit 10")
92
+ assert_equal c1, count("users_st_temp") + 10
93
+
94
+ # This is what Im testing
95
+ col1 = User.columns.size
96
+ SchemaTransformer::Transform.run(:base => @base, :action => ["switch", "users"])
97
+ User.reset_column_information
98
+ assert_equal col1 + 1, User.columns.size
99
+ assert_equal c1, count("users") # this is the new table
100
+ end
101
+
102
+ def test_run_tranformations_white_box
103
+ @transformer.generate
104
+ @transformer.gather_info("users")
105
+
106
+ assert_table_exist("users")
107
+ assert_table_not_exist("users_st_temp")
108
+ @transformer.create
109
+ assert_table_exist("users_st_temp")
110
+
111
+ assert_equal 0, UsersStTemp.count
112
+ @transformer.sync
113
+ assert_equal User.count, UsersStTemp.count
114
+
115
+ assert_table_exist("users")
116
+ @transformer.switch
117
+ assert_table_exist("users_st_trash")
118
+ assert_table_not_exist("users_st_temp")
119
+
120
+ @transformer.cleanup
121
+ assert_table_exist("users")
122
+ assert_table_not_exist("users_st_trash")
123
+ assert_table_not_exist("users_st_temp")
124
+ end
125
+
126
+ def test_generate_transformations
127
+ assert !File.exist?(@transform_file)
128
+ @transformer.generate
129
+ assert File.exist?(@transform_file)
130
+ data = JSON.parse(IO.read(@transform_file))
131
+ assert_equal "users", data["table"]
132
+ assert_match /ADD COLUMN/, data["mod"]
133
+
134
+ @transformer.gather_info("users")
135
+ assert_equal "users", @transformer.instance_variable_get(:@table)
136
+ assert_match /ADD COLUMN/, @transformer.instance_variable_get(:@mod)
137
+ end
138
138
 
139
139
  def test_analyze_timestamps
140
140
  @analyze = SchemaTransformer::Analyze.new(@base)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_transformer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 17
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tung Nguyen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-24 00:00:00 -07:00
18
+ date: 2011-01-31 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -29,6 +29,7 @@ extra_rdoc_files:
29
29
  - README.markdown
30
30
  files:
31
31
  - bin/schema_transformer
32
+ - CHANGELOG
32
33
  - gemspec.rb
33
34
  - lib/schema_transformer/analyze.rb
34
35
  - lib/schema_transformer/base.rb
@@ -40,7 +41,9 @@ files:
40
41
  - Rakefile
41
42
  - README.markdown
42
43
  - test/fake_app/config/database.yml
44
+ - test/fake_app/config/schema_transformations/articles.json
43
45
  - test/fake_app/config/schema_transformations/books.json
46
+ - test/fake_app/config/schema_transformations/users.json
44
47
  - test/fake_app/log/schema_transformer.log
45
48
  - test/schema_transformer_test.rb
46
49
  - test/test_helper.rb
@@ -75,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
78
  requirements: []
76
79
 
77
80
  rubyforge_project:
78
- rubygems_version: 1.3.7
81
+ rubygems_version: 1.4.2
79
82
  signing_key:
80
83
  specification_version: 3
81
84
  summary: Way is alter database schemas on large tables with little downtime