activerecord-cockroachdb-adapter 8.0.2 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +10 -17
- data/Gemfile +2 -1
- data/Rakefile +0 -19
- data/lib/active_record/connection_adapters/cockroachdb/column.rb +66 -24
- data/lib/active_record/connection_adapters/cockroachdb/database_statements.rb +13 -3
- data/lib/active_record/connection_adapters/cockroachdb/database_tasks.rb +1 -1
- data/lib/active_record/connection_adapters/cockroachdb/oid/spatial.rb +34 -19
- data/lib/active_record/connection_adapters/cockroachdb/quoting.rb +19 -3
- data/lib/active_record/connection_adapters/cockroachdb/referential_integrity.rb +87 -55
- data/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb +181 -102
- data/lib/active_record/connection_adapters/cockroachdb_adapter.rb +42 -25
- data/lib/version.rb +1 -1
- data/test/cases/adapter_test.rb +98 -0
- data/test/cases/adapters/cockroachdb/referential_integrity_test.rb +51 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +71 -0
- data/test/cases/adapters/postgresql/change_schema_test.rb +75 -0
- data/test/cases/adapters/postgresql/connection_test.rb +46 -0
- data/test/cases/adapters/postgresql/ddl_test.rb +326 -0
- data/test/cases/adapters/postgresql/interval_test.rb +131 -0
- data/test/cases/adapters/postgresql/nested_class_test.rb +22 -0
- data/test/cases/adapters/postgresql/numeric_test.rb +28 -0
- data/test/cases/adapters/postgresql/postgis_test.rb +185 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +115 -0
- data/test/cases/adapters/postgresql/quoting_test.rb +30 -0
- data/test/cases/adapters/postgresql/schema_statements_test.rb +29 -0
- data/test/cases/adapters/postgresql/serial_test.rb +199 -0
- data/test/cases/adapters/postgresql/spatial_queries_test.rb +118 -0
- data/test/cases/adapters/postgresql/spatial_setup_test.rb +18 -0
- data/test/cases/adapters/postgresql/spatial_type_test.rb +41 -0
- data/test/cases/adapters/postgresql/timestamp_test.rb +58 -0
- data/test/cases/adapters/postgresql/virtual_column_test.rb +39 -0
- data/test/cases/associations/eager_load_nested_include_test.rb +111 -0
- data/test/cases/associations/left_outer_join_association_test.rb +30 -0
- data/test/cases/associations_test.rb +108 -0
- data/test/cases/base_test.rb +31 -0
- data/test/cases/comment_test.rb +75 -0
- data/test/cases/connection_adapters/type_test.rb +28 -0
- data/test/cases/database_configurations/resolver_test.rb +24 -0
- data/test/cases/defaults_test.rb +45 -0
- data/test/cases/dirty_test.rb +24 -0
- data/test/cases/fixtures_test.rb +541 -0
- data/test/cases/helper_cockroachdb.rb +232 -0
- data/test/cases/inheritance_test.rb +42 -0
- data/test/cases/invertible_migration_test.rb +73 -0
- data/test/cases/marshal_serialization_test.rb +45 -0
- data/test/cases/migration/change_schema_test.rb +140 -0
- data/test/cases/migration/check_constraint_test.rb +125 -0
- data/test/cases/migration/columns_test.rb +50 -0
- data/test/cases/migration/create_join_table_test.rb +66 -0
- data/test/cases/migration/foreign_key_test.rb +390 -0
- data/test/cases/migration/hidden_column_test.rb +70 -0
- data/test/cases/migration/references_foreign_key_test.rb +124 -0
- data/test/cases/migration_test.rb +120 -0
- data/test/cases/persistence_test.rb +33 -0
- data/test/cases/primary_keys_test.rb +134 -0
- data/test/cases/relation/aost_test.rb +57 -0
- data/test/cases/relation/or_test.rb +26 -0
- data/test/cases/relation/table_hints_test.rb +124 -0
- data/test/cases/relation_test.rb +26 -0
- data/test/cases/relations_test.rb +29 -0
- data/test/cases/schema_dumper_test.rb +221 -0
- data/test/cases/show_create_test.rb +14 -0
- data/test/cases/strict_loading_test.rb +34 -0
- data/test/cases/tasks/cockroachdb_rake_test.rb +113 -0
- data/test/cases/test_fixtures_test.rb +57 -0
- data/test/cases/transactions_test.rb +51 -0
- data/test/cases/unsafe_raw_sql_test.rb +22 -0
- data/test/config.yml +23 -0
- data/test/excludes/ActiveRecord/AdapterTest.rb +3 -0
- data/test/excludes/ActiveRecord/AdapterTestWithoutTransaction.rb +25 -0
- data/test/excludes/ActiveRecord/ConnectionAdapters/PoolConfig/ResolverTest.rb +1 -0
- data/test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter/BindParameterTest.rb +15 -0
- data/test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter/QuotingTest.rb +22 -0
- data/test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapterPreventWritesLegacyTest.rb +1 -0
- data/test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapterPreventWritesTest.rb +1 -0
- data/test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapterTest.rb +40 -0
- data/test/excludes/ActiveRecord/ConnectionAdapters/RegistrationIsolatedTest.rb +14 -0
- data/test/excludes/ActiveRecord/Encryption/EncryptionPerformanceTest.rb +1 -0
- data/test/excludes/ActiveRecord/Encryption/EnvelopeEncryptionPerformanceTest.rb +1 -0
- data/test/excludes/ActiveRecord/Encryption/ExtendedDeterministicQueriesPerformanceTest.rb +1 -0
- data/test/excludes/ActiveRecord/Encryption/StoragePerformanceTest.rb +2 -0
- data/test/excludes/ActiveRecord/InstrumentationTest.rb +16 -0
- data/test/excludes/ActiveRecord/InvertibleMigrationTest.rb +2 -0
- data/test/excludes/ActiveRecord/Migration/ChangeSchemaTest.rb +7 -0
- data/test/excludes/ActiveRecord/Migration/CheckConstraintTest.rb +6 -0
- data/test/excludes/ActiveRecord/Migration/ColumnsTest.rb +4 -0
- data/test/excludes/ActiveRecord/Migration/CompatibilityTest.rb +50 -0
- data/test/excludes/ActiveRecord/Migration/CompositeForeignKeyTest.rb +2 -0
- data/test/excludes/ActiveRecord/Migration/CreateJoinTableTest.rb +2 -0
- data/test/excludes/ActiveRecord/Migration/ForeignKeyInCreateTest.rb +1 -0
- data/test/excludes/ActiveRecord/Migration/ForeignKeyTest.rb +35 -0
- data/test/excludes/ActiveRecord/Migration/InvalidOptionsTest.rb +14 -0
- data/test/excludes/ActiveRecord/Migration/PGChangeSchemaTest.rb +8 -0
- data/test/excludes/ActiveRecord/Migration/ReferencesForeignKeyTest.rb +7 -0
- data/test/excludes/ActiveRecord/Migration/ReferencesIndexTest.rb +7 -0
- data/test/excludes/ActiveRecord/Migration/ReferencesStatementsTest.rb +3 -0
- data/test/excludes/ActiveRecord/MysqlDBCreateWithInvalidPermissionsTest.rb +1 -0
- data/test/excludes/ActiveRecord/OrTest.rb +1 -0
- data/test/excludes/ActiveRecord/PostgreSQLStructureDumpTest.rb +10 -0
- data/test/excludes/ActiveRecord/PostgresqlConnectionTest.rb +12 -0
- data/test/excludes/ActiveRecord/PostgresqlTransactionNestedTest.rb +14 -0
- data/test/excludes/ActiveRecord/PostgresqlTransactionTest.rb +4 -0
- data/test/excludes/ActiveRecord/RelationTest.rb +2 -0
- data/test/excludes/ActiveRecord/TooManyOrTest.rb +1 -0
- data/test/excludes/ActiveSupportSubclassWithFixturesTest.rb +1 -0
- data/test/excludes/AssociationDeprecationTest/NotifyModeTest.rb +2 -0
- data/test/excludes/AssociationDeprecationTest/RaiseBacktraceModeTest.rb +2 -0
- data/test/excludes/AssociationDeprecationTest/RaiseModeTest.rb +2 -0
- data/test/excludes/AssociationDeprecationTest/WarnBacktraceModeTest.rb +2 -0
- data/test/excludes/AssociationDeprecationTest/WarnModeTest.rb +2 -0
- data/test/excludes/AssociationDeprecationTest/fix_backtrace_cleaner.rb +10 -0
- data/test/excludes/BasicsTest.rb +1 -0
- data/test/excludes/BulkAlterTableMigrationsTest.rb +7 -0
- data/test/excludes/CalculationsTest.rb +4 -0
- data/test/excludes/CommentTest.rb +2 -0
- data/test/excludes/CoreTest.rb +1 -0
- data/test/excludes/CreateOrFindByWithinTransactions.rb +3 -0
- data/test/excludes/DefaultsUsingMultipleSchemasAndDomainTest.rb +7 -0
- data/test/excludes/DirtyTest.rb +3 -0
- data/test/excludes/EachTest.rb +8 -0
- data/test/excludes/EagerLoadPolyAssocsTest.rb +1 -0
- data/test/excludes/ExplicitlyNamedIndexMigrationTest.rb +1 -0
- data/test/excludes/FixturesResetPkSequenceTest.rb +3 -0
- data/test/excludes/FixturesTest.rb +21 -0
- data/test/excludes/FixturesWithForeignKeyViolationsTest.rb +2 -0
- data/test/excludes/ForeignTableTest.rb +10 -0
- data/test/excludes/InheritanceComputeTypeTest.rb +1 -0
- data/test/excludes/LeftOuterJoinAssociationTest.rb +2 -0
- data/test/excludes/LegacyPrimaryKeyTest/V4_2.rb +6 -0
- data/test/excludes/LegacyPrimaryKeyTest/V5_0.rb +6 -0
- data/test/excludes/MarshalSerializationTest.rb +4 -0
- data/test/excludes/MaterializedViewTest.rb +13 -0
- data/test/excludes/MigrationTest.rb +2 -0
- data/test/excludes/MultiDbMigratorTest.rb +2 -0
- data/test/excludes/NestedRelationScopingTest.rb +1 -0
- data/test/excludes/OrTest.rb +1 -0
- data/test/excludes/PersistenceTest.rb +3 -0
- data/test/excludes/PessimisticLockingTest.rb +1 -0
- data/test/excludes/PostgreSQLExplainTest.rb +7 -0
- data/test/excludes/PostgreSQLGeometricLineTest.rb +3 -0
- data/test/excludes/PostgreSQLGeometricTypesTest.rb +7 -0
- data/test/excludes/PostgreSQLPartitionsTest.rb +1 -0
- data/test/excludes/PostgreSQLReferentialIntegrityTest.rb +14 -0
- data/test/excludes/PostgresqlArrayTest.rb +21 -0
- data/test/excludes/PostgresqlBigSerialTest.rb +7 -0
- data/test/excludes/PostgresqlBitStringTest.rb +2 -0
- data/test/excludes/PostgresqlByteaTest.rb +1 -0
- data/test/excludes/PostgresqlCitextTest.rb +7 -0
- data/test/excludes/PostgresqlCollationTest.rb +5 -0
- data/test/excludes/PostgresqlCompositeTest.rb +2 -0
- data/test/excludes/PostgresqlCompositeWithCustomOIDTest.rb +2 -0
- data/test/excludes/PostgresqlDataTypeTest.rb +9 -0
- data/test/excludes/PostgresqlDefaultExpressionTest.rb +1 -0
- data/test/excludes/PostgresqlDeferredConstraintsTest.rb +3 -0
- data/test/excludes/PostgresqlDomainTest.rb +2 -0
- data/test/excludes/PostgresqlExtensionMigrationTest.rb +5 -0
- data/test/excludes/PostgresqlFullTextTest.rb +3 -0
- data/test/excludes/PostgresqlGeometricTest.rb +4 -0
- data/test/excludes/PostgresqlHstoreTest.rb +45 -0
- data/test/excludes/PostgresqlInfinityTest.rb +5 -0
- data/test/excludes/PostgresqlIntervalTest.rb +1 -0
- data/test/excludes/PostgresqlJSONBTest.rb +27 -0
- data/test/excludes/PostgresqlJSONTest.rb +27 -0
- data/test/excludes/PostgresqlLtreeTest.rb +4 -0
- data/test/excludes/PostgresqlMoneyTest.rb +12 -0
- data/test/excludes/PostgresqlNetworkTest.rb +69 -0
- data/test/excludes/PostgresqlNumberTest.rb +1 -0
- data/test/excludes/PostgresqlPointTest.rb +15 -0
- data/test/excludes/PostgresqlRangeTest.rb +3 -0
- data/test/excludes/PostgresqlRenameTableTest.rb +2 -0
- data/test/excludes/PostgresqlSerialTest.rb +7 -0
- data/test/excludes/PostgresqlTimestampFixtureTest.rb +2 -0
- data/test/excludes/PostgresqlTimestampMigrationTest.rb +3 -0
- data/test/excludes/PostgresqlTypeLookupTest.rb +2 -0
- data/test/excludes/PostgresqlUUIDGenerationTest.rb +7 -0
- data/test/excludes/PostgresqlUUIDTest.rb +1 -0
- data/test/excludes/PostgresqlVirtualColumnTest.rb +17 -0
- data/test/excludes/PostgresqlXMLTest.rb +5 -0
- data/test/excludes/PrimaryKeyIntegerNilDefaultTest.rb +1 -0
- data/test/excludes/PrimaryKeyIntegerTest.rb +3 -0
- data/test/excludes/PrimaryKeysTest.rb +2 -0
- data/test/excludes/RelationMergingTest.rb +15 -0
- data/test/excludes/RelationTest.rb +3 -0
- data/test/excludes/ReservedWordsMigrationTest.rb +1 -0
- data/test/excludes/SameNameDifferentDatabaseFixturesTest.rb +1 -0
- data/test/excludes/SanitizeTest.rb +13 -0
- data/test/excludes/SchemaAuthorizationTest.rb +8 -0
- data/test/excludes/SchemaCreateTableOptionsTest.rb +2 -0
- data/test/excludes/SchemaDumperDefaultsTest.rb +1 -0
- data/test/excludes/SchemaDumperTest.rb +11 -0
- data/test/excludes/SchemaForeignKeyTest.rb +1 -0
- data/test/excludes/SchemaIndexNullsOrderTest.rb +2 -0
- data/test/excludes/SchemaIndexOpclassTest.rb +3 -0
- data/test/excludes/SchemaTest.rb +49 -0
- data/test/excludes/SequenceNameDetectionTestCases/CollidedSequenceNameTest.rb +1 -0
- data/test/excludes/SequenceNameDetectionTestCases/LongerSequenceNameDetectionTest.rb +1 -0
- data/test/excludes/StrictLoadingFixturesTest.rb +1 -0
- data/test/excludes/TestFixturesTest.rb +1 -0
- data/test/excludes/TransactionInstrumentationTest.rb +1 -0
- data/test/excludes/TransactionIsolationTest.rb +1 -0
- data/test/excludes/TypeTest.rb +1 -0
- data/test/excludes/UniquenessValidationTest.rb +2 -0
- data/test/excludes/UnloggedTablesTest.rb +3 -0
- data/test/excludes/UnsafeRawSqlTest.rb +2 -0
- data/test/excludes/UpdateableViewTest.rb +5 -0
- data/test/excludes/WithAnnotationsTest.rb +6 -0
- data/test/models/building.rb +4 -0
- data/test/models/spatial_model.rb +5 -0
- data/test/schema/cockroachdb_specific_schema.rb +218 -0
- data/test/support/copy_cat.rb +83 -0
- data/test/support/exclude_from_transactional_tests.rb +33 -0
- data/test/support/paths_cockroachdb.rb +46 -0
- data/test/support/rake_helpers.rb +37 -0
- data/test/support/sql_logger.rb +55 -0
- data/test/support/template_creator.rb +114 -0
- metadata +422 -34
- data/.editorconfig +0 -7
- data/.github/issue_template.md +0 -46
- data/.github/reproduction_scripts/migrations.rb +0 -60
- data/.github/reproduction_scripts/models_and_database.rb +0 -49
- data/.github/workflows/ci.yml +0 -96
- data/.github/workflows/docker.yml +0 -57
- data/.gitignore +0 -18
- data/.gitmodules +0 -0
- data/activerecord-cockroachdb-adapter.gemspec +0 -38
- data/bin/console +0 -36
- data/bin/console_schemas/default.rb +0 -11
- data/bin/console_schemas/schemas.rb +0 -23
- data/bin/setup +0 -8
- data/bin/start-cockroachdb +0 -33
- data/build/Dockerfile +0 -14
- data/build/config.teamcity.yml +0 -31
- data/build/local-test.sh +0 -32
- data/build/teamcity-test.sh +0 -76
- data/docker.sh +0 -35
- data/lib/active_record/connection_adapters/cockroachdb/spatial_column_info.rb +0 -60
- data/setup.sql +0 -18
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper_cockroachdb"
|
|
4
|
+
|
|
5
|
+
require "cases/helper"
|
|
6
|
+
require "support/schema_dumping_helper"
|
|
7
|
+
|
|
8
|
+
module CockroachDB
|
|
9
|
+
class SchemaDumperTest < ActiveRecord::TestCase
|
|
10
|
+
include SchemaDumpingHelper
|
|
11
|
+
self.use_transactional_tests = false
|
|
12
|
+
|
|
13
|
+
setup do
|
|
14
|
+
@schema_migration = ActiveRecord::Base.connection_pool.schema_migration
|
|
15
|
+
@schema_migration.create_table
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/347
|
|
19
|
+
def test_dump_index_rather_than_unique_constraints
|
|
20
|
+
ActiveRecord::Base.with_connection do |conn|
|
|
21
|
+
conn.create_table :payments, force: true do |t|
|
|
22
|
+
t.text "name"
|
|
23
|
+
t.integer "value"
|
|
24
|
+
t.unique_constraint ["name", "value"], name: "as_unique_constraint" # Will be ignored
|
|
25
|
+
t.index "lower(name::STRING) ASC", name: "simple_unique", unique: true
|
|
26
|
+
t.index "name", name: "unique_with_where", where: "name IS NOT NULL", unique: true
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
output = dump_table_schema("payments")
|
|
31
|
+
|
|
32
|
+
index_lines = output.each_line.select { _1[/simple_unique|unique_with_where|as_unique_constraint/] }
|
|
33
|
+
assert_equal 2, index_lines.size
|
|
34
|
+
index_lines.each do |line|
|
|
35
|
+
assert_match(/t.index/, line)
|
|
36
|
+
end
|
|
37
|
+
ensure
|
|
38
|
+
ActiveRecord::Base.with_connection { _1.drop_table :payments, if_exists: true }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_schema_dump_with_timestamptz_datetime_format
|
|
42
|
+
migration, original, $stdout = nil, $stdout, StringIO.new
|
|
43
|
+
|
|
44
|
+
with_cockroachdb_datetime_type(:timestamptz) do
|
|
45
|
+
migration = Class.new(ActiveRecord::Migration::Current) do
|
|
46
|
+
def up
|
|
47
|
+
create_table("timestamps") do |t|
|
|
48
|
+
t.datetime :this_should_remain_datetime
|
|
49
|
+
t.timestamptz :this_is_an_alias_of_datetime
|
|
50
|
+
t.column :without_time_zone, :timestamp
|
|
51
|
+
t.column :with_time_zone, :timestamptz
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
def down
|
|
55
|
+
drop_table("timestamps")
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
migration.migrate(:up)
|
|
59
|
+
|
|
60
|
+
output = dump_table_schema "timestamps"
|
|
61
|
+
|
|
62
|
+
assert output.include?('t.datetime "this_should_remain_datetime"')
|
|
63
|
+
assert output.include?('t.datetime "this_is_an_alias_of_datetime"')
|
|
64
|
+
assert output.include?('t.timestamp "without_time_zone"')
|
|
65
|
+
assert output.include?('t.datetime "with_time_zone"')
|
|
66
|
+
end
|
|
67
|
+
ensure
|
|
68
|
+
migration.migrate(:down)
|
|
69
|
+
$stdout = original
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_schema_dump_with_correct_timestamp_types_via_add_column_with_type_as_string
|
|
73
|
+
migration, original, $stdout = nil, $stdout, StringIO.new
|
|
74
|
+
|
|
75
|
+
with_cockroachdb_datetime_type(:timestamptz) do
|
|
76
|
+
migration = Class.new(ActiveRecord::Migration[6.1]) do
|
|
77
|
+
def up
|
|
78
|
+
create_table("timestamps")
|
|
79
|
+
|
|
80
|
+
add_column :timestamps, :this_should_change_to_timestamp, "datetime"
|
|
81
|
+
add_column :timestamps, :this_should_stay_as_timestamp, "timestamp"
|
|
82
|
+
end
|
|
83
|
+
def down
|
|
84
|
+
drop_table("timestamps")
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
migration.migrate(:up)
|
|
88
|
+
|
|
89
|
+
output = dump_table_schema "timestamps"
|
|
90
|
+
# Normally we'd write `t.datetime` here. But because you've changed the `datetime_type`
|
|
91
|
+
# to something else, `t.datetime` now means `:timestamptz`. To ensure that old columns
|
|
92
|
+
# are still created as a `:timestamp` we need to change what is written to the schema dump.
|
|
93
|
+
#
|
|
94
|
+
# Typically in Rails we handle this through Migration versioning (`ActiveRecord::Migration::Compatibility`)
|
|
95
|
+
# but that doesn't work here because the schema dumper is not aware of which migration
|
|
96
|
+
# a column was added in.
|
|
97
|
+
assert output.include?('t.timestamp "this_should_change_to_timestamp"')
|
|
98
|
+
assert output.include?('t.timestamp "this_should_stay_as_timestamp"')
|
|
99
|
+
end
|
|
100
|
+
ensure
|
|
101
|
+
migration.migrate(:down)
|
|
102
|
+
$stdout = original
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_timestamps_schema_dump_before_rails_7_with_timestamptz_setting
|
|
106
|
+
migration, original, $stdout = nil, $stdout, StringIO.new
|
|
107
|
+
|
|
108
|
+
with_cockroachdb_datetime_type(:timestamptz) do
|
|
109
|
+
migration = Class.new(ActiveRecord::Migration[6.1]) do
|
|
110
|
+
def up
|
|
111
|
+
create_table("timestamps") do |t|
|
|
112
|
+
t.datetime :this_should_change_to_timestamp
|
|
113
|
+
t.timestamp :this_should_stay_as_timestamp
|
|
114
|
+
t.column :this_should_also_stay_as_timestamp, :timestamp
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
def down
|
|
118
|
+
drop_table("timestamps")
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
migration.migrate(:up)
|
|
122
|
+
|
|
123
|
+
output = dump_table_schema "timestamps"
|
|
124
|
+
# Normally we'd write `t.datetime` here. But because you've changed the `datetime_type`
|
|
125
|
+
# to something else, `t.datetime` now means `:timestamptz`. To ensure that old columns
|
|
126
|
+
# are still created as a `:timestamp` we need to change what is written to the schema dump.
|
|
127
|
+
#
|
|
128
|
+
# Typically in Rails we handle this through Migration versioning (`ActiveRecord::Migration::Compatibility`)
|
|
129
|
+
# but that doesn't work here because the schema dumper is not aware of which migration
|
|
130
|
+
# a column was added in.
|
|
131
|
+
|
|
132
|
+
assert output.include?('t.timestamp "this_should_change_to_timestamp"')
|
|
133
|
+
assert output.include?('t.timestamp "this_should_stay_as_timestamp"')
|
|
134
|
+
assert output.include?('t.timestamp "this_should_also_stay_as_timestamp"')
|
|
135
|
+
end
|
|
136
|
+
ensure
|
|
137
|
+
migration.migrate(:down)
|
|
138
|
+
$stdout = original
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_schema_dump_with_correct_timestamp_types_via_add_column_before_rails_7_with_timestamptz_setting
|
|
142
|
+
migration, original, $stdout = nil, $stdout, StringIO.new
|
|
143
|
+
|
|
144
|
+
with_cockroachdb_datetime_type(:timestamptz) do
|
|
145
|
+
migration = Class.new(ActiveRecord::Migration[6.1]) do
|
|
146
|
+
def up
|
|
147
|
+
create_table("timestamps")
|
|
148
|
+
|
|
149
|
+
add_column :timestamps, :this_should_change_to_timestamp, :datetime
|
|
150
|
+
add_column :timestamps, :this_should_stay_as_timestamp, :timestamp
|
|
151
|
+
end
|
|
152
|
+
def down
|
|
153
|
+
drop_table("timestamps")
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
migration.migrate(:up)
|
|
157
|
+
|
|
158
|
+
output = dump_table_schema "timestamps"
|
|
159
|
+
# Normally we'd write `t.datetime` here. But because you've changed the `datetime_type`
|
|
160
|
+
# to something else, `t.datetime` now means `:timestamptz`. To ensure that old columns
|
|
161
|
+
# are still created as a `:timestamp` we need to change what is written to the schema dump.
|
|
162
|
+
#
|
|
163
|
+
# Typically in Rails we handle this through Migration versioning (`ActiveRecord::Migration::Compatibility`)
|
|
164
|
+
# but that doesn't work here because the schema dumper is not aware of which migration
|
|
165
|
+
# a column was added in.
|
|
166
|
+
|
|
167
|
+
assert output.include?('t.timestamp "this_should_change_to_timestamp"')
|
|
168
|
+
assert output.include?('t.timestamp "this_should_stay_as_timestamp"')
|
|
169
|
+
end
|
|
170
|
+
ensure
|
|
171
|
+
migration.migrate(:down)
|
|
172
|
+
$stdout = original
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_schema_dump_when_changing_datetime_type_for_an_existing_app
|
|
176
|
+
original, $stdout = $stdout, StringIO.new
|
|
177
|
+
|
|
178
|
+
migration = Class.new(ActiveRecord::Migration::Current) do
|
|
179
|
+
def up
|
|
180
|
+
create_table("timestamps") do |t|
|
|
181
|
+
t.datetime :default_format
|
|
182
|
+
t.column :without_time_zone, :timestamp
|
|
183
|
+
t.column :with_time_zone, :timestamptz
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
def down
|
|
187
|
+
drop_table("timestamps")
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
migration.migrate(:up)
|
|
191
|
+
|
|
192
|
+
output = dump_table_schema "timestamps"
|
|
193
|
+
assert output.include?('t.datetime "default_format"')
|
|
194
|
+
assert output.include?('t.datetime "without_time_zone"')
|
|
195
|
+
assert output.include?('t.timestamptz "with_time_zone"')
|
|
196
|
+
|
|
197
|
+
datetime_type_was = ActiveRecord::ConnectionAdapters::CockroachDBAdapter.datetime_type
|
|
198
|
+
ActiveRecord::ConnectionAdapters::CockroachDBAdapter.datetime_type = :timestamptz
|
|
199
|
+
|
|
200
|
+
output = dump_table_schema "timestamps"
|
|
201
|
+
assert output.include?('t.timestamp "default_format"')
|
|
202
|
+
assert output.include?('t.timestamp "without_time_zone"')
|
|
203
|
+
assert output.include?('t.datetime "with_time_zone"')
|
|
204
|
+
ensure
|
|
205
|
+
ActiveRecord::ConnectionAdapters::CockroachDBAdapter.datetime_type = datetime_type_was
|
|
206
|
+
migration.migrate(:down)
|
|
207
|
+
$stdout = original
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
if ActiveRecord::Base.lease_connection.supports_check_constraints?
|
|
211
|
+
def test_schema_dumps_check_constraints
|
|
212
|
+
constraint_definition = dump_table_schema("products").split(/\n/).grep(/t.check_constraint.*products_price_check/).first.strip
|
|
213
|
+
if current_adapter?(:Mysql2Adapter)
|
|
214
|
+
assert_equal 't.check_constraint "`price` > `discounted_price`", name: "products_price_check"', constraint_definition
|
|
215
|
+
else
|
|
216
|
+
assert_equal 't.check_constraint "(price > discounted_price)", name: "products_price_check"', constraint_definition
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper_cockroachdb"
|
|
4
|
+
require "models/post"
|
|
5
|
+
|
|
6
|
+
module CockroachDB
|
|
7
|
+
class ShowCreateTest < ActiveRecord::TestCase
|
|
8
|
+
fixtures :posts
|
|
9
|
+
|
|
10
|
+
def test_show_create
|
|
11
|
+
assert_match(/CREATE TABLE public\.posts/, Post.show_create)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper"
|
|
4
|
+
require "models/developer"
|
|
5
|
+
require "models/computer"
|
|
6
|
+
require "models/mentor"
|
|
7
|
+
require "models/project"
|
|
8
|
+
require "models/ship"
|
|
9
|
+
require "models/strict_zine"
|
|
10
|
+
require "models/interest"
|
|
11
|
+
|
|
12
|
+
module CockroachDB
|
|
13
|
+
class StrictLoadingFixturesTest < ActiveRecord::TestCase
|
|
14
|
+
# This test is identical to the ActiveRecord version except
|
|
15
|
+
# that transactional tests are disabled, so create_fixtures
|
|
16
|
+
# will work.
|
|
17
|
+
self.use_transactional_tests = false
|
|
18
|
+
|
|
19
|
+
fixtures :strict_zines
|
|
20
|
+
|
|
21
|
+
test "strict loading violations are ignored on fixtures" do
|
|
22
|
+
ActiveRecord::FixtureSet.reset_cache
|
|
23
|
+
create_fixtures("strict_zines")
|
|
24
|
+
|
|
25
|
+
assert_nothing_raised do
|
|
26
|
+
strict_zines(:going_out).interests.to_a
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
assert_raises(ActiveRecord::StrictLoadingViolationError) do
|
|
30
|
+
StrictZine.first.interests.to_a
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper"
|
|
4
|
+
require "active_record/tasks/database_tasks"
|
|
5
|
+
require "active_record/connection_adapters/cockroachdb/database_tasks"
|
|
6
|
+
|
|
7
|
+
module ActiveRecord
|
|
8
|
+
class CockroachDBStructureDumpTest < ActiveRecord::TestCase
|
|
9
|
+
def setup
|
|
10
|
+
@configuration = {
|
|
11
|
+
"adapter" => "cockroachdb",
|
|
12
|
+
"database" => "my-app-db"
|
|
13
|
+
}
|
|
14
|
+
@filename = "/tmp/awesome-file.sql"
|
|
15
|
+
FileUtils.touch(@filename)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def teardown
|
|
19
|
+
FileUtils.rm_f(@filename)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_structure_dump
|
|
23
|
+
assert_equal "", File.read(@filename)
|
|
24
|
+
File.write(@filename, "NOT TODAY\n")
|
|
25
|
+
|
|
26
|
+
config = @configuration.dup
|
|
27
|
+
config["database"] = ARTest.config["connections"]["cockroachdb"]["arunit"]["database"]
|
|
28
|
+
|
|
29
|
+
begin
|
|
30
|
+
ActiveRecord::Base.lease_connection.execute(<<~SQL)
|
|
31
|
+
CREATE TYPE IF NOT EXISTS status AS ENUM ('open', 'closed', 'inactive');
|
|
32
|
+
SQL
|
|
33
|
+
assert_called(
|
|
34
|
+
ActiveRecord::SchemaDumper,
|
|
35
|
+
:ignore_tables,
|
|
36
|
+
returns: ["accounts", "articles"]
|
|
37
|
+
) do
|
|
38
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump(config, @filename)
|
|
39
|
+
end
|
|
40
|
+
ensure
|
|
41
|
+
ActiveRecord::Base.lease_connection.execute(<<~SQL)
|
|
42
|
+
DROP TYPE IF EXISTS status;
|
|
43
|
+
SQL
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
read = File.read(@filename)
|
|
47
|
+
refute read.include?("NOT TODAY"), "The dump file previous content was not overwritten"
|
|
48
|
+
assert read.include?("CREATE SCHEMA public;"), "Schemas are not dumped"
|
|
49
|
+
assert read.include?("CREATE TYPE public.status AS ENUM ('open', 'closed', 'inactive');"), "Types are not dumped"
|
|
50
|
+
assert read.include?("CREATE TABLE public.schema_migrations"), "No dump done"
|
|
51
|
+
refute read.include?("CREATE TABLE public.articles ("), "\"articles\" table should be ignored"
|
|
52
|
+
refute read.include?("CREATE TABLE public.accounts ("), "\"accounts\" table should be ignored"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class CockroachDBStructureLoadTest < ActiveRecord::TestCase
|
|
57
|
+
def setup
|
|
58
|
+
@configuration = {
|
|
59
|
+
adapter: "cockroachdb",
|
|
60
|
+
database: "my-app-db",
|
|
61
|
+
host: "localhost"
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_structure_load
|
|
66
|
+
filename = "awesome-file.sql"
|
|
67
|
+
assert_called_with(
|
|
68
|
+
Kernel,
|
|
69
|
+
:system,
|
|
70
|
+
[
|
|
71
|
+
{"COCKROACH_INSECURE"=>"true", "COCKROACH_URL"=>"postgres://localhost/my-app-db"},
|
|
72
|
+
"cockroach", "sql", "--set", "errexit=false", "--file", filename
|
|
73
|
+
],
|
|
74
|
+
returns: true
|
|
75
|
+
) do
|
|
76
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_url_generation
|
|
81
|
+
assert_correct_url @configuration.merge(
|
|
82
|
+
%i(sslmode sslrootcert sslcert sslkey).to_h { [_1, "v#{_1}"] }
|
|
83
|
+
), "postgres://localhost/my-app-db?sslmode=vsslmode&sslrootcert=vsslrootcert&sslcert=vsslcert&sslkey=vsslkey"
|
|
84
|
+
assert_correct_url @configuration.merge({
|
|
85
|
+
username: "root",
|
|
86
|
+
port: 1234
|
|
87
|
+
}), "postgres://root@localhost:1234/my-app-db"
|
|
88
|
+
assert_correct_url @configuration.merge({
|
|
89
|
+
username: "root",
|
|
90
|
+
password: "secret"
|
|
91
|
+
}), "postgres://root:secret@localhost/my-app-db"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
private
|
|
95
|
+
|
|
96
|
+
# Verify that given a config we generate the expected connection URL,
|
|
97
|
+
# and that if we parse it again, we get the same config. Except the
|
|
98
|
+
# `adapter` key, that'll changed to postgresql as the url given to
|
|
99
|
+
# `cockroach sql` must start with the `postrges://` scheme.
|
|
100
|
+
def assert_correct_url(config, expected_url)
|
|
101
|
+
db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new("default_env", "primary", config)
|
|
102
|
+
task_chief = ActiveRecord::ConnectionAdapters::CockroachDB::DatabaseTasks.new(db_config)
|
|
103
|
+
generated_url = task_chief.send(:cockroach_env)["COCKROACH_URL"]
|
|
104
|
+
|
|
105
|
+
conf_from_generated_url = ActiveRecord::Base.
|
|
106
|
+
configurations.
|
|
107
|
+
resolve(generated_url).
|
|
108
|
+
configuration_hash
|
|
109
|
+
assert_equal expected_url, generated_url
|
|
110
|
+
assert_equal config.except(:adapter), conf_from_generated_url.except(:adapter)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper"
|
|
4
|
+
require "tempfile"
|
|
5
|
+
require "fileutils"
|
|
6
|
+
require "models/zine"
|
|
7
|
+
module CockroachDB
|
|
8
|
+
class TestFixturesTest < ActiveRecord::TestCase
|
|
9
|
+
setup do
|
|
10
|
+
@klass = Class.new
|
|
11
|
+
@klass.include(ActiveRecord::TestFixtures)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# This is identical to the Rails version, except that we set
|
|
15
|
+
# use_transactional_tests to false. This is necessary because otherwise
|
|
16
|
+
# the fixtures are created inside of a transaction, which causes a
|
|
17
|
+
# DuplicateKey error and ultimately an InFailedSqlTransaction error.
|
|
18
|
+
# Setting transactional tests to false allows the schema to update so that
|
|
19
|
+
# we do not have an erroneous DuplicateKey error when re-creating the
|
|
20
|
+
# foreign keys.
|
|
21
|
+
self.use_transactional_tests = false
|
|
22
|
+
|
|
23
|
+
unless in_memory_db?
|
|
24
|
+
def test_doesnt_rely_on_active_support_test_case_specific_methods
|
|
25
|
+
tmp_dir = Dir.mktmpdir
|
|
26
|
+
File.write(File.join(tmp_dir, "zines.yml"), <<~YML)
|
|
27
|
+
going_out:
|
|
28
|
+
title: Hello
|
|
29
|
+
YML
|
|
30
|
+
|
|
31
|
+
klass = Class.new(Minitest::Test) do
|
|
32
|
+
include ActiveRecord::TestFixtures
|
|
33
|
+
|
|
34
|
+
self.fixture_paths = [tmp_dir]
|
|
35
|
+
|
|
36
|
+
fixtures :all
|
|
37
|
+
|
|
38
|
+
def test_run_successfully
|
|
39
|
+
assert_equal("Hello", Zine.first.title)
|
|
40
|
+
assert_equal("Hello", zines(:going_out).title)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
old_handler = ActiveRecord::Base.connection_handler
|
|
45
|
+
ActiveRecord::Base.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
|
46
|
+
ActiveRecord::Base.establish_connection(:arunit)
|
|
47
|
+
|
|
48
|
+
test_result = klass.new("test_run_successfully").run
|
|
49
|
+
assert_predicate(test_result, :passed?)
|
|
50
|
+
ensure
|
|
51
|
+
ActiveRecord::Base.connection_handler = old_handler
|
|
52
|
+
clean_up_connection_handler
|
|
53
|
+
FileUtils.rm_r(tmp_dir)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper_cockroachdb"
|
|
4
|
+
|
|
5
|
+
module CockroachDB
|
|
6
|
+
class TransactionsTest < ActiveRecord::TestCase
|
|
7
|
+
self.use_transactional_tests = false
|
|
8
|
+
|
|
9
|
+
class Avenger < ActiveRecord::Base
|
|
10
|
+
singleton_class.attr_accessor :cyclic_barrier
|
|
11
|
+
|
|
12
|
+
validate :validate_unique_username
|
|
13
|
+
|
|
14
|
+
def validate_unique_username
|
|
15
|
+
self.class.cyclic_barrier.wait
|
|
16
|
+
duplicate = self.class.where(name: name).any?
|
|
17
|
+
errors.add("Duplicate username!") if duplicate
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def setup
|
|
22
|
+
@conn = ActiveRecord::Base.lease_connection
|
|
23
|
+
@conn.create_table :avengers, force: true do |t|
|
|
24
|
+
t.string :name
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def teardown
|
|
29
|
+
@conn.drop_table :avengers, if_exists: true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_concurrent_insert_with_processes # corrupting #1
|
|
33
|
+
avengers = %w[Hulk Thor Loki]
|
|
34
|
+
Avenger.cyclic_barrier = Concurrent::CyclicBarrier.new(avengers.size - 1)
|
|
35
|
+
Thread.current[:name] = "Main" # For debug logs.
|
|
36
|
+
|
|
37
|
+
assert_queries_match(/ROLLBACK/) do # Ensure we are properly testing the retry mechanism.
|
|
38
|
+
avengers.map do |name|
|
|
39
|
+
Thread.fork do
|
|
40
|
+
Thread.current[:name] = name # For debug logs.
|
|
41
|
+
Avenger.create!(name: name)
|
|
42
|
+
end
|
|
43
|
+
end.each(&:join)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
assert_equal avengers.size, Avenger.count
|
|
47
|
+
ensure
|
|
48
|
+
Thread.current[:name] = nil
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper_cockroachdb"
|
|
4
|
+
require "models/post"
|
|
5
|
+
require "models/comment"
|
|
6
|
+
|
|
7
|
+
module CockroachDB
|
|
8
|
+
class UnsafeRawSqlTest < ActiveRecord::TestCase
|
|
9
|
+
fixtures :posts, :comments
|
|
10
|
+
|
|
11
|
+
# OVERRIDE: We use the PostgreSQL `collation_name` for our adapter.
|
|
12
|
+
test "order: allows valid arguments with COLLATE" do
|
|
13
|
+
collation_name = "C" # <- Here is the overriden part.
|
|
14
|
+
|
|
15
|
+
ids_expected = Post.order(Arel.sql(%Q'author_id, title COLLATE "#{collation_name}" DESC')).pluck(:id)
|
|
16
|
+
|
|
17
|
+
ids = Post.order(["author_id", %Q'title COLLATE "#{collation_name}" DESC']).pluck(:id)
|
|
18
|
+
|
|
19
|
+
assert_equal ids_expected, ids
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/test/config.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
default_connection: cockroachdb
|
|
2
|
+
connections:
|
|
3
|
+
cockroachdb:
|
|
4
|
+
arunit: &arunit
|
|
5
|
+
min_messages: warning
|
|
6
|
+
host: 127.0.0.1
|
|
7
|
+
port: 26257
|
|
8
|
+
user: root
|
|
9
|
+
disable_cockroachdb_telemetry: true
|
|
10
|
+
# `autocommit_before_ddl` changed to default true in CockroachDB v25.1.
|
|
11
|
+
# This does not work with active record's test suite.
|
|
12
|
+
#
|
|
13
|
+
# This options keyword is referenced here in libpq:
|
|
14
|
+
# https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-OPTIONS
|
|
15
|
+
#
|
|
16
|
+
# NOTE: with command lines or a URI, one could use `-c autocommit_before_ddl=false`
|
|
17
|
+
variables:
|
|
18
|
+
autocommit_before_ddl: false
|
|
19
|
+
arunit_without_prepared_statements:
|
|
20
|
+
<<: *arunit
|
|
21
|
+
prepared_statements: false
|
|
22
|
+
arunit2:
|
|
23
|
+
<<: *arunit
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
exclude :test_indexes, "Rails transactional tests are being used while making schema changes. See https://www.cockroachlabs.com/docs/stable/online-schema-changes.html#limited-support-for-schema-changes-within-transactions."
|
|
2
|
+
exclude :test_remove_index_when_name_and_wrong_column_name_specified, "Rails transactional tests are being used while making schema changes. See https://www.cockroachlabs.com/docs/stable/online-schema-changes.html#limited-support-for-schema-changes-within-transactions."
|
|
3
|
+
exclude :test_remove_index_when_name_and_wrong_column_name_specified_positional_argument, "Rails transactional tests are being used while making schema changes. See https://www.cockroachlabs.com/docs/stable/online-schema-changes.html#limited-support-for-schema-changes-within-transactions."
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
exclude :test_reset_empty_table_with_custom_pk, "The test fails because serial primary keys in CockroachDB are created with unique_rowid() where PostgreSQL will create them with a sequence. See https://www.cockroachlabs.com/docs/v19.2/serial.html#modes-of-operation"
|
|
2
|
+
|
|
3
|
+
require "support/copy_cat"
|
|
4
|
+
|
|
5
|
+
# This fixes a bug where our `TestRetryHelper` logic combined
|
|
6
|
+
# with `reset_fixtures` trying to reset a table without foreign
|
|
7
|
+
# keys from another table.
|
|
8
|
+
# It would first crash, removing the foreign key constraint (due
|
|
9
|
+
# to how we handle `disable_referential_integrity`). And then pass,
|
|
10
|
+
# since the foreign key constraint is gone. But we need that
|
|
11
|
+
# constraint in later tests.
|
|
12
|
+
#
|
|
13
|
+
# From:
|
|
14
|
+
# fixture_names.each do |fixture_name|
|
|
15
|
+
# ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, fixture_name)
|
|
16
|
+
# end
|
|
17
|
+
# To:
|
|
18
|
+
# ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, fixture_names)
|
|
19
|
+
CopyCat.copy_methods(self, self, :reset_fixtures) do
|
|
20
|
+
def on_block(node)
|
|
21
|
+
return unless node in [:block, [:send, [:lvar, :fixture_names], :each], *]
|
|
22
|
+
|
|
23
|
+
replace(node.loc.expression, "ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, fixture_names)")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exclude :test_url_invalid_adapter, "rewritten to include cockroachdb in test"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "support/copy_cat"
|
|
2
|
+
|
|
3
|
+
# CockroachDB quotes numbers as strings.
|
|
4
|
+
CopyCat.copy_methods(self, self,
|
|
5
|
+
:test_where_with_float_for_string_column_using_bind_parameters,
|
|
6
|
+
:test_where_with_decimal_for_string_column_using_bind_parameters,
|
|
7
|
+
:test_where_with_rational_for_string_column_using_bind_parameters,
|
|
8
|
+
:test_where_with_integer_for_string_column_using_bind_parameters) do
|
|
9
|
+
def on_str(node)
|
|
10
|
+
str = node.children[0]
|
|
11
|
+
return unless ["0.0", "0", "0/1"].include?(str)
|
|
12
|
+
|
|
13
|
+
replace(node.loc.expression, "'#{str}'".inspect)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
comment = "This adapter quotes integers as string, as CRDB is capable of " \
|
|
2
|
+
"implicitely converting, and checking for out of bound errors. " \
|
|
3
|
+
"See quoting.rb for more information."
|
|
4
|
+
exclude :test_do_not_raise_when_int_is_not_wider_than_64bit, comment
|
|
5
|
+
exclude :test_do_not_raise_when_raise_int_wider_than_64bit_is_false, comment
|
|
6
|
+
exclude :test_raise_when_int_is_wider_than_64bit, comment
|
|
7
|
+
|
|
8
|
+
require "support/copy_cat"
|
|
9
|
+
|
|
10
|
+
CopyCat.copy_methods(self, self,
|
|
11
|
+
:test_quote_big_decimal,
|
|
12
|
+
:test_quote_rational,
|
|
13
|
+
:test_quote_integer) do
|
|
14
|
+
def on_str(node)
|
|
15
|
+
return if defined?(@already_quoted)
|
|
16
|
+
@already_quoted = true
|
|
17
|
+
node => [:str, str]
|
|
18
|
+
return unless ["4.2", "3/4", "42"].include?(str)
|
|
19
|
+
|
|
20
|
+
replace(node.loc.expression, "'#{str}'".inspect)
|
|
21
|
+
end
|
|
22
|
+
end
|
data/test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapterPreventWritesLegacyTest.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exclude :test_doesnt_error_when_a_read_query_with_cursors_is_called_while_preventing_writes, "CockroachDB does not currently support declaring a cursor. See https://github.com/cockroachdb/cockroach/issues/41412."
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exclude :test_doesnt_error_when_a_read_query_with_cursors_is_called_while_preventing_writes, "CockroachDB does not currently support declaring a cursor. See https://github.com/cockroachdb/cockroach/issues/41412."
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
exclude :test_exec_insert_with_returning_disabled_and_no_sequence_name_given, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
2
|
+
exclude :test_default_sequence_name, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
3
|
+
exclude :test_bad_connection, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
4
|
+
exclude :test_exec_insert_with_returning_disabled, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
5
|
+
exclude :test_only_warn_on_first_encounter_of_unrecognized_oid, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
6
|
+
exclude :test_index_with_opclass, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
7
|
+
exclude :test_exec_insert_default_values_with_returning_disabled_and_no_sequence_name_given, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
8
|
+
exclude :test_reload_type_map_for_newly_defined_types, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
9
|
+
exclude :test_unparsed_defaults_are_at_least_set_when_saving, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
10
|
+
exclude :test_default_sequence_name_bad_table, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
11
|
+
exclude :test_exec_insert_default_values_quoted_schema_with_returning_disabled_and_no_sequence_name_given, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
12
|
+
exclude :test_expression_index, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
13
|
+
exclude :test_serial_sequence, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
|
|
14
|
+
exclude :test_database_exists_returns_false_when_the_database_does_not_exist, "Test is reimplemented to use cockroachdb adapter. Still not working in CI, skip until we can triage further"
|
|
15
|
+
exclude :test_database_exists_returns_true_when_the_database_exists, "Test is reimplemented to use cockroachdb adapter"
|
|
16
|
+
exclude :test_invalid_index, "The error message differs from PostgreSQL."
|
|
17
|
+
exclude :test_partial_index_on_column_named_like_keyword, "CockroachDB adds parentheses around the WHERE definition."
|
|
18
|
+
exclude :test_only_check_for_insensitive_comparison_capability_once, "the DROP DOMAIN syntax is not supported by CRDB"
|
|
19
|
+
|
|
20
|
+
exclude :test_pk_and_sequence_for, "The test needs a little rework since the sequence is empty in CRDB"
|
|
21
|
+
exclude :test_pk_and_sequence_for_with_non_standard_primary_key, "The test needs a little rework since the sequence is empty in CRDB"
|
|
22
|
+
|
|
23
|
+
exclude :test_pk_and_sequence_for_with_collision_pg_class_oid, "We cannot DELETE on relation pg_depend in CockroachDB. Skipped for now"
|
|
24
|
+
|
|
25
|
+
# NOTE: The expression `do $$ BEGIN RAISE WARNING 'foo'; END; $$` works with PG, not CRDB.
|
|
26
|
+
plpgsql_needed = "PL-PGSQL differs in CockroachDB. Not tested yet. See #339"
|
|
27
|
+
exclude :test_ignores_warnings_when_behavior_ignore, plpgsql_needed
|
|
28
|
+
exclude :test_logs_warnings_when_behavior_log, plpgsql_needed
|
|
29
|
+
exclude :test_raises_warnings_when_behavior_raise, plpgsql_needed
|
|
30
|
+
exclude :test_reports_when_behavior_report, plpgsql_needed
|
|
31
|
+
exclude :test_warnings_behavior_can_be_customized_with_a_proc, plpgsql_needed
|
|
32
|
+
exclude :test_allowlist_of_warnings_to_ignore, plpgsql_needed
|
|
33
|
+
exclude :test_allowlist_of_warning_codes_to_ignore, plpgsql_needed
|
|
34
|
+
|
|
35
|
+
exclude :test_translate_no_connection_exception_to_not_established, "CRDB doesn't implement pg_terminate_backend()"
|
|
36
|
+
|
|
37
|
+
exclude :test_disable_extension_without_schema, ExcludeMessage::NO_HSTORE
|
|
38
|
+
exclude :test_extensions_omits_current_schema_name, ExcludeMessage::NO_HSTORE
|
|
39
|
+
exclude :test_extensions_includes_non_current_schema_name, ExcludeMessage::NO_HSTORE
|
|
40
|
+
exclude :test_disable_extension_with_schema, ExcludeMessage::NO_HSTORE
|