sequel 4.22.0 → 4.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +22 -0
- data/README.rdoc +6 -0
- data/Rakefile +59 -81
- data/doc/migration.rdoc +2 -0
- data/doc/release_notes/4.23.0.txt +65 -0
- data/doc/sharding.rdoc +16 -14
- data/doc/testing.rdoc +61 -77
- data/lib/sequel/adapters/jdbc.rb +1 -0
- data/lib/sequel/adapters/mock.rb +0 -1
- data/lib/sequel/adapters/postgres.rb +1 -0
- data/lib/sequel/adapters/postgresql.rb +1 -0
- data/lib/sequel/adapters/shared/postgres.rb +3 -3
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
- data/lib/sequel/connection_pool/threaded.rb +9 -1
- data/lib/sequel/database/connecting.rb +1 -1
- data/lib/sequel/database/transactions.rb +2 -1
- data/lib/sequel/dataset/prepared_statements.rb +1 -1
- data/lib/sequel/extensions/constraint_validations.rb +12 -12
- data/lib/sequel/extensions/date_arithmetic.rb +0 -4
- data/lib/sequel/extensions/pagination.rb +14 -2
- data/lib/sequel/extensions/pg_enum.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +1 -1
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +2 -0
- data/lib/sequel/plugins/delay_add_association.rb +50 -0
- data/lib/sequel/plugins/list.rb +2 -2
- data/lib/sequel/plugins/nested_attributes.rb +8 -28
- data/lib/sequel/plugins/update_refresh.rb +50 -0
- data/lib/sequel/plugins/validate_associated.rb +55 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +29 -29
- data/spec/adapters/firebird_spec.rb +97 -103
- data/spec/adapters/informix_spec.rb +25 -25
- data/spec/adapters/mssql_spec.rb +156 -172
- data/spec/adapters/mysql_spec.rb +334 -359
- data/spec/adapters/oracle_spec.rb +67 -69
- data/spec/adapters/postgres_spec.rb +1298 -1249
- data/spec/adapters/spec_helper.rb +2 -35
- data/spec/adapters/sqlanywhere_spec.rb +39 -39
- data/spec/adapters/sqlite_spec.rb +203 -200
- data/spec/bin_spec.rb +57 -59
- data/spec/core/connection_pool_spec.rb +402 -401
- data/spec/core/database_spec.rb +953 -944
- data/spec/core/dataset_spec.rb +2178 -2168
- data/spec/core/deprecated_spec.rb +19 -19
- data/spec/core/expression_filters_spec.rb +415 -415
- data/spec/core/mock_adapter_spec.rb +212 -212
- data/spec/core/object_graph_spec.rb +73 -73
- data/spec/core/placeholder_literalizer_spec.rb +71 -71
- data/spec/core/schema_generator_spec.rb +44 -44
- data/spec/core/schema_spec.rb +470 -472
- data/spec/core/spec_helper.rb +5 -20
- data/spec/core/version_spec.rb +2 -2
- data/spec/core_extensions_spec.rb +320 -320
- data/spec/extensions/accessed_columns_spec.rb +12 -12
- data/spec/extensions/active_model_spec.rb +3 -3
- data/spec/extensions/after_initialize_spec.rb +2 -2
- data/spec/extensions/arbitrary_servers_spec.rb +23 -23
- data/spec/extensions/association_dependencies_spec.rb +34 -34
- data/spec/extensions/association_pks_spec.rb +98 -98
- data/spec/extensions/association_proxies_spec.rb +33 -33
- data/spec/extensions/auto_validations_spec.rb +46 -46
- data/spec/extensions/blacklist_security_spec.rb +19 -18
- data/spec/extensions/blank_spec.rb +36 -36
- data/spec/extensions/boolean_readers_spec.rb +36 -36
- data/spec/extensions/caching_spec.rb +82 -82
- data/spec/extensions/class_table_inheritance_spec.rb +72 -72
- data/spec/extensions/column_conflicts_spec.rb +19 -14
- data/spec/extensions/column_select_spec.rb +19 -19
- data/spec/extensions/columns_introspection_spec.rb +43 -43
- data/spec/extensions/composition_spec.rb +64 -64
- data/spec/extensions/connection_validator_spec.rb +92 -90
- data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
- data/spec/extensions/constraint_validations_spec.rb +80 -80
- data/spec/extensions/core_refinements_spec.rb +220 -220
- data/spec/extensions/csv_serializer_spec.rb +44 -44
- data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
- data/spec/extensions/dataset_associations_spec.rb +65 -65
- data/spec/extensions/dataset_source_alias_spec.rb +16 -16
- data/spec/extensions/date_arithmetic_spec.rb +51 -58
- data/spec/extensions/defaults_setter_spec.rb +19 -19
- data/spec/extensions/delay_add_association_spec.rb +52 -0
- data/spec/extensions/dirty_spec.rb +51 -51
- data/spec/extensions/eager_each_spec.rb +8 -8
- data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
- data/spec/extensions/error_splitter_spec.rb +2 -2
- data/spec/extensions/error_sql_spec.rb +4 -4
- data/spec/extensions/eval_inspect_spec.rb +3 -3
- data/spec/extensions/filter_having_spec.rb +8 -8
- data/spec/extensions/force_encoding_spec.rb +30 -30
- data/spec/extensions/from_block_spec.rb +7 -7
- data/spec/extensions/graph_each_spec.rb +19 -19
- data/spec/extensions/hash_aliases_spec.rb +5 -5
- data/spec/extensions/hook_class_methods_spec.rb +100 -100
- data/spec/extensions/inflector_spec.rb +54 -54
- data/spec/extensions/input_transformer_spec.rb +10 -10
- data/spec/extensions/insert_returning_select_spec.rb +8 -8
- data/spec/extensions/instance_filters_spec.rb +26 -26
- data/spec/extensions/instance_hooks_spec.rb +85 -85
- data/spec/extensions/json_serializer_spec.rb +68 -68
- data/spec/extensions/lazy_attributes_spec.rb +49 -49
- data/spec/extensions/list_spec.rb +77 -75
- data/spec/extensions/looser_typecasting_spec.rb +16 -16
- data/spec/extensions/many_through_many_spec.rb +627 -627
- data/spec/extensions/meta_def_spec.rb +7 -7
- data/spec/extensions/migration_spec.rb +217 -217
- data/spec/extensions/modification_detection_spec.rb +20 -20
- data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
- data/spec/extensions/named_timezones_spec.rb +18 -18
- data/spec/extensions/nested_attributes_spec.rb +107 -107
- data/spec/extensions/null_dataset_spec.rb +24 -24
- data/spec/extensions/optimistic_locking_spec.rb +21 -21
- data/spec/extensions/pagination_spec.rb +52 -52
- data/spec/extensions/pg_array_associations_spec.rb +273 -273
- data/spec/extensions/pg_array_ops_spec.rb +52 -52
- data/spec/extensions/pg_array_spec.rb +152 -152
- data/spec/extensions/pg_enum_spec.rb +13 -13
- data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
- data/spec/extensions/pg_hstore_spec.rb +84 -84
- data/spec/extensions/pg_inet_spec.rb +15 -15
- data/spec/extensions/pg_interval_spec.rb +29 -29
- data/spec/extensions/pg_json_ops_spec.rb +86 -84
- data/spec/extensions/pg_json_spec.rb +104 -104
- data/spec/extensions/pg_loose_count_spec.rb +6 -6
- data/spec/extensions/pg_range_ops_spec.rb +24 -24
- data/spec/extensions/pg_range_spec.rb +143 -143
- data/spec/extensions/pg_row_ops_spec.rb +14 -14
- data/spec/extensions/pg_row_plugin_spec.rb +12 -12
- data/spec/extensions/pg_row_spec.rb +118 -118
- data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
- data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
- data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
- data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
- data/spec/extensions/prepared_statements_spec.rb +28 -28
- data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
- data/spec/extensions/pretty_table_spec.rb +16 -16
- data/spec/extensions/query_literals_spec.rb +37 -37
- data/spec/extensions/query_spec.rb +32 -32
- data/spec/extensions/rcte_tree_spec.rb +141 -141
- data/spec/extensions/round_timestamps_spec.rb +21 -21
- data/spec/extensions/schema_caching_spec.rb +8 -8
- data/spec/extensions/schema_dumper_spec.rb +78 -78
- data/spec/extensions/schema_spec.rb +31 -27
- data/spec/extensions/scissors_spec.rb +3 -3
- data/spec/extensions/select_remove_spec.rb +14 -14
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
- data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
- data/spec/extensions/serialization_spec.rb +79 -78
- data/spec/extensions/server_block_spec.rb +17 -17
- data/spec/extensions/set_overrides_spec.rb +30 -30
- data/spec/extensions/sharding_spec.rb +65 -65
- data/spec/extensions/shared_caching_spec.rb +29 -29
- data/spec/extensions/single_table_inheritance_spec.rb +79 -79
- data/spec/extensions/skip_create_refresh_spec.rb +3 -3
- data/spec/extensions/spec_helper.rb +4 -29
- data/spec/extensions/split_array_nil_spec.rb +9 -9
- data/spec/extensions/split_values_spec.rb +7 -7
- data/spec/extensions/sql_expr_spec.rb +32 -32
- data/spec/extensions/static_cache_spec.rb +123 -123
- data/spec/extensions/string_date_time_spec.rb +34 -34
- data/spec/extensions/string_stripper_spec.rb +15 -15
- data/spec/extensions/subclasses_spec.rb +31 -31
- data/spec/extensions/table_select_spec.rb +15 -15
- data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
- data/spec/extensions/thread_local_timezones_spec.rb +13 -13
- data/spec/extensions/timestamps_spec.rb +40 -40
- data/spec/extensions/to_dot_spec.rb +34 -34
- data/spec/extensions/touch_spec.rb +52 -52
- data/spec/extensions/tree_spec.rb +72 -72
- data/spec/extensions/typecast_on_load_spec.rb +25 -25
- data/spec/extensions/unlimited_update_spec.rb +2 -2
- data/spec/extensions/update_or_create_spec.rb +36 -36
- data/spec/extensions/update_primary_key_spec.rb +35 -35
- data/spec/extensions/update_refresh_spec.rb +41 -0
- data/spec/extensions/validate_associated_spec.rb +52 -0
- data/spec/extensions/validation_class_methods_spec.rb +314 -317
- data/spec/extensions/validation_helpers_spec.rb +195 -195
- data/spec/extensions/xml_serializer_spec.rb +48 -48
- data/spec/guards_helper.rb +55 -0
- data/spec/integration/associations_test.rb +1089 -1088
- data/spec/integration/database_test.rb +29 -29
- data/spec/integration/dataset_test.rb +661 -661
- data/spec/integration/eager_loader_test.rb +147 -147
- data/spec/integration/migrator_test.rb +122 -122
- data/spec/integration/model_test.rb +70 -70
- data/spec/integration/plugin_test.rb +682 -640
- data/spec/integration/prepared_statement_test.rb +172 -172
- data/spec/integration/schema_test.rb +245 -245
- data/spec/integration/spec_helper.rb +1 -64
- data/spec/integration/timezone_test.rb +17 -17
- data/spec/integration/transaction_test.rb +87 -87
- data/spec/integration/type_test.rb +33 -33
- data/spec/model/association_reflection_spec.rb +130 -121
- data/spec/model/associations_spec.rb +1112 -1113
- data/spec/model/base_spec.rb +197 -196
- data/spec/model/class_dataset_methods_spec.rb +118 -118
- data/spec/model/dataset_methods_spec.rb +49 -49
- data/spec/model/eager_loading_spec.rb +705 -702
- data/spec/model/hooks_spec.rb +169 -168
- data/spec/model/inflector_spec.rb +5 -5
- data/spec/model/model_spec.rb +287 -297
- data/spec/model/plugins_spec.rb +47 -47
- data/spec/model/record_spec.rb +534 -535
- data/spec/model/spec_helper.rb +3 -21
- data/spec/model/validations_spec.rb +72 -70
- data/spec/spec_config.rb +8 -0
- metadata +41 -9
- data/lib/sequel/adapters/fdbsql.rb +0 -286
- data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
- data/lib/sequel/adapters/openbase.rb +0 -54
- data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
- data/spec/adapters/fdbsql_spec.rb +0 -429
- data/spec/rspec_helper.rb +0 -22
@@ -1,21 +1,21 @@
|
|
1
1
|
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
2
2
|
|
3
3
|
describe "Sequel::Metaprogramming" do
|
4
|
-
|
4
|
+
it "should add meta_def method to Database, Dataset, and Model classes and instances" do
|
5
5
|
Sequel::Database.meta_def(:foo){1}
|
6
|
-
Sequel::Database.foo.
|
6
|
+
Sequel::Database.foo.must_equal 1
|
7
7
|
Sequel::Dataset.meta_def(:foo){2}
|
8
|
-
Sequel::Dataset.foo.
|
8
|
+
Sequel::Dataset.foo.must_equal 2
|
9
9
|
Sequel::Model.meta_def(:foo){3}
|
10
|
-
Sequel::Model.foo.
|
10
|
+
Sequel::Model.foo.must_equal 3
|
11
11
|
o = Sequel::Database.new
|
12
12
|
o.meta_def(:foo){4}
|
13
|
-
o.foo.
|
13
|
+
o.foo.must_equal 4
|
14
14
|
o = o[:a]
|
15
15
|
o.meta_def(:foo){5}
|
16
|
-
o.foo.
|
16
|
+
o.foo.must_equal 5
|
17
17
|
o = Sequel::Model.new
|
18
18
|
o.meta_def(:foo){6}
|
19
|
-
o.foo.
|
19
|
+
o.foo.must_equal 6
|
20
20
|
end
|
21
21
|
end
|
@@ -7,26 +7,26 @@ describe "Migration.descendants" do
|
|
7
7
|
Sequel::Migration.descendants.clear
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
it "should include Migration subclasses" do
|
11
11
|
@class = Class.new(Sequel::Migration)
|
12
12
|
|
13
|
-
Sequel::Migration.descendants.
|
13
|
+
Sequel::Migration.descendants.must_equal [@class]
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
it "should include Migration subclasses in order of creation" do
|
17
17
|
@c1 = Class.new(Sequel::Migration)
|
18
18
|
@c2 = Class.new(Sequel::Migration)
|
19
19
|
@c3 = Class.new(Sequel::Migration)
|
20
20
|
|
21
|
-
Sequel::Migration.descendants.
|
21
|
+
Sequel::Migration.descendants.must_equal [@c1, @c2, @c3]
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
it "should include SimpleMigration instances created by migration DSL" do
|
25
25
|
i1 = Sequel.migration{}
|
26
26
|
i2 = Sequel.migration{}
|
27
27
|
i3 = Sequel.migration{}
|
28
28
|
|
29
|
-
Sequel::Migration.descendants.
|
29
|
+
Sequel::Migration.descendants.must_equal [i1, i2, i3]
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -39,29 +39,29 @@ describe "Migration.apply" do
|
|
39
39
|
@db = @c.new
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
proc {Sequel::Migration.apply(@db, :hahaha)}.
|
42
|
+
it "should raise for an invalid direction" do
|
43
|
+
proc {Sequel::Migration.apply(@db, :hahaha)}.must_raise(ArgumentError)
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
it "should apply the up and down directions correctly" do
|
47
47
|
m = Class.new(Sequel::Migration) do
|
48
48
|
define_method(:up) {one(3333)}
|
49
49
|
define_method(:down) {two(4444)}
|
50
50
|
end
|
51
|
-
m.apply(@db, :up).
|
52
|
-
m.apply(@db, :down).
|
51
|
+
m.apply(@db, :up).must_equal [1111, 3333]
|
52
|
+
m.apply(@db, :down).must_equal [2222, 4444]
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
it "should have default up and down actions that do nothing" do
|
56
56
|
m = Class.new(Sequel::Migration)
|
57
|
-
m.apply(@db, :up).
|
58
|
-
m.apply(@db, :down).
|
57
|
+
m.apply(@db, :up).must_equal nil
|
58
|
+
m.apply(@db, :down).must_equal nil
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
it "should respond to the methods the database responds to" do
|
62
62
|
m = Sequel::Migration.new(Sequel.mock)
|
63
|
-
m.respond_to?(:foo).
|
64
|
-
m.respond_to?(:execute).
|
63
|
+
m.respond_to?(:foo).must_equal false
|
64
|
+
m.respond_to?(:execute).must_equal true
|
65
65
|
end if RUBY_VERSION >= '1.9'
|
66
66
|
end
|
67
67
|
|
@@ -74,23 +74,23 @@ describe "SimpleMigration#apply" do
|
|
74
74
|
@db = @c.new
|
75
75
|
end
|
76
76
|
|
77
|
-
|
78
|
-
proc {Sequel.migration{}.apply(@db, :hahaha)}.
|
77
|
+
it "should raise for an invalid direction" do
|
78
|
+
proc {Sequel.migration{}.apply(@db, :hahaha)}.must_raise(ArgumentError)
|
79
79
|
end
|
80
80
|
|
81
|
-
|
81
|
+
it "should apply the up and down directions correctly" do
|
82
82
|
m = Sequel.migration do
|
83
83
|
up{one(3333)}
|
84
84
|
down{two(4444)}
|
85
85
|
end
|
86
|
-
m.apply(@db, :up).
|
87
|
-
m.apply(@db, :down).
|
86
|
+
m.apply(@db, :up).must_equal [1111, 3333]
|
87
|
+
m.apply(@db, :down).must_equal [2222, 4444]
|
88
88
|
end
|
89
89
|
|
90
|
-
|
90
|
+
it "should have default up and down actions that do nothing" do
|
91
91
|
m = Sequel.migration{}
|
92
|
-
m.apply(@db, :up).
|
93
|
-
m.apply(@db, :down).
|
92
|
+
m.apply(@db, :up).must_equal nil
|
93
|
+
m.apply(@db, :down).must_equal nil
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -143,10 +143,10 @@ describe "Reversible Migrations with Sequel.migration{change{}}" do
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
|
146
|
+
it "should apply up with normal actions in normal order" do
|
147
147
|
p = @p
|
148
148
|
Sequel.migration{change(&p)}.apply(@db, :up)
|
149
|
-
@db.actions.
|
149
|
+
@db.actions.must_equal [[:create_table, :a, {:foo=>:bar}],
|
150
150
|
[:add_column, :a, :b, String],
|
151
151
|
[:add_index, :a, :b],
|
152
152
|
[:rename_column, :a, :b, :c],
|
@@ -167,10 +167,10 @@ describe "Reversible Migrations with Sequel.migration{change{}}" do
|
|
167
167
|
[:create_join_table, {:cat_id=>:cats, :dog_id=>:dogs}]]
|
168
168
|
end
|
169
169
|
|
170
|
-
|
170
|
+
it "should execute down with reversing actions in reverse order" do
|
171
171
|
p = @p
|
172
172
|
Sequel.migration{change(&p)}.apply(@db, :down)
|
173
|
-
@db.actions.
|
173
|
+
@db.actions.must_equal [
|
174
174
|
[:drop_join_table, {:cat_id=>:cats, :dog_id=>:dogs}],
|
175
175
|
[:drop_view, :c, {:foo=>:bar}],
|
176
176
|
[:alter_table, [
|
@@ -192,37 +192,37 @@ describe "Reversible Migrations with Sequel.migration{change{}}" do
|
|
192
192
|
[:drop_table, :a, {:foo=>:bar}]]
|
193
193
|
end
|
194
194
|
|
195
|
-
|
195
|
+
it "should raise in the down direction if migration uses unsupported method" do
|
196
196
|
m = Sequel.migration{change{run 'SQL'}}
|
197
|
-
|
198
|
-
proc{m.apply(@db, :down)}.
|
197
|
+
m.apply(@db, :up)
|
198
|
+
proc{m.apply(@db, :down)}.must_raise(Sequel::Error)
|
199
199
|
end
|
200
200
|
|
201
|
-
|
201
|
+
it "should raise in the down direction if migration uses add_primary_key with an array" do
|
202
202
|
m = Sequel.migration{change{alter_table(:a){add_primary_key [:b]}}}
|
203
|
-
|
204
|
-
proc{m.apply(@db, :down)}.
|
203
|
+
m.apply(@db, :up)
|
204
|
+
proc{m.apply(@db, :down)}.must_raise(Sequel::Error)
|
205
205
|
end
|
206
206
|
|
207
|
-
|
207
|
+
it "should raise in the down direction if migration uses add_foreign_key with an array" do
|
208
208
|
m = Sequel.migration{change{alter_table(:a){add_foreign_key [:b]}}}
|
209
|
-
|
210
|
-
proc{m.apply(@db, :down)}.
|
209
|
+
m.apply(@db, :up)
|
210
|
+
proc{m.apply(@db, :down)}.must_raise(Sequel::Error)
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
214
214
|
describe "Sequel::Migrator.migrator_class" do
|
215
|
-
|
216
|
-
Sequel::Migrator.migrator_class("spec/files/integer_migrations").
|
215
|
+
it "should return IntegerMigrator if not using timestamp migrations" do
|
216
|
+
Sequel::Migrator.migrator_class("spec/files/integer_migrations").must_equal Sequel::IntegerMigrator
|
217
217
|
end
|
218
218
|
|
219
|
-
|
220
|
-
Sequel::Migrator.migrator_class('spec/files/timestamped_migrations').
|
219
|
+
it "should return TimestampMigrator if using timestamp migrations" do
|
220
|
+
Sequel::Migrator.migrator_class('spec/files/timestamped_migrations').must_equal Sequel::TimestampMigrator
|
221
221
|
end
|
222
222
|
|
223
|
-
|
224
|
-
Sequel::IntegerMigrator.migrator_class("spec/files/timestamped_migrations").
|
225
|
-
Sequel::TimestampMigrator.migrator_class("spec/files/integer_migrations").
|
223
|
+
it "should return self if run on a subclass" do
|
224
|
+
Sequel::IntegerMigrator.migrator_class("spec/files/timestamped_migrations").must_equal Sequel::IntegerMigrator
|
225
|
+
Sequel::TimestampMigrator.migrator_class("spec/files/integer_migrations").must_equal Sequel::TimestampMigrator
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
@@ -273,126 +273,126 @@ describe "Sequel::IntegerMigrator" do
|
|
273
273
|
Object.send(:remove_const, "CreateSessions") if Object.const_defined?("CreateSessions")
|
274
274
|
end
|
275
275
|
|
276
|
-
|
277
|
-
proc{Sequel::Migrator.apply(@db, "spec/files/missing_integer_migrations")}.
|
276
|
+
it "should raise and error if there is a missing integer migration version" do
|
277
|
+
proc{Sequel::Migrator.apply(@db, "spec/files/missing_integer_migrations")}.must_raise(Sequel::Migrator::Error)
|
278
278
|
end
|
279
279
|
|
280
|
-
|
280
|
+
it "should not raise and error if there is a missing integer migration version and allow_missing_migration_files is true" do
|
281
281
|
Sequel::Migrator.run(@db, "spec/files/missing_integer_migrations", :allow_missing_migration_files => true)
|
282
|
-
@db.sqls.last.
|
282
|
+
@db.sqls.last.must_equal "UPDATE schema_info SET version = 3"
|
283
283
|
Sequel::Migrator.run(@db, "spec/files/missing_integer_migrations", :allow_missing_migration_files => true, :target=>0)
|
284
|
-
@db.sqls.last.
|
284
|
+
@db.sqls.last.must_equal "UPDATE schema_info SET version = 0"
|
285
285
|
end
|
286
286
|
|
287
|
-
|
288
|
-
proc{Sequel::Migrator.apply(@db, "spec/files/duplicate_integer_migrations")}.
|
287
|
+
it "should raise and error if there is a duplicate integer migration version" do
|
288
|
+
proc{Sequel::Migrator.apply(@db, "spec/files/duplicate_integer_migrations")}.must_raise(Sequel::Migrator::Error)
|
289
289
|
end
|
290
290
|
|
291
|
-
|
291
|
+
it "should add a column name if it doesn't already exist in the schema_info table" do
|
292
292
|
@db.create_table(:schema_info){Integer :v}
|
293
|
-
@db.
|
293
|
+
def @db.alter_table(*); end
|
294
294
|
Sequel::Migrator.apply(@db, @dirname)
|
295
295
|
end
|
296
296
|
|
297
|
-
|
298
|
-
@db.table_exists?(:schema_info).
|
297
|
+
it "should automatically create the schema_info table with the version column" do
|
298
|
+
@db.table_exists?(:schema_info).must_equal false
|
299
299
|
Sequel::Migrator.run(@db, @dirname, :target=>0)
|
300
|
-
@db.table_exists?(:schema_info).
|
301
|
-
@db.dataset.columns.
|
300
|
+
@db.table_exists?(:schema_info).must_equal true
|
301
|
+
@db.dataset.columns.must_equal [:version]
|
302
302
|
end
|
303
303
|
|
304
|
-
|
305
|
-
@db.table_exists?(:si).
|
304
|
+
it "should allow specifying the table and columns" do
|
305
|
+
@db.table_exists?(:si).must_equal false
|
306
306
|
Sequel::Migrator.run(@db, @dirname, :target=>0, :table=>:si, :column=>:sic)
|
307
|
-
@db.table_exists?(:si).
|
308
|
-
@db.dataset.columns.
|
307
|
+
@db.table_exists?(:si).must_equal true
|
308
|
+
@db.dataset.columns.must_equal [:sic]
|
309
309
|
end
|
310
310
|
|
311
|
-
|
311
|
+
it "should apply migrations correctly in the up direction if no target is given" do
|
312
312
|
Sequel::Migrator.apply(@db, @dirname)
|
313
|
-
@db.creates.
|
314
|
-
@db.version.
|
315
|
-
@db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.
|
313
|
+
@db.creates.must_equal [1111, 2222, 3333]
|
314
|
+
@db.version.must_equal 3
|
315
|
+
@db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.must_equal [1, 2, 3]
|
316
316
|
end
|
317
317
|
|
318
|
-
|
319
|
-
Sequel::Migrator.is_current?(@db, @dirname).
|
318
|
+
it "should be able to tell whether there are outstanding migrations" do
|
319
|
+
Sequel::Migrator.is_current?(@db, @dirname).must_equal false
|
320
320
|
Sequel::Migrator.apply(@db, @dirname)
|
321
|
-
Sequel::Migrator.is_current?(@db, @dirname).
|
321
|
+
Sequel::Migrator.is_current?(@db, @dirname).must_equal true
|
322
322
|
end
|
323
323
|
|
324
|
-
|
325
|
-
proc{Sequel::Migrator.check_current(@db, @dirname)}.
|
324
|
+
it "should have #check_current raise an exception if the migrator is not current" do
|
325
|
+
proc{Sequel::Migrator.check_current(@db, @dirname)}.must_raise(Sequel::Migrator::NotCurrentError)
|
326
326
|
Sequel::Migrator.apply(@db, @dirname)
|
327
|
-
|
327
|
+
Sequel::Migrator.check_current(@db, @dirname)
|
328
328
|
end
|
329
329
|
|
330
|
-
|
330
|
+
it "should apply migrations correctly in the up direction with target" do
|
331
331
|
Sequel::Migrator.apply(@db, @dirname, 2)
|
332
|
-
@db.creates.
|
333
|
-
@db.version.
|
334
|
-
@db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.
|
332
|
+
@db.creates.must_equal [1111, 2222]
|
333
|
+
@db.version.must_equal 2
|
334
|
+
@db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.must_equal [1, 2]
|
335
335
|
end
|
336
336
|
|
337
|
-
|
337
|
+
it "should apply migrations correctly in the up direction with target and existing" do
|
338
338
|
Sequel::Migrator.apply(@db, @dirname, 2, 1)
|
339
|
-
@db.creates.
|
340
|
-
@db.version.
|
341
|
-
@db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.
|
339
|
+
@db.creates.must_equal [2222]
|
340
|
+
@db.version.must_equal 2
|
341
|
+
@db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.must_equal [2]
|
342
342
|
end
|
343
343
|
|
344
|
-
|
344
|
+
it "should apply migrations correctly in the down direction with target" do
|
345
345
|
@db.create_table(:schema_info){Integer :version, :default=>0}
|
346
346
|
@db[:schema_info].insert(:version=>3)
|
347
|
-
@db.version.
|
347
|
+
@db.version.must_equal 3
|
348
348
|
Sequel::Migrator.apply(@db, @dirname, 0)
|
349
|
-
@db.drops.
|
350
|
-
@db.version.
|
351
|
-
@db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.
|
349
|
+
@db.drops.must_equal [3333, 2222, 1111]
|
350
|
+
@db.version.must_equal 0
|
351
|
+
@db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.must_equal [2, 1, 0]
|
352
352
|
end
|
353
353
|
|
354
|
-
|
354
|
+
it "should apply migrations correctly in the down direction with target and existing" do
|
355
355
|
Sequel::Migrator.apply(@db, @dirname, 1, 2)
|
356
|
-
@db.drops.
|
357
|
-
@db.version.
|
358
|
-
@db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.
|
356
|
+
@db.drops.must_equal [2222]
|
357
|
+
@db.version.must_equal 1
|
358
|
+
@db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.must_equal [1]
|
359
359
|
end
|
360
360
|
|
361
|
-
|
362
|
-
Sequel::Migrator.apply(@db, @dirname, 3, 2).
|
363
|
-
Sequel::Migrator.apply(@db, @dirname, 0).
|
364
|
-
Sequel::Migrator.apply(@db, @dirname).
|
361
|
+
it "should return the target version" do
|
362
|
+
Sequel::Migrator.apply(@db, @dirname, 3, 2).must_equal 3
|
363
|
+
Sequel::Migrator.apply(@db, @dirname, 0).must_equal 0
|
364
|
+
Sequel::Migrator.apply(@db, @dirname).must_equal 3
|
365
365
|
end
|
366
366
|
|
367
|
-
|
368
|
-
proc{Sequel::IntegerMigrator.apply(@db, "spec/files/timestamped_migrations")}.
|
367
|
+
it "should use IntegerMigrator if IntegerMigrator.apply called, even for timestamped migration directory" do
|
368
|
+
proc{Sequel::IntegerMigrator.apply(@db, "spec/files/timestamped_migrations")}.must_raise(Sequel::Migrator::Error)
|
369
369
|
end
|
370
370
|
|
371
|
-
|
371
|
+
it "should not use transactions by default" do
|
372
372
|
Sequel::Migrator.apply(@db, "spec/files/transaction_unspecified_migrations")
|
373
|
-
@db.sqls.
|
373
|
+
@db.sqls.must_equal ["CREATE TABLE schema_info (version integer DEFAULT 0 NOT NULL)", "SELECT 1 AS one FROM schema_info LIMIT 1", "INSERT INTO schema_info (version) VALUES (0)", "SELECT version FROM schema_info LIMIT 1", "CREATE TABLE sm11111 (smc1 integer)", "UPDATE schema_info SET version = 1", "CREATE TABLE sm (smc1 integer)", "UPDATE schema_info SET version = 2"]
|
374
374
|
end
|
375
375
|
|
376
|
-
|
376
|
+
it "should use transactions by default if the database supports transactional ddl" do
|
377
377
|
@db.meta_def(:supports_transactional_ddl?){true}
|
378
378
|
Sequel::Migrator.apply(@db, "spec/files/transaction_unspecified_migrations")
|
379
|
-
@db.sqls.
|
379
|
+
@db.sqls.must_equal ["CREATE TABLE schema_info (version integer DEFAULT 0 NOT NULL)", "SELECT 1 AS one FROM schema_info LIMIT 1", "INSERT INTO schema_info (version) VALUES (0)", "SELECT version FROM schema_info LIMIT 1", "BEGIN", "CREATE TABLE sm11111 (smc1 integer)", "UPDATE schema_info SET version = 1", "COMMIT", "BEGIN", "CREATE TABLE sm (smc1 integer)", "UPDATE schema_info SET version = 2", "COMMIT"]
|
380
380
|
end
|
381
381
|
|
382
|
-
|
382
|
+
it "should respect transaction use on a per migration basis" do
|
383
383
|
@db.meta_def(:supports_transactional_ddl?){true}
|
384
384
|
Sequel::Migrator.apply(@db, "spec/files/transaction_specified_migrations")
|
385
|
-
@db.sqls.
|
385
|
+
@db.sqls.must_equal ["CREATE TABLE schema_info (version integer DEFAULT 0 NOT NULL)", "SELECT 1 AS one FROM schema_info LIMIT 1", "INSERT INTO schema_info (version) VALUES (0)", "SELECT version FROM schema_info LIMIT 1", "BEGIN", "CREATE TABLE sm11111 (smc1 integer)", "UPDATE schema_info SET version = 1", "COMMIT", "CREATE TABLE sm (smc1 integer)", "UPDATE schema_info SET version = 2"]
|
386
386
|
end
|
387
387
|
|
388
|
-
|
388
|
+
it "should force transactions if enabled in the migrator" do
|
389
389
|
Sequel::Migrator.run(@db, "spec/files/transaction_specified_migrations", :use_transactions=>true)
|
390
|
-
@db.sqls.
|
390
|
+
@db.sqls.must_equal ["CREATE TABLE schema_info (version integer DEFAULT 0 NOT NULL)", "SELECT 1 AS one FROM schema_info LIMIT 1", "INSERT INTO schema_info (version) VALUES (0)", "SELECT version FROM schema_info LIMIT 1", "BEGIN", "CREATE TABLE sm11111 (smc1 integer)", "UPDATE schema_info SET version = 1", "COMMIT", "BEGIN", "CREATE TABLE sm (smc1 integer)", "UPDATE schema_info SET version = 2", "COMMIT"]
|
391
391
|
end
|
392
392
|
|
393
|
-
|
393
|
+
it "should not use transactions if disabled in the migrator" do
|
394
394
|
Sequel::Migrator.run(@db, "spec/files/transaction_unspecified_migrations", :use_transactions=>false)
|
395
|
-
@db.sqls.
|
395
|
+
@db.sqls.must_equal ["CREATE TABLE schema_info (version integer DEFAULT 0 NOT NULL)", "SELECT 1 AS one FROM schema_info LIMIT 1", "INSERT INTO schema_info (version) VALUES (0)", "SELECT version FROM schema_info LIMIT 1", "CREATE TABLE sm11111 (smc1 integer)", "UPDATE schema_info SET version = 1", "CREATE TABLE sm (smc1 integer)", "UPDATE schema_info SET version = 2"]
|
396
396
|
end
|
397
397
|
end
|
398
398
|
|
@@ -474,239 +474,239 @@ describe "Sequel::TimestampMigrator" do
|
|
474
474
|
Object.send(:remove_const, "CreateAlbums") if Object.const_defined?("CreateAlbums")
|
475
475
|
end
|
476
476
|
|
477
|
-
|
477
|
+
it "should handle migrating up or down all the way" do
|
478
478
|
@dir = 'spec/files/timestamped_migrations'
|
479
479
|
@m.apply(@db, @dir)
|
480
|
-
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
481
|
-
@db[:schema_migrations].select_order_map(:filename).
|
480
|
+
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
481
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb 1273253853_3_create_users.rb'
|
482
482
|
@m.apply(@db, @dir, 0)
|
483
|
-
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
484
|
-
@db[:schema_migrations].select_order_map(:filename).
|
483
|
+
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
484
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal []
|
485
485
|
end
|
486
486
|
|
487
|
-
|
487
|
+
it "should handle migrating up or down to specific timestamps" do
|
488
488
|
@dir = 'spec/files/timestamped_migrations'
|
489
489
|
@m.apply(@db, @dir, 1273253851)
|
490
|
-
[:schema_migrations, :sm1111, :sm2222].each{|n| @db.table_exists?(n).
|
491
|
-
@db.table_exists?(:sm3333).
|
492
|
-
@db[:schema_migrations].select_order_map(:filename).
|
490
|
+
[:schema_migrations, :sm1111, :sm2222].each{|n| @db.table_exists?(n).must_equal true}
|
491
|
+
@db.table_exists?(:sm3333).must_equal false
|
492
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb'
|
493
493
|
@m.apply(@db, @dir, 1273253849)
|
494
|
-
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
495
|
-
@db.table_exists?(:sm1111).
|
496
|
-
@db[:schema_migrations].select_order_map(:filename).
|
494
|
+
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
495
|
+
@db.table_exists?(:sm1111).must_equal true
|
496
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb'
|
497
497
|
end
|
498
498
|
|
499
|
-
|
499
|
+
it "should not be current when there are migrations to apply" do
|
500
500
|
@dir = 'spec/files/timestamped_migrations'
|
501
501
|
@m.apply(@db, @dir)
|
502
|
-
@m.is_current?(@db, @dir).
|
502
|
+
@m.is_current?(@db, @dir).must_equal true
|
503
503
|
@dir = 'spec/files/interleaved_timestamped_migrations'
|
504
|
-
@m.is_current?(@db, @dir).
|
504
|
+
@m.is_current?(@db, @dir).must_equal false
|
505
505
|
end
|
506
506
|
|
507
|
-
|
507
|
+
it "should raise an exception if the migrator is not current" do
|
508
508
|
@dir = 'spec/files/timestamped_migrations'
|
509
509
|
@m.apply(@db, @dir)
|
510
|
-
|
510
|
+
@m.check_current(@db, @dir)
|
511
511
|
@dir = 'spec/files/interleaved_timestamped_migrations'
|
512
|
-
proc{@m.check_current(@db, @dir)}.
|
512
|
+
proc{@m.check_current(@db, @dir)}.must_raise(Sequel::Migrator::NotCurrentError)
|
513
513
|
end
|
514
514
|
|
515
|
-
|
515
|
+
it "should apply all missing files when migrating up" do
|
516
516
|
@dir = 'spec/files/timestamped_migrations'
|
517
517
|
@m.apply(@db, @dir)
|
518
518
|
@dir = 'spec/files/interleaved_timestamped_migrations'
|
519
519
|
@m.apply(@db, @dir)
|
520
|
-
[:schema_migrations, :sm1111, :sm1122, :sm2222, :sm2233, :sm3333].each{|n| @db.table_exists?(n).
|
521
|
-
@db[:schema_migrations].select_order_map(:filename).
|
520
|
+
[:schema_migrations, :sm1111, :sm1122, :sm2222, :sm2233, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
521
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253850_create_artists.rb 1273253851_create_nodes.rb 1273253852_create_albums.rb 1273253853_3_create_users.rb'
|
522
522
|
end
|
523
523
|
|
524
|
-
|
524
|
+
it "should not apply down action to migrations where up action hasn't been applied" do
|
525
525
|
@dir = 'spec/files/timestamped_migrations'
|
526
526
|
@m.apply(@db, @dir)
|
527
527
|
@dir = 'spec/files/interleaved_timestamped_migrations'
|
528
528
|
@m.apply(@db, @dir, 0)
|
529
|
-
[:sm1111, :sm1122, :sm2222, :sm2233, :sm3333].each{|n| @db.table_exists?(n).
|
530
|
-
@db[:schema_migrations].select_order_map(:filename).
|
529
|
+
[:sm1111, :sm1122, :sm2222, :sm2233, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
530
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal []
|
531
531
|
end
|
532
532
|
|
533
|
-
|
533
|
+
it "should handle updating to a specific timestamp when interleaving migrations" do
|
534
534
|
@dir = 'spec/files/timestamped_migrations'
|
535
535
|
@m.apply(@db, @dir)
|
536
536
|
@dir = 'spec/files/interleaved_timestamped_migrations'
|
537
537
|
@m.apply(@db, @dir, 1273253851)
|
538
|
-
[:schema_migrations, :sm1111, :sm1122, :sm2222].each{|n| @db.table_exists?(n).
|
539
|
-
[:sm2233, :sm3333].each{|n| @db.table_exists?(n).
|
540
|
-
@db[:schema_migrations].select_order_map(:filename).
|
538
|
+
[:schema_migrations, :sm1111, :sm1122, :sm2222].each{|n| @db.table_exists?(n).must_equal true}
|
539
|
+
[:sm2233, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
540
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253850_create_artists.rb 1273253851_create_nodes.rb'
|
541
541
|
end
|
542
542
|
|
543
|
-
|
543
|
+
it "should correctly update schema_migrations table when an error occurs when migrating up or down" do
|
544
544
|
@dir = 'spec/files/bad_timestamped_migrations'
|
545
|
-
proc{@m.apply(@db, @dir)}.
|
546
|
-
[:schema_migrations, :sm1111, :sm2222].each{|n| @db.table_exists?(n).
|
547
|
-
@db.table_exists?(:sm3333).
|
548
|
-
@db[:schema_migrations].select_order_map(:filename).
|
549
|
-
proc{@m.apply(@db, @dir, 0)}.
|
550
|
-
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
551
|
-
@db.table_exists?(:sm1111).
|
552
|
-
@db[:schema_migrations].select_order_map(:filename).
|
545
|
+
proc{@m.apply(@db, @dir)}.must_raise NoMethodError
|
546
|
+
[:schema_migrations, :sm1111, :sm2222].each{|n| @db.table_exists?(n).must_equal true}
|
547
|
+
@db.table_exists?(:sm3333).must_equal false
|
548
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb'
|
549
|
+
proc{@m.apply(@db, @dir, 0)}.must_raise NoMethodError
|
550
|
+
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
551
|
+
@db.table_exists?(:sm1111).must_equal true
|
552
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb'
|
553
553
|
end
|
554
554
|
|
555
|
-
|
555
|
+
it "should handle multiple migrations with the same timestamp correctly" do
|
556
556
|
@dir = 'spec/files/duplicate_timestamped_migrations'
|
557
557
|
@m.apply(@db, @dir)
|
558
|
-
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
559
|
-
@db[:schema_migrations].select_order_map(:filename).
|
558
|
+
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
559
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253853_create_nodes.rb 1273253853_create_users.rb'
|
560
560
|
@m.apply(@db, @dir, 1273253853)
|
561
|
-
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
562
|
-
@db[:schema_migrations].select_order_map(:filename).
|
561
|
+
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
562
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253853_create_nodes.rb 1273253853_create_users.rb'
|
563
563
|
@m.apply(@db, @dir, 1273253849)
|
564
|
-
[:sm1111].each{|n| @db.table_exists?(n).
|
565
|
-
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
566
|
-
@db[:schema_migrations].select_order_map(:filename).
|
564
|
+
[:sm1111].each{|n| @db.table_exists?(n).must_equal true}
|
565
|
+
[:sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
566
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb'
|
567
567
|
@m.apply(@db, @dir, 1273253848)
|
568
|
-
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
569
|
-
@db[:schema_migrations].select_order_map(:filename).
|
568
|
+
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
569
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal []
|
570
570
|
end
|
571
571
|
|
572
|
-
|
572
|
+
it "should convert schema_info table to schema_migrations table" do
|
573
573
|
@dir = 'spec/files/integer_migrations'
|
574
574
|
@m.apply(@db, @dir)
|
575
|
-
[:schema_info, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
576
|
-
[:schema_migrations, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
575
|
+
[:schema_info, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
576
|
+
[:schema_migrations, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
577
577
|
|
578
578
|
@dir = 'spec/files/convert_to_timestamp_migrations'
|
579
579
|
@m.apply(@db, @dir)
|
580
|
-
[:schema_info, :sm1111, :sm2222, :sm3333, :schema_migrations, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
581
|
-
@db[:schema_migrations].select_order_map(:filename).
|
580
|
+
[:schema_info, :sm1111, :sm2222, :sm3333, :schema_migrations, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal true}
|
581
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'001_create_sessions.rb 002_create_nodes.rb 003_3_create_users.rb 1273253850_create_artists.rb 1273253852_create_albums.rb'
|
582
582
|
|
583
583
|
@m.apply(@db, @dir, 4)
|
584
|
-
[:schema_info, :schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
585
|
-
[:sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
586
|
-
@db[:schema_migrations].select_order_map(:filename).
|
584
|
+
[:schema_info, :schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
585
|
+
[:sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
586
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'001_create_sessions.rb 002_create_nodes.rb 003_3_create_users.rb'
|
587
587
|
|
588
588
|
@m.apply(@db, @dir, 0)
|
589
|
-
[:schema_info, :schema_migrations].each{|n| @db.table_exists?(n).
|
590
|
-
[:sm1111, :sm2222, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
591
|
-
@db[:schema_migrations].select_order_map(:filename).
|
589
|
+
[:schema_info, :schema_migrations].each{|n| @db.table_exists?(n).must_equal true}
|
590
|
+
[:sm1111, :sm2222, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
591
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal []
|
592
592
|
end
|
593
593
|
|
594
|
-
|
594
|
+
it "should handle unapplied migrations when migrating schema_info table to schema_migrations table" do
|
595
595
|
@dir = 'spec/files/integer_migrations'
|
596
596
|
@m.apply(@db, @dir, 2)
|
597
|
-
[:schema_info, :sm1111, :sm2222].each{|n| @db.table_exists?(n).
|
598
|
-
[:schema_migrations, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
597
|
+
[:schema_info, :sm1111, :sm2222].each{|n| @db.table_exists?(n).must_equal true}
|
598
|
+
[:schema_migrations, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
599
599
|
|
600
600
|
@dir = 'spec/files/convert_to_timestamp_migrations'
|
601
601
|
@m.apply(@db, @dir, 1273253850)
|
602
|
-
[:schema_info, :sm1111, :sm2222, :sm3333, :schema_migrations, :sm1122].each{|n| @db.table_exists?(n).
|
603
|
-
[:sm2233].each{|n| @db.table_exists?(n).
|
604
|
-
@db[:schema_migrations].select_order_map(:filename).
|
602
|
+
[:schema_info, :sm1111, :sm2222, :sm3333, :schema_migrations, :sm1122].each{|n| @db.table_exists?(n).must_equal true}
|
603
|
+
[:sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
604
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'001_create_sessions.rb 002_create_nodes.rb 003_3_create_users.rb 1273253850_create_artists.rb'
|
605
605
|
end
|
606
606
|
|
607
|
-
|
607
|
+
it "should handle unapplied migrations when migrating schema_info table to schema_migrations table and target is less than last integer migration version" do
|
608
608
|
@dir = 'spec/files/integer_migrations'
|
609
609
|
@m.apply(@db, @dir, 1)
|
610
|
-
[:schema_info, :sm1111].each{|n| @db.table_exists?(n).
|
611
|
-
[:schema_migrations, :sm2222, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
610
|
+
[:schema_info, :sm1111].each{|n| @db.table_exists?(n).must_equal true}
|
611
|
+
[:schema_migrations, :sm2222, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
612
612
|
|
613
613
|
@dir = 'spec/files/convert_to_timestamp_migrations'
|
614
614
|
@m.apply(@db, @dir, 2)
|
615
|
-
[:schema_info, :sm1111, :sm2222, :schema_migrations].each{|n| @db.table_exists?(n).
|
616
|
-
[:sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
617
|
-
@db[:schema_migrations].select_order_map(:filename).
|
615
|
+
[:schema_info, :sm1111, :sm2222, :schema_migrations].each{|n| @db.table_exists?(n).must_equal true}
|
616
|
+
[:sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal false}
|
617
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'001_create_sessions.rb 002_create_nodes.rb'
|
618
618
|
|
619
619
|
@m.apply(@db, @dir)
|
620
|
-
[:schema_info, :sm1111, :sm2222, :schema_migrations, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).
|
621
|
-
@db[:schema_migrations].select_order_map(:filename).
|
620
|
+
[:schema_info, :sm1111, :sm2222, :schema_migrations, :sm3333, :sm1122, :sm2233].each{|n| @db.table_exists?(n).must_equal true}
|
621
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'001_create_sessions.rb 002_create_nodes.rb 003_3_create_users.rb 1273253850_create_artists.rb 1273253852_create_albums.rb'
|
622
622
|
end
|
623
623
|
|
624
|
-
|
624
|
+
it "should raise error for applied migrations not in file system" do
|
625
625
|
@dir = 'spec/files/timestamped_migrations'
|
626
626
|
@m.apply(@db, @dir)
|
627
|
-
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
628
|
-
@db[:schema_migrations].select_order_map(:filename).
|
627
|
+
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
628
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb 1273253853_3_create_users.rb'
|
629
629
|
|
630
630
|
@dir = 'spec/files/missing_timestamped_migrations'
|
631
|
-
proc{@m.apply(@db, @dir, 0)}.
|
632
|
-
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
633
|
-
@db[:schema_migrations].select_order_map(:filename).
|
631
|
+
proc{@m.apply(@db, @dir, 0)}.must_raise(Sequel::Migrator::Error)
|
632
|
+
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
633
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb 1273253853_3_create_users.rb'
|
634
634
|
end
|
635
635
|
|
636
|
-
|
636
|
+
it "should not raise error for applied migrations not in file system if :allow_missing_migration_files is true" do
|
637
637
|
@dir = 'spec/files/timestamped_migrations'
|
638
638
|
@m.apply(@db, @dir)
|
639
|
-
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
640
|
-
@db[:schema_migrations].select_order_map(:filename).
|
639
|
+
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
640
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb 1273253853_3_create_users.rb'
|
641
641
|
|
642
642
|
@dir = 'spec/files/missing_timestamped_migrations'
|
643
|
-
|
644
|
-
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
645
|
-
@db[:schema_migrations].select_order_map(:filename).
|
643
|
+
@m.run(@db, @dir, :allow_missing_migration_files => true)
|
644
|
+
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
645
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb 1273253853_3_create_users.rb'
|
646
646
|
end
|
647
647
|
|
648
|
-
|
648
|
+
it "should raise error missing column name in existing schema_migrations table" do
|
649
649
|
@dir = 'spec/files/timestamped_migrations'
|
650
650
|
@m.apply(@db, @dir)
|
651
|
-
proc{@m.run(@db, @dir, :column=>:fn)}.
|
651
|
+
proc{@m.run(@db, @dir, :column=>:fn)}.must_raise(Sequel::Migrator::Error)
|
652
652
|
end
|
653
653
|
|
654
|
-
|
654
|
+
it "should handle migration filenames in a case insensitive manner" do
|
655
655
|
@dir = 'spec/files/uppercase_timestamped_migrations'
|
656
656
|
@m.apply(@db, @dir)
|
657
|
-
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
658
|
-
@db[:schema_migrations].select_order_map(:filename).
|
657
|
+
[:schema_migrations, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
658
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb 1273253853_3_create_users.rb'
|
659
659
|
@dir = 'spec/files/timestamped_migrations'
|
660
660
|
@m.apply(@db, @dir, 0)
|
661
|
-
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
662
|
-
@db[:schema_migrations].select_order_map(:filename).
|
661
|
+
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
662
|
+
@db[:schema_migrations].select_order_map(:filename).must_equal []
|
663
663
|
end
|
664
664
|
|
665
|
-
|
665
|
+
it "should :table and :column options" do
|
666
666
|
@dir = 'spec/files/timestamped_migrations'
|
667
667
|
@m.run(@db, @dir, :table=>:sm, :column=>:fn)
|
668
|
-
[:sm, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
669
|
-
@db[:sm].select_order_map(:filename).
|
668
|
+
[:sm, :sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal true}
|
669
|
+
@db[:sm].select_order_map(:filename).must_equal %w'1273253849_create_sessions.rb 1273253851_create_nodes.rb 1273253853_3_create_users.rb'
|
670
670
|
@m.run(@db, @dir, :target=>0, :table=>:sm, :column=>:fn)
|
671
|
-
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).
|
672
|
-
@db[:sm].select_order_map(:fn).
|
671
|
+
[:sm1111, :sm2222, :sm3333].each{|n| @db.table_exists?(n).must_equal false}
|
672
|
+
@db[:sm].select_order_map(:fn).must_equal []
|
673
673
|
end
|
674
674
|
|
675
|
-
|
675
|
+
it "should return nil" do
|
676
676
|
@dir = 'spec/files/timestamped_migrations'
|
677
|
-
@m.apply(@db, @dir, 1273253850).
|
678
|
-
@m.apply(@db, @dir, 0).
|
679
|
-
@m.apply(@db, @dir).
|
677
|
+
@m.apply(@db, @dir, 1273253850).must_equal nil
|
678
|
+
@m.apply(@db, @dir, 0).must_equal nil
|
679
|
+
@m.apply(@db, @dir).must_equal nil
|
680
680
|
end
|
681
681
|
|
682
|
-
|
682
|
+
it "should use TimestampMigrator if TimestampMigrator.apply is called even for integer migrations directory" do
|
683
683
|
Sequel::TimestampMigrator.apply(@db, "spec/files/integer_migrations")
|
684
|
-
@db.sqls.
|
684
|
+
@db.sqls.must_equal ["SELECT NULL AS nil FROM schema_migrations LIMIT 1", "CREATE TABLE schema_migrations (filename varchar(255) PRIMARY KEY)", "SELECT NULL AS nil FROM schema_info LIMIT 1", "SELECT filename FROM schema_migrations ORDER BY filename", "CREATE TABLE sm1111 (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('001_create_sessions.rb')", "CREATE TABLE sm2222 (smc2 integer)", "INSERT INTO schema_migrations (filename) VALUES ('002_create_nodes.rb')", "CREATE TABLE sm3333 (smc3 integer)", "INSERT INTO schema_migrations (filename) VALUES ('003_3_create_users.rb')"]
|
685
685
|
end
|
686
686
|
|
687
|
-
|
687
|
+
it "should not use transactions by default" do
|
688
688
|
Sequel::TimestampMigrator.apply(@db, "spec/files/transaction_unspecified_migrations")
|
689
|
-
@db.sqls.
|
689
|
+
@db.sqls.must_equal ["SELECT NULL AS nil FROM schema_migrations LIMIT 1", "CREATE TABLE schema_migrations (filename varchar(255) PRIMARY KEY)", "SELECT NULL AS nil FROM schema_info LIMIT 1", "SELECT filename FROM schema_migrations ORDER BY filename", "CREATE TABLE sm11111 (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('001_create_alt_basic.rb')", "CREATE TABLE sm (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('002_create_basic.rb')"]
|
690
690
|
end
|
691
691
|
|
692
|
-
|
692
|
+
it "should use transactions by default if database supports transactional ddl" do
|
693
693
|
@db.meta_def(:supports_transactional_ddl?){true}
|
694
694
|
Sequel::TimestampMigrator.apply(@db, "spec/files/transaction_unspecified_migrations")
|
695
|
-
@db.sqls.
|
695
|
+
@db.sqls.must_equal ["SELECT NULL AS nil FROM schema_migrations LIMIT 1", "CREATE TABLE schema_migrations (filename varchar(255) PRIMARY KEY)", "SELECT NULL AS nil FROM schema_info LIMIT 1", "SELECT filename FROM schema_migrations ORDER BY filename", "BEGIN", "CREATE TABLE sm11111 (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('001_create_alt_basic.rb')", "COMMIT", "BEGIN", "CREATE TABLE sm (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('002_create_basic.rb')", "COMMIT"]
|
696
696
|
end
|
697
697
|
|
698
|
-
|
698
|
+
it "should support transaction use on a per migration basis" do
|
699
699
|
Sequel::TimestampMigrator.apply(@db, "spec/files/transaction_specified_migrations")
|
700
|
-
@db.sqls.
|
700
|
+
@db.sqls.must_equal ["SELECT NULL AS nil FROM schema_migrations LIMIT 1", "CREATE TABLE schema_migrations (filename varchar(255) PRIMARY KEY)", "SELECT NULL AS nil FROM schema_info LIMIT 1", "SELECT filename FROM schema_migrations ORDER BY filename", "BEGIN", "CREATE TABLE sm11111 (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('001_create_alt_basic.rb')", "COMMIT", "CREATE TABLE sm (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('002_create_basic.rb')"]
|
701
701
|
end
|
702
702
|
|
703
|
-
|
703
|
+
it "should force transactions if enabled by the migrator" do
|
704
704
|
Sequel::TimestampMigrator.run(@db, "spec/files/transaction_specified_migrations", :use_transactions=>true)
|
705
|
-
@db.sqls.
|
705
|
+
@db.sqls.must_equal ["SELECT NULL AS nil FROM schema_migrations LIMIT 1", "CREATE TABLE schema_migrations (filename varchar(255) PRIMARY KEY)", "SELECT NULL AS nil FROM schema_info LIMIT 1", "SELECT filename FROM schema_migrations ORDER BY filename", "BEGIN", "CREATE TABLE sm11111 (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('001_create_alt_basic.rb')", "COMMIT", "BEGIN", "CREATE TABLE sm (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('002_create_basic.rb')", "COMMIT"]
|
706
706
|
end
|
707
707
|
|
708
|
-
|
708
|
+
it "should not use transactions if disabled in the migrator" do
|
709
709
|
Sequel::TimestampMigrator.run(@db, "spec/files/transaction_unspecified_migrations", :use_transactions=>false)
|
710
|
-
@db.sqls.
|
710
|
+
@db.sqls.must_equal ["SELECT NULL AS nil FROM schema_migrations LIMIT 1", "CREATE TABLE schema_migrations (filename varchar(255) PRIMARY KEY)", "SELECT NULL AS nil FROM schema_info LIMIT 1", "SELECT filename FROM schema_migrations ORDER BY filename", "CREATE TABLE sm11111 (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('001_create_alt_basic.rb')", "CREATE TABLE sm (smc1 integer)", "INSERT INTO schema_migrations (filename) VALUES ('002_create_basic.rb')"]
|
711
711
|
end
|
712
712
|
end
|