sequel 5.29.0 → 5.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -1922
- data/doc/release_notes/5.30.0.txt +20 -0
- data/lib/sequel/adapters/shared/sqlite.rb +7 -1
- data/lib/sequel/database/transactions.rb +5 -9
- data/lib/sequel/version.rb +1 -1
- metadata +4 -368
- data/Rakefile +0 -151
- data/doc/release_notes/4.0.0.txt +0 -262
- data/doc/release_notes/4.1.0.txt +0 -85
- data/doc/release_notes/4.10.0.txt +0 -226
- data/doc/release_notes/4.11.0.txt +0 -147
- data/doc/release_notes/4.12.0.txt +0 -105
- data/doc/release_notes/4.13.0.txt +0 -169
- data/doc/release_notes/4.14.0.txt +0 -68
- data/doc/release_notes/4.15.0.txt +0 -56
- data/doc/release_notes/4.16.0.txt +0 -36
- data/doc/release_notes/4.17.0.txt +0 -38
- data/doc/release_notes/4.18.0.txt +0 -36
- data/doc/release_notes/4.19.0.txt +0 -45
- data/doc/release_notes/4.2.0.txt +0 -129
- data/doc/release_notes/4.20.0.txt +0 -79
- data/doc/release_notes/4.21.0.txt +0 -94
- data/doc/release_notes/4.22.0.txt +0 -72
- data/doc/release_notes/4.23.0.txt +0 -65
- data/doc/release_notes/4.24.0.txt +0 -99
- data/doc/release_notes/4.25.0.txt +0 -181
- data/doc/release_notes/4.26.0.txt +0 -44
- data/doc/release_notes/4.27.0.txt +0 -78
- data/doc/release_notes/4.28.0.txt +0 -57
- data/doc/release_notes/4.29.0.txt +0 -41
- data/doc/release_notes/4.3.0.txt +0 -40
- data/doc/release_notes/4.30.0.txt +0 -37
- data/doc/release_notes/4.31.0.txt +0 -57
- data/doc/release_notes/4.32.0.txt +0 -132
- data/doc/release_notes/4.33.0.txt +0 -88
- data/doc/release_notes/4.34.0.txt +0 -86
- data/doc/release_notes/4.35.0.txt +0 -130
- data/doc/release_notes/4.36.0.txt +0 -116
- data/doc/release_notes/4.37.0.txt +0 -50
- data/doc/release_notes/4.38.0.txt +0 -67
- data/doc/release_notes/4.39.0.txt +0 -127
- data/doc/release_notes/4.4.0.txt +0 -92
- data/doc/release_notes/4.40.0.txt +0 -179
- data/doc/release_notes/4.41.0.txt +0 -77
- data/doc/release_notes/4.42.0.txt +0 -221
- data/doc/release_notes/4.43.0.txt +0 -87
- data/doc/release_notes/4.44.0.txt +0 -125
- data/doc/release_notes/4.45.0.txt +0 -370
- data/doc/release_notes/4.46.0.txt +0 -404
- data/doc/release_notes/4.47.0.txt +0 -56
- data/doc/release_notes/4.48.0.txt +0 -293
- data/doc/release_notes/4.49.0.txt +0 -222
- data/doc/release_notes/4.5.0.txt +0 -34
- data/doc/release_notes/4.6.0.txt +0 -30
- data/doc/release_notes/4.7.0.txt +0 -103
- data/doc/release_notes/4.8.0.txt +0 -175
- data/doc/release_notes/4.9.0.txt +0 -190
- data/spec/adapter_spec.rb +0 -4
- data/spec/adapters/db2_spec.rb +0 -170
- data/spec/adapters/mssql_spec.rb +0 -828
- data/spec/adapters/mysql_spec.rb +0 -1060
- data/spec/adapters/oracle_spec.rb +0 -371
- data/spec/adapters/postgres_spec.rb +0 -4476
- data/spec/adapters/spec_helper.rb +0 -44
- data/spec/adapters/sqlanywhere_spec.rb +0 -97
- data/spec/adapters/sqlite_spec.rb +0 -652
- data/spec/bin_spec.rb +0 -278
- data/spec/core/connection_pool_spec.rb +0 -1250
- data/spec/core/database_spec.rb +0 -2915
- data/spec/core/dataset_spec.rb +0 -5544
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1498
- data/spec/core/mock_adapter_spec.rb +0 -722
- data/spec/core/object_graph_spec.rb +0 -336
- data/spec/core/placeholder_literalizer_spec.rb +0 -166
- data/spec/core/schema_generator_spec.rb +0 -214
- data/spec/core/schema_spec.rb +0 -1844
- data/spec/core/spec_helper.rb +0 -24
- data/spec/core/version_spec.rb +0 -14
- data/spec/core_extensions_spec.rb +0 -763
- data/spec/core_model_spec.rb +0 -2
- data/spec/core_spec.rb +0 -1
- data/spec/deprecation_helper.rb +0 -30
- data/spec/extensions/accessed_columns_spec.rb +0 -51
- data/spec/extensions/active_model_spec.rb +0 -99
- data/spec/extensions/after_initialize_spec.rb +0 -28
- data/spec/extensions/any_not_empty_spec.rb +0 -23
- data/spec/extensions/arbitrary_servers_spec.rb +0 -109
- data/spec/extensions/association_dependencies_spec.rb +0 -125
- data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
- data/spec/extensions/association_pks_spec.rb +0 -423
- data/spec/extensions/association_proxies_spec.rb +0 -100
- data/spec/extensions/auto_literal_strings_spec.rb +0 -205
- data/spec/extensions/auto_validations_spec.rb +0 -229
- data/spec/extensions/blacklist_security_spec.rb +0 -95
- data/spec/extensions/blank_spec.rb +0 -69
- data/spec/extensions/boolean_readers_spec.rb +0 -93
- data/spec/extensions/boolean_subsets_spec.rb +0 -47
- data/spec/extensions/caching_spec.rb +0 -273
- data/spec/extensions/caller_logging_spec.rb +0 -52
- data/spec/extensions/class_table_inheritance_spec.rb +0 -750
- data/spec/extensions/column_conflicts_spec.rb +0 -75
- data/spec/extensions/column_select_spec.rb +0 -129
- data/spec/extensions/columns_introspection_spec.rb +0 -90
- data/spec/extensions/columns_updated_spec.rb +0 -35
- data/spec/extensions/composition_spec.rb +0 -248
- data/spec/extensions/connection_expiration_spec.rb +0 -151
- data/spec/extensions/connection_validator_spec.rb +0 -144
- data/spec/extensions/constant_sql_override_spec.rb +0 -24
- data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
- data/spec/extensions/constraint_validations_spec.rb +0 -439
- data/spec/extensions/core_refinements_spec.rb +0 -528
- data/spec/extensions/csv_serializer_spec.rb +0 -183
- data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
- data/spec/extensions/dataset_associations_spec.rb +0 -365
- data/spec/extensions/dataset_source_alias_spec.rb +0 -51
- data/spec/extensions/date_arithmetic_spec.rb +0 -181
- data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
- data/spec/extensions/def_dataset_method_spec.rb +0 -100
- data/spec/extensions/defaults_setter_spec.rb +0 -150
- data/spec/extensions/delay_add_association_spec.rb +0 -73
- data/spec/extensions/dirty_spec.rb +0 -222
- data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
- data/spec/extensions/eager_each_spec.rb +0 -62
- data/spec/extensions/eager_graph_eager_spec.rb +0 -100
- data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
- data/spec/extensions/empty_failure_backtraces_spec.rb +0 -60
- data/spec/extensions/error_splitter_spec.rb +0 -18
- data/spec/extensions/error_sql_spec.rb +0 -20
- data/spec/extensions/escaped_like_spec.rb +0 -40
- data/spec/extensions/eval_inspect_spec.rb +0 -81
- data/spec/extensions/exclude_or_null_spec.rb +0 -15
- data/spec/extensions/finder_spec.rb +0 -260
- data/spec/extensions/force_encoding_spec.rb +0 -126
- data/spec/extensions/freeze_datasets_spec.rb +0 -31
- data/spec/extensions/graph_each_spec.rb +0 -113
- data/spec/extensions/hook_class_methods_spec.rb +0 -402
- data/spec/extensions/identifier_mangling_spec.rb +0 -201
- data/spec/extensions/implicit_subquery_spec.rb +0 -58
- data/spec/extensions/index_caching_spec.rb +0 -66
- data/spec/extensions/inflector_spec.rb +0 -183
- data/spec/extensions/input_transformer_spec.rb +0 -69
- data/spec/extensions/insert_conflict_spec.rb +0 -103
- data/spec/extensions/insert_returning_select_spec.rb +0 -72
- data/spec/extensions/instance_filters_spec.rb +0 -79
- data/spec/extensions/instance_hooks_spec.rb +0 -246
- data/spec/extensions/integer64_spec.rb +0 -22
- data/spec/extensions/inverted_subsets_spec.rb +0 -33
- data/spec/extensions/json_serializer_spec.rb +0 -346
- data/spec/extensions/lazy_attributes_spec.rb +0 -183
- data/spec/extensions/list_spec.rb +0 -291
- data/spec/extensions/looser_typecasting_spec.rb +0 -43
- data/spec/extensions/many_through_many_spec.rb +0 -2177
- data/spec/extensions/migration_spec.rb +0 -864
- data/spec/extensions/modification_detection_spec.rb +0 -93
- data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
- data/spec/extensions/named_timezones_spec.rb +0 -218
- data/spec/extensions/nested_attributes_spec.rb +0 -815
- data/spec/extensions/null_dataset_spec.rb +0 -85
- data/spec/extensions/optimistic_locking_spec.rb +0 -127
- data/spec/extensions/pagination_spec.rb +0 -116
- data/spec/extensions/pg_array_associations_spec.rb +0 -802
- data/spec/extensions/pg_array_ops_spec.rb +0 -144
- data/spec/extensions/pg_array_spec.rb +0 -398
- data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -209
- data/spec/extensions/pg_enum_spec.rb +0 -118
- data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
- data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
- data/spec/extensions/pg_hstore_spec.rb +0 -219
- data/spec/extensions/pg_inet_ops_spec.rb +0 -102
- data/spec/extensions/pg_inet_spec.rb +0 -72
- data/spec/extensions/pg_interval_spec.rb +0 -103
- data/spec/extensions/pg_json_ops_spec.rb +0 -356
- data/spec/extensions/pg_json_spec.rb +0 -451
- data/spec/extensions/pg_loose_count_spec.rb +0 -23
- data/spec/extensions/pg_range_ops_spec.rb +0 -60
- data/spec/extensions/pg_range_spec.rb +0 -600
- data/spec/extensions/pg_row_ops_spec.rb +0 -61
- data/spec/extensions/pg_row_plugin_spec.rb +0 -60
- data/spec/extensions/pg_row_spec.rb +0 -363
- data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
- data/spec/extensions/pg_timestamptz_spec.rb +0 -17
- data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
- data/spec/extensions/prepared_statements_spec.rb +0 -177
- data/spec/extensions/pretty_table_spec.rb +0 -123
- data/spec/extensions/query_spec.rb +0 -94
- data/spec/extensions/rcte_tree_spec.rb +0 -387
- data/spec/extensions/round_timestamps_spec.rb +0 -39
- data/spec/extensions/s_spec.rb +0 -60
- data/spec/extensions/schema_caching_spec.rb +0 -64
- data/spec/extensions/schema_dumper_spec.rb +0 -870
- data/spec/extensions/select_remove_spec.rb +0 -38
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
- data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
- data/spec/extensions/serialization_spec.rb +0 -365
- data/spec/extensions/server_block_spec.rb +0 -135
- data/spec/extensions/server_logging_spec.rb +0 -45
- data/spec/extensions/sharding_spec.rb +0 -197
- data/spec/extensions/shared_caching_spec.rb +0 -151
- data/spec/extensions/single_table_inheritance_spec.rb +0 -347
- data/spec/extensions/singular_table_names_spec.rb +0 -22
- data/spec/extensions/skip_create_refresh_spec.rb +0 -18
- data/spec/extensions/spec_helper.rb +0 -70
- data/spec/extensions/split_array_nil_spec.rb +0 -24
- data/spec/extensions/split_values_spec.rb +0 -57
- data/spec/extensions/sql_comments_spec.rb +0 -33
- data/spec/extensions/sql_expr_spec.rb +0 -59
- data/spec/extensions/static_cache_cache_spec.rb +0 -35
- data/spec/extensions/static_cache_spec.rb +0 -471
- data/spec/extensions/string_agg_spec.rb +0 -90
- data/spec/extensions/string_date_time_spec.rb +0 -95
- data/spec/extensions/string_stripper_spec.rb +0 -68
- data/spec/extensions/subclasses_spec.rb +0 -79
- data/spec/extensions/subset_conditions_spec.rb +0 -38
- data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
- data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
- data/spec/extensions/synchronize_sql_spec.rb +0 -124
- data/spec/extensions/table_select_spec.rb +0 -83
- data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
- data/spec/extensions/thread_local_timezones_spec.rb +0 -67
- data/spec/extensions/throw_failures_spec.rb +0 -74
- data/spec/extensions/timestamps_spec.rb +0 -209
- data/spec/extensions/to_dot_spec.rb +0 -153
- data/spec/extensions/touch_spec.rb +0 -226
- data/spec/extensions/tree_spec.rb +0 -334
- data/spec/extensions/typecast_on_load_spec.rb +0 -86
- data/spec/extensions/unlimited_update_spec.rb +0 -21
- data/spec/extensions/update_or_create_spec.rb +0 -83
- data/spec/extensions/update_primary_key_spec.rb +0 -105
- data/spec/extensions/update_refresh_spec.rb +0 -59
- data/spec/extensions/uuid_spec.rb +0 -101
- data/spec/extensions/validate_associated_spec.rb +0 -52
- data/spec/extensions/validation_class_methods_spec.rb +0 -1040
- data/spec/extensions/validation_contexts_spec.rb +0 -31
- data/spec/extensions/validation_helpers_spec.rb +0 -525
- data/spec/extensions/whitelist_security_spec.rb +0 -157
- data/spec/extensions/xml_serializer_spec.rb +0 -213
- data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
- data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
- data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
- data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
- data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/double_migration/001_create_sessions.rb +0 -9
- data/spec/files/double_migration/002_create_nodes.rb +0 -19
- data/spec/files/double_migration/003_3_create_users.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
- data/spec/files/empty_migration/001_create_sessions.rb +0 -9
- data/spec/files/empty_migration/002_create_nodes.rb +0 -0
- data/spec/files/empty_migration/003_3_create_users.rb +0 -4
- data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
- data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
- data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
- data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
- data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/reversible_migrations/001_reversible.rb +0 -5
- data/spec/files/reversible_migrations/002_reversible.rb +0 -5
- data/spec/files/reversible_migrations/003_reversible.rb +0 -5
- data/spec/files/reversible_migrations/004_reversible.rb +0 -5
- data/spec/files/reversible_migrations/005_reversible.rb +0 -10
- data/spec/files/reversible_migrations/006_reversible.rb +0 -10
- data/spec/files/reversible_migrations/007_reversible.rb +0 -10
- data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
- data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
- data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
- data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
- data/spec/guards_helper.rb +0 -59
- data/spec/integration/associations_test.rb +0 -2597
- data/spec/integration/database_test.rb +0 -113
- data/spec/integration/dataset_test.rb +0 -2037
- data/spec/integration/eager_loader_test.rb +0 -687
- data/spec/integration/migrator_test.rb +0 -262
- data/spec/integration/model_test.rb +0 -203
- data/spec/integration/plugin_test.rb +0 -2423
- data/spec/integration/prepared_statement_test.rb +0 -405
- data/spec/integration/schema_test.rb +0 -903
- data/spec/integration/spec_helper.rb +0 -71
- data/spec/integration/timezone_test.rb +0 -86
- data/spec/integration/transaction_test.rb +0 -603
- data/spec/integration/type_test.rb +0 -127
- data/spec/model/association_reflection_spec.rb +0 -803
- data/spec/model/associations_spec.rb +0 -4738
- data/spec/model/base_spec.rb +0 -875
- data/spec/model/class_dataset_methods_spec.rb +0 -146
- data/spec/model/dataset_methods_spec.rb +0 -198
- data/spec/model/eager_loading_spec.rb +0 -2377
- data/spec/model/hooks_spec.rb +0 -370
- data/spec/model/inflector_spec.rb +0 -26
- data/spec/model/model_spec.rb +0 -956
- data/spec/model/plugins_spec.rb +0 -429
- data/spec/model/record_spec.rb +0 -2118
- data/spec/model/spec_helper.rb +0 -46
- data/spec/model/validations_spec.rb +0 -220
- data/spec/model_no_assoc_spec.rb +0 -1
- data/spec/model_spec.rb +0 -1
- data/spec/plugin_spec.rb +0 -1
- data/spec/sequel_coverage.rb +0 -15
- data/spec/sequel_warning.rb +0 -5
- data/spec/spec_config.rb +0 -12
@@ -1,39 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "Sequel::Dataset::RoundTimestamps" do
|
4
|
-
before do
|
5
|
-
@dataset = Sequel.mock.dataset.extension(:round_timestamps)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should round times properly for databases supporting microsecond precision" do
|
9
|
-
@dataset.literal(Sequel::SQLTime.create(1, 2, 3, 499999.5)).must_equal "'01:02:03.500000'"
|
10
|
-
@dataset.literal(Time.local(2010, 1, 2, 3, 4, 5.4999995)).must_equal "'2010-01-02 03:04:05.500000'"
|
11
|
-
@dataset.literal(DateTime.new(2010, 1, 2, 3, 4, Rational(54999995, 10000000))).must_equal "'2010-01-02 03:04:05.500000'"
|
12
|
-
|
13
|
-
@dataset.literal(Sequel::SQLTime.create(1, 2, 3, 499999.4)).must_equal "'01:02:03.499999'"
|
14
|
-
@dataset.literal(Time.local(2010, 1, 2, 3, 4, 5.4999994)).must_equal "'2010-01-02 03:04:05.499999'"
|
15
|
-
@dataset.literal(DateTime.new(2010, 1, 2, 3, 4, Rational(54999994, 10000000))).must_equal "'2010-01-02 03:04:05.499999'"
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should round times properly for databases supporting millisecond precision" do
|
19
|
-
@dataset = @dataset.with_extend{def timestamp_precision; 3 end}
|
20
|
-
@dataset.literal(Sequel::SQLTime.create(1, 2, 3, 499500)).must_equal "'01:02:03.500'"
|
21
|
-
@dataset.literal(Time.local(2010, 1, 2, 3, 4, 5.4995)).must_equal "'2010-01-02 03:04:05.500'"
|
22
|
-
@dataset.literal(DateTime.new(2010, 1, 2, 3, 4, Rational(54995, 10000))).must_equal "'2010-01-02 03:04:05.500'"
|
23
|
-
|
24
|
-
@dataset.literal(Sequel::SQLTime.create(1, 2, 3, 499499)).must_equal "'01:02:03.499'"
|
25
|
-
@dataset.literal(Time.local(2010, 1, 2, 3, 4, 5.4994)).must_equal "'2010-01-02 03:04:05.499'"
|
26
|
-
@dataset.literal(DateTime.new(2010, 1, 2, 3, 4, Rational(54994, 10000))).must_equal "'2010-01-02 03:04:05.499'"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should round times properly for databases supporting second precision" do
|
30
|
-
@dataset = @dataset.with_extend{def supports_timestamp_usecs?; false end}
|
31
|
-
@dataset.literal(Sequel::SQLTime.create(1, 2, 3, 500000)).must_equal "'01:02:04'"
|
32
|
-
@dataset.literal(Time.local(2010, 1, 2, 3, 4, 5.5)).must_equal "'2010-01-02 03:04:06'"
|
33
|
-
@dataset.literal(DateTime.new(2010, 1, 2, 3, 4, Rational(55, 10))).must_equal "'2010-01-02 03:04:06'"
|
34
|
-
|
35
|
-
@dataset.literal(Sequel::SQLTime.create(1, 2, 3, 499999)).must_equal "'01:02:03'"
|
36
|
-
@dataset.literal(Time.local(2010, 1, 2, 3, 4, 5.4999999)).must_equal "'2010-01-02 03:04:05'"
|
37
|
-
@dataset.literal(DateTime.new(2010, 1, 2, 3, 4, Rational(54999999, 10000000))).must_equal "'2010-01-02 03:04:05'"
|
38
|
-
end
|
39
|
-
end
|
data/spec/extensions/s_spec.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
Sequel.extension :s
|
4
|
-
|
5
|
-
describe "s extension as refinement" do
|
6
|
-
include Sequel::S
|
7
|
-
|
8
|
-
before do
|
9
|
-
@db = Sequel.mock
|
10
|
-
end
|
11
|
-
|
12
|
-
it "S should be callable with different arguments" do
|
13
|
-
@db.literal(S(:s) + 1).must_equal "(s + 1)"
|
14
|
-
@db.literal(S('s') + '1').must_equal "('s' || '1')"
|
15
|
-
@db.literal(~S([[:s, 1], [:z, 2]])).must_equal "((s != 1) OR (z != 2))"
|
16
|
-
end
|
17
|
-
|
18
|
-
it "S should be callable with blocks" do
|
19
|
-
@db.literal(S{x + 1}).must_equal "(x + 1)"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "S should raise an error if called with multiple objects" do
|
23
|
-
proc{S(:x, 1)}.must_raise ArgumentError
|
24
|
-
end
|
25
|
-
|
26
|
-
it "S should raise an error if called with objects and block" do
|
27
|
-
proc{S(:x){}}.must_raise Sequel::Error
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
if (RUBY_VERSION >= '2.0.0' && RUBY_ENGINE == 'ruby') || (RUBY_ENGINE == 'jruby' && (JRUBY_VERSION >= '9.3' || (JRUBY_VERSION.match(/\A9\.2\.(\d+)/) && $1.to_i >= 7)))
|
33
|
-
using Sequel::S
|
34
|
-
|
35
|
-
describe "s extension as refinement" do
|
36
|
-
before do
|
37
|
-
@db = Sequel.mock
|
38
|
-
end
|
39
|
-
|
40
|
-
it "S should be callable with different arguments" do
|
41
|
-
@db.literal(S(:s) + 1).must_equal "(s + 1)"
|
42
|
-
@db.literal(S('s') + '1').must_equal "('s' || '1')"
|
43
|
-
@db.literal(~S([[:s, 1], [:z, 2]])).must_equal "((s != 1) OR (z != 2))"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "S should be callable with blocks" do
|
47
|
-
@db.literal(S{x + 1}).must_equal "(x + 1)"
|
48
|
-
end
|
49
|
-
|
50
|
-
it "S should raise an error if called with multiple objects" do
|
51
|
-
proc{S(:x, 1)}.must_raise ArgumentError
|
52
|
-
end
|
53
|
-
|
54
|
-
it "S should raise an error if called with objects and block" do
|
55
|
-
proc{S(:x){}}.must_raise Sequel::Error
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "schema_caching extension" do
|
4
|
-
before do
|
5
|
-
@db = Sequel.mock.extension(:schema_caching)
|
6
|
-
@schemas = {'"table"'=>[[:column, {:db_type=>"integer", :default=>"nextval('table_id_seq'::regclass)", :allow_null=>false, :primary_key=>true, :type=>:integer, :ruby_default=>nil}]]}
|
7
|
-
@filename = "spec/files/test_schema_#$$.dump"
|
8
|
-
@db.instance_variable_set(:@schemas, @schemas)
|
9
|
-
end
|
10
|
-
after do
|
11
|
-
File.delete(@filename) if File.exist?(@filename)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "Database#dump_schema_cache should dump cached schema to the given file" do
|
15
|
-
File.exist?(@filename).must_equal false
|
16
|
-
@db.dump_schema_cache(@filename)
|
17
|
-
File.exist?(@filename).must_equal true
|
18
|
-
File.size(@filename).must_be :>, 0
|
19
|
-
end
|
20
|
-
|
21
|
-
it "Database#dump_schema_cache/load_schema_cache should work with :callable_default values set in schema_post_process" do
|
22
|
-
@schemas['"table"'][0][1][:callable_default] = lambda{1}
|
23
|
-
@schemas['"table"'][0][1][:default] = 'call_1'
|
24
|
-
@db.dump_schema_cache(@filename)
|
25
|
-
db = Sequel.mock(:host=>'postgres').extension(:schema_caching)
|
26
|
-
def db.schema_post_process(_)
|
27
|
-
super.each{|_, c| c[:callable_default] = lambda{1} if c[:default] == 'call_1'}
|
28
|
-
end
|
29
|
-
db.load_schema_cache(@filename)
|
30
|
-
db.schema(:table)[0][1][:callable_default].call.must_equal 1
|
31
|
-
end
|
32
|
-
|
33
|
-
it "Database#load_schema_cache should load cached schema from the given file dumped by #dump_schema_cache" do
|
34
|
-
@db.dump_schema_cache(@filename)
|
35
|
-
db = Sequel::Database.new.extension(:schema_caching)
|
36
|
-
db.load_schema_cache(@filename)
|
37
|
-
@db.instance_variable_get(:@schemas).must_equal @schemas
|
38
|
-
end
|
39
|
-
|
40
|
-
it "Database#load_schema_cache should have frozen string values in the schema caches" do
|
41
|
-
@db.dump_schema_cache(@filename)
|
42
|
-
db = Sequel.mock(:host=>'postgres').extension(:schema_caching)
|
43
|
-
db.load_schema_cache(@filename)
|
44
|
-
h = db.schema(:table)[0][1]
|
45
|
-
h[:db_type].must_equal 'integer'
|
46
|
-
h[:db_type].frozen?.must_equal true
|
47
|
-
h[:default].must_equal "nextval('table_id_seq'::regclass)"
|
48
|
-
h[:default].frozen?.must_equal true
|
49
|
-
end
|
50
|
-
|
51
|
-
it "Database#dump_schema_cache? should dump cached schema to the given file unless the file exists" do
|
52
|
-
File.open(@filename, 'wb'){|f|}
|
53
|
-
File.size(@filename).must_equal 0
|
54
|
-
@db.dump_schema_cache?(@filename)
|
55
|
-
File.size(@filename).must_equal 0
|
56
|
-
end
|
57
|
-
|
58
|
-
it "Database#load_schema_cache? should load cached schema from the given file if it exists" do
|
59
|
-
db = Sequel::Database.new.extension(:schema_caching)
|
60
|
-
File.exist?(@filename).must_equal false
|
61
|
-
db.load_schema_cache?(@filename)
|
62
|
-
db.instance_variable_get(:@schemas).must_equal({})
|
63
|
-
end
|
64
|
-
end
|
@@ -1,870 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "Sequel::Schema::CreateTableGenerator dump methods" do
|
4
|
-
before do
|
5
|
-
@d = Sequel::Database.new.extension(:schema_dumper)
|
6
|
-
@g = Sequel::Schema::CreateTableGenerator
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should allow the same table information to be converted to a string for evaling inside of another instance with the same result" do
|
10
|
-
g = @g.new(@d) do
|
11
|
-
Integer :a
|
12
|
-
varchar :b
|
13
|
-
column :dt, DateTime
|
14
|
-
column :vc, :varchar
|
15
|
-
primary_key :c
|
16
|
-
foreign_key :d, :a
|
17
|
-
foreign_key :e
|
18
|
-
foreign_key [:d, :e], :name=>:cfk
|
19
|
-
constraint :blah, "a=1"
|
20
|
-
check :a=>1
|
21
|
-
unique [:e]
|
22
|
-
index :a
|
23
|
-
index [:c, :e]
|
24
|
-
index [:b, :c], :type=>:hash
|
25
|
-
index [:d], :unique=>true
|
26
|
-
spatial_index :a
|
27
|
-
full_text_index [:b, :c]
|
28
|
-
end
|
29
|
-
g2 = @g.new(@d) do
|
30
|
-
instance_eval(g.dump_columns, __FILE__, __LINE__)
|
31
|
-
instance_eval(g.dump_constraints, __FILE__, __LINE__)
|
32
|
-
instance_eval(g.dump_indexes, __FILE__, __LINE__)
|
33
|
-
end
|
34
|
-
g.columns.must_equal g2.columns
|
35
|
-
g.constraints.must_equal g2.constraints
|
36
|
-
g.indexes.must_equal g2.indexes
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should respect :keep_order option to primary_key" do
|
40
|
-
g = @g.new(@d) do
|
41
|
-
Integer :a
|
42
|
-
primary_key :c, :keep_order=>true
|
43
|
-
end
|
44
|
-
g2 = @g.new(@d) do
|
45
|
-
instance_eval(g.dump_columns, __FILE__, __LINE__)
|
46
|
-
end
|
47
|
-
g.columns.must_equal g2.columns
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should allow dumping indexes as separate add_index and drop_index methods" do
|
51
|
-
g = @g.new(@d) do
|
52
|
-
index :a
|
53
|
-
index [:c, :e], :name=>:blah
|
54
|
-
index [:b, :c], :unique=>true
|
55
|
-
end
|
56
|
-
|
57
|
-
g.dump_indexes(:add_index=>:t).must_equal((<<END_CODE).strip)
|
58
|
-
add_index :t, [:a]
|
59
|
-
add_index :t, [:c, :e], :name=>:blah
|
60
|
-
add_index :t, [:b, :c], :unique=>true
|
61
|
-
END_CODE
|
62
|
-
|
63
|
-
g.dump_indexes(:drop_index=>:t).must_equal((<<END_CODE).strip)
|
64
|
-
drop_index :t, [:b, :c], :unique=>true
|
65
|
-
drop_index :t, [:c, :e], :name=>:blah
|
66
|
-
drop_index :t, [:a]
|
67
|
-
END_CODE
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should raise an error if you try to dump a Generator that uses a constraint with a proc" do
|
71
|
-
proc{@g.new(@d){check{a>1}}.dump_constraints}.must_raise(Sequel::Error)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "Sequel::Database dump methods" do
|
76
|
-
before do
|
77
|
-
@d = Sequel::Database.new.extension(:schema_dumper)
|
78
|
-
def @d.tables(o) o[:schema] ? [o[:schema]] : [:t1, :t2] end
|
79
|
-
def @d.schema(t, *o)
|
80
|
-
v = case t
|
81
|
-
when :t1, 't__t1', Sequel.identifier(:t__t1)
|
82
|
-
[[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true, :allow_null=>false}],
|
83
|
-
[:c2, {:db_type=>'varchar(20)', :allow_null=>true}]]
|
84
|
-
when :t2
|
85
|
-
[[:c1, {:db_type=>'integer', :primary_key=>true, :allow_null=>false}],
|
86
|
-
[:c2, {:db_type=>'numeric', :primary_key=>true, :allow_null=>false}]]
|
87
|
-
when :t3
|
88
|
-
[[:c2, {:db_type=>'varchar(20)', :allow_null=>true}],
|
89
|
-
[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true, :allow_null=>false}]]
|
90
|
-
when :t5
|
91
|
-
[[:c1, {:db_type=>'blahblah', :allow_null=>true}]]
|
92
|
-
end
|
93
|
-
|
94
|
-
if o.first.is_a?(Hash) && o.first[:schema]
|
95
|
-
v.last.last[:db_type] = o.first[:schema]
|
96
|
-
end
|
97
|
-
|
98
|
-
v
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should support dumping table with :schema option" do
|
103
|
-
@d.dump_table_schema(:t1, :schema=>'varchar(15)').must_equal "create_table(:t1) do\n primary_key :c1\n String :c2, :size=>15\nend"
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should support dumping table schemas as create_table method calls" do
|
107
|
-
@d.dump_table_schema(:t1).must_equal "create_table(:t1) do\n primary_key :c1\n String :c2, :size=>20\nend"
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should support dumping table schemas when given a string" do
|
111
|
-
@d.dump_table_schema('t__t1').must_equal "create_table(\"t__t1\") do\n primary_key :c1\n String :c2, :size=>20\nend"
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should support dumping table schemas when given an identifier" do
|
115
|
-
@d.dump_table_schema(Sequel.identifier(:t__t1)).must_equal "create_table(Sequel::SQL::Identifier.new(:t__t1)) do\n primary_key :c1\n String :c2, :size=>20\nend"
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should dump non-Integer primary key columns with explicit :type" do
|
119
|
-
def @d.schema(*s) [[:c1, {:db_type=>'bigint', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]] end
|
120
|
-
@d.dump_table_schema(:t6).must_equal "create_table(:t6) do\n primary_key :c1, :type=>:Bignum\nend"
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should dump non-Integer primary key columns with explicit :type when using :same_db=>true" do
|
124
|
-
def @d.schema(*s) [[:c1, {:db_type=>'bigint', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]] end
|
125
|
-
@d.dump_table_schema(:t6, :same_db=>true).must_equal "create_table(:t6) do\n primary_key :c1, :type=>:Bignum\nend"
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should dump auto incrementing primary keys with :keep_order option if they are not first" do
|
129
|
-
@d.dump_table_schema(:t3).must_equal "create_table(:t3) do\n String :c2, :size=>20\n primary_key :c1, :keep_order=>true\nend"
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should handle foreign keys" do
|
133
|
-
def @d.schema(*s) [[:c1, {:db_type=>'integer', :allow_null=>true}]] end
|
134
|
-
def @d.supports_foreign_key_parsing?; true end
|
135
|
-
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2]}] end
|
136
|
-
@d.dump_table_schema(:t6).must_equal "create_table(:t6) do\n foreign_key :c1, :t2, :key=>[:c2]\nend"
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should handle primary keys that are also foreign keys" do
|
140
|
-
def @d.schema(*s) [[:c1, {:db_type=>'integer', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]] end
|
141
|
-
def @d.supports_foreign_key_parsing?; true end
|
142
|
-
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2]}] end
|
143
|
-
@d.dump_table_schema(:t6).must_equal((<<OUTPUT).chomp)
|
144
|
-
create_table(:t6) do
|
145
|
-
primary_key :c1, :table=>:t2, :key=>[:c2]
|
146
|
-
end
|
147
|
-
OUTPUT
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should handle foreign key options" do
|
151
|
-
def @d.schema(*s) [[:c1, {:db_type=>'integer', :allow_null=>true}]] end
|
152
|
-
def @d.supports_foreign_key_parsing?; true end
|
153
|
-
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2], :on_delete=>:restrict, :on_update=>:set_null, :deferrable=>true}] end
|
154
|
-
@d.dump_table_schema(:t6).must_equal((<<OUTPUT).chomp)
|
155
|
-
create_table(:t6) do
|
156
|
-
foreign_key :c1, :t2, :key=>[:c2], :on_delete=>:restrict, :on_update=>:set_null, :deferrable=>true
|
157
|
-
end
|
158
|
-
OUTPUT
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should handle foreign key options in the primary key" do
|
162
|
-
def @d.schema(*s) [[:c1, {:db_type=>'integer', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]] end
|
163
|
-
def @d.supports_foreign_key_parsing?; true end
|
164
|
-
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2], :on_delete=>:restrict, :on_update=>:set_null, :deferrable=>true}] end
|
165
|
-
@d.dump_table_schema(:t6).must_equal((<<OUTPUT).chomp)
|
166
|
-
create_table(:t6) do
|
167
|
-
primary_key :c1, :table=>:t2, :key=>[:c2], :on_delete=>:restrict, :on_update=>:set_null, :deferrable=>true
|
168
|
-
end
|
169
|
-
OUTPUT
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should omit foreign key options that are the same as defaults" do
|
173
|
-
def @d.schema(*s) [[:c1, {:db_type=>'integer', :allow_null=>true}]] end
|
174
|
-
def @d.supports_foreign_key_parsing?; true end
|
175
|
-
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2], :on_delete=>:no_action, :on_update=>:no_action, :deferrable=>false}] end
|
176
|
-
@d.dump_table_schema(:t6).must_equal((<<OUTPUT).chomp)
|
177
|
-
create_table(:t6) do
|
178
|
-
foreign_key :c1, :t2, :key=>[:c2]
|
179
|
-
end
|
180
|
-
OUTPUT
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should omit foreign key options that are the same as defaults in the primary key" do
|
184
|
-
def @d.schema(*s) [[:c1, {:db_type=>'integer', :primary_key=>true, :allow_null=>true, :auto_increment=>true}]] end
|
185
|
-
def @d.supports_foreign_key_parsing?; true end
|
186
|
-
def @d.foreign_key_list(*s) [{:columns=>[:c1], :table=>:t2, :key=>[:c2], :on_delete=>:no_action, :on_update=>:no_action, :deferrable=>false}] end
|
187
|
-
@d.dump_table_schema(:t6).must_equal((<<OUTPUT).chomp)
|
188
|
-
create_table(:t6) do
|
189
|
-
primary_key :c1, :table=>:t2, :key=>[:c2]
|
190
|
-
end
|
191
|
-
OUTPUT
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should dump primary key columns with explicit type equal to the database type when :same_db option is passed" do
|
195
|
-
def @d.schema(*s) [[:c1, {:db_type=>'somedbspecifictype', :primary_key=>true, :allow_null=>false}]] end
|
196
|
-
@d.dump_table_schema(:t7, :same_db => true).must_equal "create_table(:t7) do\n column :c1, \"somedbspecifictype\", :null=>false\n \n primary_key [:c1]\nend"
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should use a composite primary_key calls if there is a composite primary key" do
|
200
|
-
@d.dump_table_schema(:t2).must_equal "create_table(:t2) do\n Integer :c1, :null=>false\n BigDecimal :c2, :null=>false\n \n primary_key [:c1, :c2]\nend"
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should use a composite foreign_key calls if there is a composite foreign key" do
|
204
|
-
def @d.schema(*s) [[:c1, {:db_type=>'integer'}], [:c2, {:db_type=>'integer'}]] end
|
205
|
-
def @d.supports_foreign_key_parsing?; true end
|
206
|
-
def @d.foreign_key_list(*s) [{:columns=>[:c1, :c2], :table=>:t2, :key=>[:c3, :c4]}] end
|
207
|
-
@d.dump_table_schema(:t1).must_equal "create_table(:t1) do\n Integer :c1\n Integer :c2\n \n foreign_key [:c1, :c2], :t2, :key=>[:c3, :c4]\nend"
|
208
|
-
end
|
209
|
-
|
210
|
-
it "should include index information if available" do
|
211
|
-
def @d.supports_index_parsing?; true end
|
212
|
-
def @d.indexes(t)
|
213
|
-
{:i1=>{:columns=>[:c1], :unique=>false},
|
214
|
-
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
|
215
|
-
end
|
216
|
-
@d.dump_table_schema(:t1).must_equal "create_table(:t1, :ignore_index_errors=>true) do\n primary_key :c1\n String :c2, :size=>20\n \n index [:c1], :name=>:i1\n index [:c2, :c1], :unique=>true\nend"
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should support dumping the whole database as a migration with a :schema option" do
|
220
|
-
@d.dump_schema_migration(:schema=>'t__t1').must_equal <<-END_MIG
|
221
|
-
Sequel.migration do
|
222
|
-
change do
|
223
|
-
create_table("t__t1") do
|
224
|
-
primary_key :c1
|
225
|
-
String :c2
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
END_MIG
|
230
|
-
end
|
231
|
-
|
232
|
-
it "should support dumping the whole database as a migration" do
|
233
|
-
@d.dump_schema_migration.must_equal <<-END_MIG
|
234
|
-
Sequel.migration do
|
235
|
-
change do
|
236
|
-
create_table(:t1) do
|
237
|
-
primary_key :c1
|
238
|
-
String :c2, :size=>20
|
239
|
-
end
|
240
|
-
|
241
|
-
create_table(:t2) do
|
242
|
-
Integer :c1, :null=>false
|
243
|
-
BigDecimal :c2, :null=>false
|
244
|
-
|
245
|
-
primary_key [:c1, :c2]
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
END_MIG
|
250
|
-
end
|
251
|
-
|
252
|
-
it "should sort table names when dumping a migration" do
|
253
|
-
def @d.tables(o) [:t2, :t1] end
|
254
|
-
@d.dump_schema_migration.must_equal <<-END_MIG
|
255
|
-
Sequel.migration do
|
256
|
-
change do
|
257
|
-
create_table(:t1) do
|
258
|
-
primary_key :c1
|
259
|
-
String :c2, :size=>20
|
260
|
-
end
|
261
|
-
|
262
|
-
create_table(:t2) do
|
263
|
-
Integer :c1, :null=>false
|
264
|
-
BigDecimal :c2, :null=>false
|
265
|
-
|
266
|
-
primary_key [:c1, :c2]
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
END_MIG
|
271
|
-
end
|
272
|
-
|
273
|
-
it "should sort table names topologically when dumping a migration with foreign keys" do
|
274
|
-
def @d.tables(o) [:t1, :t2] end
|
275
|
-
def @d.schema(t, *o)
|
276
|
-
t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true}]]
|
277
|
-
end
|
278
|
-
def @d.supports_foreign_key_parsing?; true end
|
279
|
-
def @d.foreign_key_list(t)
|
280
|
-
t == :t1 ? [{:columns=>[:c2], :table=>:t2, :key=>[:c1]}] : []
|
281
|
-
end
|
282
|
-
@d.dump_schema_migration.must_equal <<-END_MIG
|
283
|
-
Sequel.migration do
|
284
|
-
change do
|
285
|
-
create_table(:t2) do
|
286
|
-
primary_key :c1
|
287
|
-
end
|
288
|
-
|
289
|
-
create_table(:t1) do
|
290
|
-
foreign_key :c2, :t2, :key=>[:c1]
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
END_MIG
|
295
|
-
end
|
296
|
-
|
297
|
-
it "should handle circular dependencies when dumping a migration with foreign keys" do
|
298
|
-
def @d.tables(o) [:t1, :t2] end
|
299
|
-
def @d.schema(t, *o)
|
300
|
-
t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer'}]]
|
301
|
-
end
|
302
|
-
def @d.supports_foreign_key_parsing?; true end
|
303
|
-
def @d.foreign_key_list(t)
|
304
|
-
t == :t1 ? [{:columns=>[:c2], :table=>:t2, :key=>[:c1]}] : [{:columns=>[:c1], :table=>:t1, :key=>[:c2]}]
|
305
|
-
end
|
306
|
-
@d.dump_schema_migration.must_equal <<-END_MIG
|
307
|
-
Sequel.migration do
|
308
|
-
change do
|
309
|
-
create_table(:t1) do
|
310
|
-
Integer :c2
|
311
|
-
end
|
312
|
-
|
313
|
-
create_table(:t2) do
|
314
|
-
foreign_key :c1, :t1, :key=>[:c2]
|
315
|
-
end
|
316
|
-
|
317
|
-
alter_table(:t1) do
|
318
|
-
add_foreign_key [:c2], :t2, :key=>[:c1]
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
322
|
-
END_MIG
|
323
|
-
end
|
324
|
-
|
325
|
-
it "should sort topologically even if the database raises an error when trying to parse foreign keys for a non-existent table" do
|
326
|
-
def @d.tables(o) [:t1, :t2] end
|
327
|
-
def @d.schema(t, *o)
|
328
|
-
t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true}]]
|
329
|
-
end
|
330
|
-
def @d.supports_foreign_key_parsing?; true end
|
331
|
-
def @d.foreign_key_list(t)
|
332
|
-
raise Sequel::DatabaseError unless [:t1, :t2].include?(t)
|
333
|
-
t == :t1 ? [{:columns=>[:c2], :table=>:t2, :key=>[:c1]}] : []
|
334
|
-
end
|
335
|
-
@d.dump_schema_migration.must_equal <<-END_MIG
|
336
|
-
Sequel.migration do
|
337
|
-
change do
|
338
|
-
create_table(:t2) do
|
339
|
-
primary_key :c1
|
340
|
-
end
|
341
|
-
|
342
|
-
create_table(:t1) do
|
343
|
-
foreign_key :c2, :t2, :key=>[:c1]
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
END_MIG
|
348
|
-
end
|
349
|
-
|
350
|
-
it "should honor the :same_db option to not convert types" do
|
351
|
-
@d.dump_table_schema(:t1, :same_db=>true).must_equal "create_table(:t1) do\n primary_key :c1\n column :c2, \"varchar(20)\"\nend"
|
352
|
-
@d.dump_schema_migration(:same_db=>true).must_equal <<-END_MIG
|
353
|
-
Sequel.migration do
|
354
|
-
change do
|
355
|
-
create_table(:t1) do
|
356
|
-
primary_key :c1
|
357
|
-
column :c2, "varchar(20)"
|
358
|
-
end
|
359
|
-
|
360
|
-
create_table(:t2) do
|
361
|
-
column :c1, "integer", :null=>false
|
362
|
-
column :c2, "numeric", :null=>false
|
363
|
-
|
364
|
-
primary_key [:c1, :c2]
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|
368
|
-
END_MIG
|
369
|
-
end
|
370
|
-
|
371
|
-
it "should honor the :index_names => false option to not include names of indexes" do
|
372
|
-
def @d.supports_index_parsing?; true end
|
373
|
-
def @d.indexes(t)
|
374
|
-
{:i1=>{:columns=>[:c1], :unique=>false},
|
375
|
-
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
|
376
|
-
end
|
377
|
-
@d.dump_table_schema(:t1, :index_names=>false).must_equal "create_table(:t1, :ignore_index_errors=>true) do\n primary_key :c1\n String :c2, :size=>20\n \n index [:c1]\n index [:c2, :c1], :unique=>true\nend"
|
378
|
-
@d.dump_schema_migration(:index_names=>false).must_equal <<-END_MIG
|
379
|
-
Sequel.migration do
|
380
|
-
change do
|
381
|
-
create_table(:t1, :ignore_index_errors=>true) do
|
382
|
-
primary_key :c1
|
383
|
-
String :c2, :size=>20
|
384
|
-
|
385
|
-
index [:c1]
|
386
|
-
index [:c2, :c1], :unique=>true
|
387
|
-
end
|
388
|
-
|
389
|
-
create_table(:t2, :ignore_index_errors=>true) do
|
390
|
-
Integer :c1, :null=>false
|
391
|
-
BigDecimal :c2, :null=>false
|
392
|
-
|
393
|
-
primary_key [:c1, :c2]
|
394
|
-
|
395
|
-
index [:c1]
|
396
|
-
index [:c2, :c1], :unique=>true
|
397
|
-
end
|
398
|
-
end
|
399
|
-
end
|
400
|
-
END_MIG
|
401
|
-
end
|
402
|
-
|
403
|
-
it "should make :index_names => :namespace option a noop if there is a global index namespace" do
|
404
|
-
def @d.supports_index_parsing?; true end
|
405
|
-
def @d.indexes(t)
|
406
|
-
{:i1=>{:columns=>[:c1], :unique=>false},
|
407
|
-
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>false}}
|
408
|
-
end
|
409
|
-
@d.dump_table_schema(:t1, :index_names=>:namespace).must_equal "create_table(:t1, :ignore_index_errors=>true) do\n primary_key :c1\n String :c2, :size=>20\n \n index [:c1], :name=>:i1\n index [:c2, :c1]\nend"
|
410
|
-
@d.dump_schema_migration(:index_names=>:namespace).must_equal <<-END_MIG
|
411
|
-
Sequel.migration do
|
412
|
-
change do
|
413
|
-
create_table(:t1, :ignore_index_errors=>true) do
|
414
|
-
primary_key :c1
|
415
|
-
String :c2, :size=>20
|
416
|
-
|
417
|
-
index [:c1], :name=>:i1
|
418
|
-
index [:c2, :c1]
|
419
|
-
end
|
420
|
-
|
421
|
-
create_table(:t2, :ignore_index_errors=>true) do
|
422
|
-
Integer :c1, :null=>false
|
423
|
-
BigDecimal :c2, :null=>false
|
424
|
-
|
425
|
-
primary_key [:c1, :c2]
|
426
|
-
|
427
|
-
index [:c1], :name=>:i1
|
428
|
-
index [:c2, :c1], :name=>:t1_c2_c1_index
|
429
|
-
end
|
430
|
-
end
|
431
|
-
end
|
432
|
-
END_MIG
|
433
|
-
end
|
434
|
-
|
435
|
-
it "should honor the :index_names => :namespace option to include names of indexes with prepended table name if there is no global index namespace" do
|
436
|
-
def @d.global_index_namespace?; false end
|
437
|
-
def @d.supports_index_parsing?; true end
|
438
|
-
def @d.indexes(t)
|
439
|
-
{:i1=>{:columns=>[:c1], :unique=>false},
|
440
|
-
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>false}}
|
441
|
-
end
|
442
|
-
@d.dump_table_schema(:t1, :index_names=>:namespace).must_equal "create_table(:t1, :ignore_index_errors=>true) do\n primary_key :c1\n String :c2, :size=>20\n \n index [:c1], :name=>:t1_i1\n index [:c2, :c1]\nend"
|
443
|
-
@d.dump_schema_migration(:index_names=>:namespace).must_equal <<-END_MIG
|
444
|
-
Sequel.migration do
|
445
|
-
change do
|
446
|
-
create_table(:t1, :ignore_index_errors=>true) do
|
447
|
-
primary_key :c1
|
448
|
-
String :c2, :size=>20
|
449
|
-
|
450
|
-
index [:c1], :name=>:t1_i1
|
451
|
-
index [:c2, :c1]
|
452
|
-
end
|
453
|
-
|
454
|
-
create_table(:t2, :ignore_index_errors=>true) do
|
455
|
-
Integer :c1, :null=>false
|
456
|
-
BigDecimal :c2, :null=>false
|
457
|
-
|
458
|
-
primary_key [:c1, :c2]
|
459
|
-
|
460
|
-
index [:c1], :name=>:t2_i1
|
461
|
-
index [:c2, :c1], :name=>:t2_t1_c2_c1_index
|
462
|
-
end
|
463
|
-
end
|
464
|
-
end
|
465
|
-
END_MIG
|
466
|
-
end
|
467
|
-
|
468
|
-
it "should honor the :indexes => false option to not include indexes" do
|
469
|
-
def @d.supports_index_parsing?; true end
|
470
|
-
def @d.indexes(t)
|
471
|
-
{:i1=>{:columns=>[:c1], :unique=>false},
|
472
|
-
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
|
473
|
-
end
|
474
|
-
@d.dump_table_schema(:t1, :indexes=>false).must_equal "create_table(:t1) do\n primary_key :c1\n String :c2, :size=>20\nend"
|
475
|
-
@d.dump_schema_migration(:indexes=>false).must_equal <<-END_MIG
|
476
|
-
Sequel.migration do
|
477
|
-
change do
|
478
|
-
create_table(:t1) do
|
479
|
-
primary_key :c1
|
480
|
-
String :c2, :size=>20
|
481
|
-
end
|
482
|
-
|
483
|
-
create_table(:t2) do
|
484
|
-
Integer :c1, :null=>false
|
485
|
-
BigDecimal :c2, :null=>false
|
486
|
-
|
487
|
-
primary_key [:c1, :c2]
|
488
|
-
end
|
489
|
-
end
|
490
|
-
end
|
491
|
-
END_MIG
|
492
|
-
end
|
493
|
-
|
494
|
-
it "should have :indexes => false option disable foreign keys as well when dumping a whole migration" do
|
495
|
-
def @d.foreign_key_list(t)
|
496
|
-
t == :t1 ? [{:columns=>[:c2], :table=>:t2, :key=>[:c1]}] : []
|
497
|
-
end
|
498
|
-
@d.dump_schema_migration(:indexes=>false).wont_match(/foreign_key/)
|
499
|
-
end
|
500
|
-
|
501
|
-
it "should have :foreign_keys option override :indexes => false disabling of foreign keys" do
|
502
|
-
def @d.supports_foreign_key_parsing?; true end
|
503
|
-
def @d.foreign_key_list(t)
|
504
|
-
t == :t1 ? [{:columns=>[:c2], :table=>:t2, :key=>[:c1]}] : []
|
505
|
-
end
|
506
|
-
@d.dump_schema_migration(:indexes=>false, :foreign_keys=>true).must_equal(<<OUTPUT)
|
507
|
-
Sequel.migration do
|
508
|
-
change do
|
509
|
-
create_table(:t2) do
|
510
|
-
Integer :c1, :null=>false
|
511
|
-
BigDecimal :c2, :null=>false
|
512
|
-
|
513
|
-
primary_key [:c1, :c2]
|
514
|
-
end
|
515
|
-
|
516
|
-
create_table(:t1) do
|
517
|
-
primary_key :c1
|
518
|
-
foreign_key :c2, :t2, :type=>String, :size=>20, :key=>[:c1]
|
519
|
-
end
|
520
|
-
end
|
521
|
-
end
|
522
|
-
OUTPUT
|
523
|
-
end
|
524
|
-
|
525
|
-
it "should support dumping just indexes as a migration" do
|
526
|
-
def @d.tables(o) [:t1] end
|
527
|
-
def @d.supports_index_parsing?; true end
|
528
|
-
def @d.indexes(t)
|
529
|
-
{:i1=>{:columns=>[:c1], :unique=>false},
|
530
|
-
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
|
531
|
-
end
|
532
|
-
@d.dump_indexes_migration.must_equal <<-END_MIG
|
533
|
-
Sequel.migration do
|
534
|
-
change do
|
535
|
-
add_index :t1, [:c1], :ignore_errors=>true, :name=>:i1
|
536
|
-
add_index :t1, [:c2, :c1], :ignore_errors=>true, :unique=>true
|
537
|
-
end
|
538
|
-
end
|
539
|
-
END_MIG
|
540
|
-
end
|
541
|
-
|
542
|
-
it "should honor the :index_names => false option to not include names of indexes when dumping just indexes as a migration" do
|
543
|
-
def @d.tables(o) [:t1] end
|
544
|
-
def @d.supports_index_parsing?; true end
|
545
|
-
def @d.indexes(t)
|
546
|
-
{:i1=>{:columns=>[:c1], :unique=>false},
|
547
|
-
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
|
548
|
-
end
|
549
|
-
@d.dump_indexes_migration(:index_names=>false).must_equal <<-END_MIG
|
550
|
-
Sequel.migration do
|
551
|
-
change do
|
552
|
-
add_index :t1, [:c1], :ignore_errors=>true
|
553
|
-
add_index :t1, [:c2, :c1], :ignore_errors=>true, :unique=>true
|
554
|
-
end
|
555
|
-
end
|
556
|
-
END_MIG
|
557
|
-
end
|
558
|
-
|
559
|
-
it "should honor the :index_names => :namespace option be a noop if there is a global index namespace" do
|
560
|
-
def @d.tables(o) [:t1, :t2] end
|
561
|
-
def @d.supports_index_parsing?; true end
|
562
|
-
def @d.indexes(t)
|
563
|
-
{:i1=>{:columns=>[:c1], :unique=>false},
|
564
|
-
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>false}}
|
565
|
-
end
|
566
|
-
@d.dump_indexes_migration(:index_names=>:namespace).must_equal <<-END_MIG
|
567
|
-
Sequel.migration do
|
568
|
-
change do
|
569
|
-
add_index :t1, [:c1], :ignore_errors=>true, :name=>:i1
|
570
|
-
add_index :t1, [:c2, :c1], :ignore_errors=>true
|
571
|
-
|
572
|
-
add_index :t2, [:c1], :ignore_errors=>true, :name=>:i1
|
573
|
-
add_index :t2, [:c2, :c1], :ignore_errors=>true, :name=>:t1_c2_c1_index
|
574
|
-
end
|
575
|
-
end
|
576
|
-
END_MIG
|
577
|
-
end
|
578
|
-
|
579
|
-
it "should honor the :index_names => :namespace option to include names of indexes with prepended table name when dumping just indexes as a migration if there is no global index namespace" do
|
580
|
-
def @d.global_index_namespace?; false end
|
581
|
-
def @d.tables(o) [:t1, :t2] end
|
582
|
-
def @d.supports_index_parsing?; true end
|
583
|
-
def @d.indexes(t)
|
584
|
-
{:i1=>{:columns=>[:c1], :unique=>false},
|
585
|
-
:t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>false}}
|
586
|
-
end
|
587
|
-
@d.dump_indexes_migration(:index_names=>:namespace).must_equal <<-END_MIG
|
588
|
-
Sequel.migration do
|
589
|
-
change do
|
590
|
-
add_index :t1, [:c1], :ignore_errors=>true, :name=>:t1_i1
|
591
|
-
add_index :t1, [:c2, :c1], :ignore_errors=>true
|
592
|
-
|
593
|
-
add_index :t2, [:c1], :ignore_errors=>true, :name=>:t2_i1
|
594
|
-
add_index :t2, [:c2, :c1], :ignore_errors=>true, :name=>:t2_t1_c2_c1_index
|
595
|
-
end
|
596
|
-
end
|
597
|
-
END_MIG
|
598
|
-
end
|
599
|
-
|
600
|
-
it "should handle missing index parsing support when dumping index migration" do
|
601
|
-
def @d.tables(o) [:t1] end
|
602
|
-
@d.dump_indexes_migration.must_equal <<-END_MIG
|
603
|
-
Sequel.migration do
|
604
|
-
change do
|
605
|
-
|
606
|
-
end
|
607
|
-
end
|
608
|
-
END_MIG
|
609
|
-
end
|
610
|
-
|
611
|
-
it "should handle missing foreign key parsing support when dumping foreign key migration" do
|
612
|
-
def @d.tables(o) [:t1] end
|
613
|
-
@d.dump_foreign_key_migration.must_equal <<-END_MIG
|
614
|
-
Sequel.migration do
|
615
|
-
change do
|
616
|
-
|
617
|
-
end
|
618
|
-
end
|
619
|
-
END_MIG
|
620
|
-
end
|
621
|
-
|
622
|
-
it "should support dumping just foreign_keys as a migration" do
|
623
|
-
def @d.tables(o) [:t1, :t2, :t3] end
|
624
|
-
def @d.schema(t, *o)
|
625
|
-
t == :t1 ? [[:c2, {:db_type=>'integer'}]] : [[:c1, {:db_type=>'integer'}]]
|
626
|
-
end
|
627
|
-
def @d.supports_foreign_key_parsing?; true end
|
628
|
-
def @d.foreign_key_list(t, *a)
|
629
|
-
case t
|
630
|
-
when :t1
|
631
|
-
[{:columns=>[:c2], :table=>:t2, :key=>[:c1]}]
|
632
|
-
when :t2
|
633
|
-
[{:columns=>[:c1, :c3], :table=>:t1, :key=>[:c2, :c4]}]
|
634
|
-
else
|
635
|
-
[]
|
636
|
-
end
|
637
|
-
end
|
638
|
-
@d.dump_foreign_key_migration.must_equal <<-END_MIG
|
639
|
-
Sequel.migration do
|
640
|
-
change do
|
641
|
-
alter_table(:t1) do
|
642
|
-
add_foreign_key [:c2], :t2, :key=>[:c1]
|
643
|
-
end
|
644
|
-
|
645
|
-
alter_table(:t2) do
|
646
|
-
add_foreign_key [:c1, :c3], :t1, :key=>[:c2, :c4]
|
647
|
-
end
|
648
|
-
end
|
649
|
-
end
|
650
|
-
END_MIG
|
651
|
-
end
|
652
|
-
|
653
|
-
it "should handle not null values and defaults" do
|
654
|
-
def @d.schema(*s) [[:c1, {:db_type=>'date', :default=>"'now()'", :allow_null=>true}], [:c2, {:db_type=>'datetime', :allow_null=>false}]] end
|
655
|
-
@d.dump_table_schema(:t3).must_equal "create_table(:t3) do\n Date :c1\n DateTime :c2, :null=>false\nend"
|
656
|
-
end
|
657
|
-
|
658
|
-
it "should handle converting common defaults" do
|
659
|
-
def @d.schema(t, *os)
|
660
|
-
s = [[:c1, {:db_type=>'boolean', :default=>"false", :type=>:boolean, :allow_null=>true}],
|
661
|
-
[:c2, {:db_type=>'varchar', :default=>"'blah'", :type=>:string, :allow_null=>true}],
|
662
|
-
[:c3, {:db_type=>'integer', :default=>"-1", :type=>:integer, :allow_null=>true}],
|
663
|
-
[:c4, {:db_type=>'float', :default=>"1.0", :type=>:float, :allow_null=>true}],
|
664
|
-
[:c5, {:db_type=>'decimal', :default=>"100.50", :type=>:decimal, :allow_null=>true}],
|
665
|
-
[:c6, {:db_type=>'blob', :default=>"'blah'", :type=>:blob, :allow_null=>true}],
|
666
|
-
[:c7, {:db_type=>'date', :default=>"'2008-10-29'", :type=>:date, :allow_null=>true}],
|
667
|
-
[:c8, {:db_type=>'datetime', :default=>"'2008-10-29 10:20:30'", :type=>:datetime, :allow_null=>true}],
|
668
|
-
[:c9, {:db_type=>'time', :default=>"'10:20:30'", :type=>:time, :allow_null=>true}],
|
669
|
-
[:c10, {:db_type=>'foo', :default=>"'6 weeks'", :type=>nil, :allow_null=>true}],
|
670
|
-
[:c11, {:db_type=>'date', :default=>"CURRENT_DATE", :type=>:date, :allow_null=>true}],
|
671
|
-
[:c12, {:db_type=>'timestamp', :default=>"now()", :type=>:datetime, :allow_null=>true}]]
|
672
|
-
s.each{|_, c| c[:ruby_default] = column_schema_to_ruby_default(c[:default], c[:type])}
|
673
|
-
s
|
674
|
-
end
|
675
|
-
e = RUBY_VERSION >= '2.4' ? 'e' : 'E'
|
676
|
-
@d.dump_table_schema(:t4).gsub(/[+-]\d\d\d\d"\)/, '")').gsub(/\.0+/, '.0').must_equal "create_table(:t4) do\n TrueClass :c1, :default=>false\n String :c2, :default=>\"blah\"\n Integer :c3, :default=>-1\n Float :c4, :default=>1.0\n BigDecimal :c5, :default=>Kernel::BigDecimal(\"0.1005#{e}3\")\n File :c6, :default=>Sequel::SQL::Blob.new(\"blah\")\n Date :c7, :default=>Date.new(2008, 10, 29)\n DateTime :c8, :default=>DateTime.parse(\"2008-10-29T10:20:30.0\")\n Time :c9, :default=>Sequel::SQLTime.parse(\"10:20:30.0\"), :only_time=>true\n String :c10\n Date :c11, :default=>Sequel::CURRENT_DATE\n DateTime :c12, :default=>Sequel::CURRENT_TIMESTAMP\nend"
|
677
|
-
@d.dump_table_schema(:t4, :same_db=>true).gsub(/[+-]\d\d\d\d"\)/, '")').gsub(/\.0+/, '.0').must_equal "create_table(:t4) do\n column :c1, \"boolean\", :default=>false\n column :c2, \"varchar\", :default=>\"blah\"\n column :c3, \"integer\", :default=>-1\n column :c4, \"float\", :default=>1.0\n column :c5, \"decimal\", :default=>Kernel::BigDecimal(\"0.1005#{e}3\")\n column :c6, \"blob\", :default=>Sequel::SQL::Blob.new(\"blah\")\n column :c7, \"date\", :default=>Date.new(2008, 10, 29)\n column :c8, \"datetime\", :default=>DateTime.parse(\"2008-10-29T10:20:30.0\")\n column :c9, \"time\", :default=>Sequel::SQLTime.parse(\"10:20:30.0\")\n column :c10, \"foo\", :default=>Sequel::LiteralString.new(\"'6 weeks'\")\n column :c11, \"date\", :default=>Sequel::CURRENT_DATE\n column :c12, \"timestamp\", :default=>Sequel::CURRENT_TIMESTAMP\nend"
|
678
|
-
end
|
679
|
-
|
680
|
-
it "should not use a literal string as a fallback if using MySQL with the :same_db option" do
|
681
|
-
def @d.database_type; :mysql end
|
682
|
-
def @d.supports_index_parsing?; false end
|
683
|
-
def @d.supports_foreign_key_parsing?; false end
|
684
|
-
def @d.schema(t, *os)
|
685
|
-
s = [[:c10, {:db_type=>'foo', :default=>"'6 weeks'", :type=>nil, :allow_null=>true}]]
|
686
|
-
s.each{|_, c| c[:ruby_default] = column_schema_to_ruby_default(c[:default], c[:type])}
|
687
|
-
s
|
688
|
-
end
|
689
|
-
@d.dump_table_schema(:t5, :same_db=>true).must_equal "create_table(:t5) do\n column :c10, \"foo\"\nend"
|
690
|
-
end
|
691
|
-
|
692
|
-
it "should convert unknown database types to strings" do
|
693
|
-
@d.dump_table_schema(:t5).must_equal "create_table(:t5) do\n String :c1\nend"
|
694
|
-
end
|
695
|
-
|
696
|
-
it "should convert many database types to ruby types" do
|
697
|
-
def @d.schema(t, *o)
|
698
|
-
types = %w"mediumint smallint int integer mediumint(6) smallint(7) int(8) integer(9)
|
699
|
-
tinyint tinyint(2) bigint bigint(20) real float double boolean tinytext mediumtext
|
700
|
-
longtext text clob date datetime timestamp time char character
|
701
|
-
varchar varchar(255) varchar(30) bpchar string money
|
702
|
-
decimal decimal(10,2) numeric numeric(15,3) number bytea tinyblob mediumblob longblob
|
703
|
-
blob varbinary varbinary(10) binary binary(20) year" +
|
704
|
-
["double precision", "timestamp with time zone", "timestamp without time zone",
|
705
|
-
"time with time zone", "time without time zone", "character varying(20)"] +
|
706
|
-
%w"nvarchar ntext smalldatetime smallmoney binary varbinary nchar" +
|
707
|
-
["timestamp(6) without time zone", "timestamp(6) with time zone", 'mediumint(10) unsigned', 'int(9) unsigned',
|
708
|
-
'int(10) unsigned', "int(12) unsigned", 'bigint unsigned', 'tinyint(3) unsigned', 'identity', 'int identity'] +
|
709
|
-
%w"integer(10) bit bool"
|
710
|
-
i = 0
|
711
|
-
types.map{|x| [:"c#{i+=1}", {:db_type=>x, :allow_null=>true}]}
|
712
|
-
end
|
713
|
-
@d.dump_table_schema(:x).must_equal((<<END_MIG).chomp)
|
714
|
-
create_table(:x) do
|
715
|
-
Integer :c1
|
716
|
-
Integer :c2
|
717
|
-
Integer :c3
|
718
|
-
Integer :c4
|
719
|
-
Integer :c5
|
720
|
-
Integer :c6
|
721
|
-
Integer :c7
|
722
|
-
Integer :c8
|
723
|
-
Integer :c9
|
724
|
-
Integer :c10
|
725
|
-
Bignum :c11
|
726
|
-
Bignum :c12
|
727
|
-
Float :c13
|
728
|
-
Float :c14
|
729
|
-
Float :c15
|
730
|
-
TrueClass :c16
|
731
|
-
String :c17, :text=>true
|
732
|
-
String :c18, :text=>true
|
733
|
-
String :c19, :text=>true
|
734
|
-
String :c20, :text=>true
|
735
|
-
String :c21, :text=>true
|
736
|
-
Date :c22
|
737
|
-
DateTime :c23
|
738
|
-
DateTime :c24
|
739
|
-
Time :c25, :only_time=>true
|
740
|
-
String :c26, :fixed=>true
|
741
|
-
String :c27, :fixed=>true
|
742
|
-
String :c28
|
743
|
-
String :c29, :size=>255
|
744
|
-
String :c30, :size=>30
|
745
|
-
String :c31
|
746
|
-
String :c32
|
747
|
-
BigDecimal :c33, :size=>[19, 2]
|
748
|
-
BigDecimal :c34
|
749
|
-
BigDecimal :c35, :size=>[10, 2]
|
750
|
-
BigDecimal :c36
|
751
|
-
BigDecimal :c37, :size=>[15, 3]
|
752
|
-
BigDecimal :c38
|
753
|
-
File :c39
|
754
|
-
File :c40
|
755
|
-
File :c41
|
756
|
-
File :c42
|
757
|
-
File :c43
|
758
|
-
File :c44
|
759
|
-
File :c45, :size=>10
|
760
|
-
File :c46
|
761
|
-
File :c47, :size=>20
|
762
|
-
Integer :c48
|
763
|
-
Float :c49
|
764
|
-
DateTime :c50
|
765
|
-
DateTime :c51
|
766
|
-
Time :c52, :only_time=>true
|
767
|
-
Time :c53, :only_time=>true
|
768
|
-
String :c54, :size=>20
|
769
|
-
String :c55
|
770
|
-
String :c56, :text=>true
|
771
|
-
DateTime :c57
|
772
|
-
BigDecimal :c58, :size=>[19, 2]
|
773
|
-
File :c59
|
774
|
-
File :c60
|
775
|
-
String :c61, :fixed=>true
|
776
|
-
DateTime :c62, :size=>6
|
777
|
-
DateTime :c63, :size=>6
|
778
|
-
Integer :c64
|
779
|
-
Integer :c65
|
780
|
-
Bignum :c66
|
781
|
-
Bignum :c67
|
782
|
-
Bignum :c68
|
783
|
-
Integer :c69
|
784
|
-
Integer :c70
|
785
|
-
Integer :c71
|
786
|
-
Integer :c72
|
787
|
-
TrueClass :c73
|
788
|
-
TrueClass :c74
|
789
|
-
|
790
|
-
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c64), 0)
|
791
|
-
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c65), 0)
|
792
|
-
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c66), 0)
|
793
|
-
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c67), 0)
|
794
|
-
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c68), 0)
|
795
|
-
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c69), 0)
|
796
|
-
end
|
797
|
-
END_MIG
|
798
|
-
end
|
799
|
-
|
800
|
-
it "should convert mysql types to ruby types" do
|
801
|
-
def @d.schema(t, *o)
|
802
|
-
i = 0
|
803
|
-
['float unsigned', 'double(15,2)', 'double(7,1) unsigned'].map{|x| [:"c#{i+=1}", {:db_type=>x, :allow_null=>true}]}
|
804
|
-
end
|
805
|
-
@d.dump_table_schema(:x).must_equal((<<END_MIG).chomp)
|
806
|
-
create_table(:x) do
|
807
|
-
Float :c1
|
808
|
-
Float :c2
|
809
|
-
Float :c3
|
810
|
-
|
811
|
-
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c1), 0)
|
812
|
-
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c3), 0)
|
813
|
-
end
|
814
|
-
END_MIG
|
815
|
-
end
|
816
|
-
|
817
|
-
it "should convert oracle special types to ruby types" do
|
818
|
-
def @d.database_type; :oracle end
|
819
|
-
def @d.schema(t, *o)
|
820
|
-
i = 0
|
821
|
-
['number not null', 'date not null', 'varchar2(4 byte) not null'].map{|x| [:"c#{i+=1}", {:db_type=>x, :allow_null=>false}]}
|
822
|
-
end
|
823
|
-
@d.dump_table_schema(:x).must_equal((<<END_MIG).chomp)
|
824
|
-
create_table(:x) do
|
825
|
-
BigDecimal :c1, :null=>false
|
826
|
-
Date :c2, :null=>false
|
827
|
-
String :c3, :null=>false
|
828
|
-
end
|
829
|
-
END_MIG
|
830
|
-
end
|
831
|
-
|
832
|
-
it "should force specify :null option for MySQL timestamp columns when using :same_db" do
|
833
|
-
def @d.database_type; :mysql end
|
834
|
-
def @d.schema(*s) [[:c1, {:db_type=>'timestamp', :primary_key=>true, :allow_null=>true}]] end
|
835
|
-
@d.dump_table_schema(:t3, :same_db=>true).must_equal "create_table(:t3) do\n column :c1, \"timestamp\", :null=>true\n \n primary_key [:c1]\nend"
|
836
|
-
|
837
|
-
def @d.schema(*s) [[:c1, {:db_type=>'timestamp', :primary_key=>true, :allow_null=>false}]] end
|
838
|
-
@d.dump_table_schema(:t3, :same_db=>true).must_equal "create_table(:t3) do\n column :c1, \"timestamp\", :null=>false\n \n primary_key [:c1]\nend"
|
839
|
-
end
|
840
|
-
|
841
|
-
it "should use separate primary_key call with non autoincrementable types" do
|
842
|
-
def @d.schema(*s) [[:c1, {:db_type=>'varchar(8)', :primary_key=>true, :auto_increment=>false}]] end
|
843
|
-
@d.dump_table_schema(:t3).must_equal "create_table(:t3) do\n String :c1, :size=>8\n \n primary_key [:c1]\nend"
|
844
|
-
@d.dump_table_schema(:t3, :same_db=>true).must_equal "create_table(:t3) do\n column :c1, \"varchar(8)\"\n \n primary_key [:c1]\nend"
|
845
|
-
end
|
846
|
-
|
847
|
-
it "should use explicit type for non integer foreign_key types" do
|
848
|
-
def @d.schema(*s) [[:c1, {:db_type=>'date', :primary_key=>true, :auto_increment=>false}]] end
|
849
|
-
def @d.supports_foreign_key_parsing?; true end
|
850
|
-
def @d.foreign_key_list(t, *a) [{:columns=>[:c1], :table=>:t3, :key=>[:c1]}] if t == :t4 end
|
851
|
-
["create_table(:t4) do\n foreign_key :c1, :t3, :type=>Date, :key=>[:c1]\n \n primary_key [:c1]\nend",
|
852
|
-
"create_table(:t4) do\n foreign_key :c1, :t3, :key=>[:c1], :type=>Date\n \n primary_key [:c1]\nend"].must_include(@d.dump_table_schema(:t4))
|
853
|
-
["create_table(:t4) do\n foreign_key :c1, :t3, :type=>\"date\", :key=>[:c1]\n \n primary_key [:c1]\nend",
|
854
|
-
"create_table(:t4) do\n foreign_key :c1, :t3, :key=>[:c1], :type=>\"date\"\n \n primary_key [:c1]\nend"].must_include(@d.dump_table_schema(:t4, :same_db=>true))
|
855
|
-
end
|
856
|
-
|
857
|
-
it "should correctly handing autoincrementing primary keys that are also foreign keys" do
|
858
|
-
def @d.schema(*s) [[:c1, {:db_type=>'integer', :primary_key=>true, :auto_increment=>true}]] end
|
859
|
-
def @d.supports_foreign_key_parsing?; true end
|
860
|
-
def @d.foreign_key_list(t, *a) [{:columns=>[:c1], :table=>:t3, :key=>[:c1]}] if t == :t4 end
|
861
|
-
["create_table(:t4) do\n primary_key :c1, :table=>:t3, :key=>[:c1]\nend",
|
862
|
-
"create_table(:t4) do\n primary_key :c1, :key=>[:c1], :table=>:t3\nend"].must_include(@d.dump_table_schema(:t4))
|
863
|
-
end
|
864
|
-
|
865
|
-
it "should handle dumping on PostgreSQL using qualified tables" do
|
866
|
-
@d = Sequel.connect('mock://postgres').extension(:schema_dumper)
|
867
|
-
def @d.schema(*s) [[:c1, {:db_type=>'timestamp', :primary_key=>true, :allow_null=>true}]] end
|
868
|
-
@d.dump_table_schema(Sequel.qualify(:foo, :bar), :same_db=>true).must_equal "create_table(Sequel::SQL::QualifiedIdentifier.new(:foo, :bar)) do\n column :c1, \"timestamp\"\n \n primary_key [:c1]\nend"
|
869
|
-
end
|
870
|
-
end
|