activerecord-cockroachdb-adapter 8.0.3 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/CONTRIBUTING.md +10 -17
- data/Gemfile +2 -1
- data/Rakefile +0 -19
- data/lib/active_record/connection_adapters/cockroachdb/column.rb +69 -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 +137 -51
- data/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb +181 -102
- data/lib/active_record/connection_adapters/cockroachdb_adapter.rb +78 -34
- data/lib/version.rb +1 -1
- data/test/cases/adapter_test.rb +98 -0
- data/test/cases/adapters/cockroachdb/cached_plan_failure_test.rb +106 -0
- data/test/cases/adapters/cockroachdb/referential_integrity_test.rb +91 -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 +199 -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/QueryCacheExpiryTest.rb +10 -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 -30
- 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,111 @@
|
|
|
1
|
+
# This test has been copied to fix a bug in the test setup. It can be removed
|
|
2
|
+
# once the bug has been fixed and released in Rails.
|
|
3
|
+
# See test/excludes/EagerLoadPolyAssocsTest.rb
|
|
4
|
+
|
|
5
|
+
require "cases/helper_cockroachdb"
|
|
6
|
+
|
|
7
|
+
# Load dependencies from ActiveRecord test suite
|
|
8
|
+
require "models/post"
|
|
9
|
+
require "models/tag"
|
|
10
|
+
require "models/author"
|
|
11
|
+
require "models/comment"
|
|
12
|
+
require "models/category"
|
|
13
|
+
require "models/categorization"
|
|
14
|
+
require "models/tagging"
|
|
15
|
+
|
|
16
|
+
module CockroachDB
|
|
17
|
+
module Remembered
|
|
18
|
+
extend ActiveSupport::Concern
|
|
19
|
+
|
|
20
|
+
included do
|
|
21
|
+
after_create :remember
|
|
22
|
+
private
|
|
23
|
+
def remember; self.class.remembered << self; end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module ClassMethods
|
|
27
|
+
# The test setup bug is fixed here. @@remembered was being shared by every
|
|
28
|
+
# class that included the Remembered module. Instead, we can use
|
|
29
|
+
# @remembered which will be unique to each included class.
|
|
30
|
+
def remembered; @remembered ||= []; end
|
|
31
|
+
def sample; remembered.sample; end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class ShapeExpression < ActiveRecord::Base
|
|
36
|
+
belongs_to :shape, polymorphic: true
|
|
37
|
+
belongs_to :paint, polymorphic: true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class Circle < ActiveRecord::Base
|
|
41
|
+
has_many :shape_expressions, as: :shape
|
|
42
|
+
include Remembered
|
|
43
|
+
end
|
|
44
|
+
class Square < ActiveRecord::Base
|
|
45
|
+
has_many :shape_expressions, as: :shape
|
|
46
|
+
include Remembered
|
|
47
|
+
end
|
|
48
|
+
class Triangle < ActiveRecord::Base
|
|
49
|
+
has_many :shape_expressions, as: :shape
|
|
50
|
+
include Remembered
|
|
51
|
+
end
|
|
52
|
+
class PaintColor < ActiveRecord::Base
|
|
53
|
+
has_many :shape_expressions, as: :paint
|
|
54
|
+
belongs_to :non_poly, foreign_key: "non_poly_one_id", class_name: "NonPolyOne"
|
|
55
|
+
include Remembered
|
|
56
|
+
end
|
|
57
|
+
class PaintTexture < ActiveRecord::Base
|
|
58
|
+
has_many :shape_expressions, as: :paint
|
|
59
|
+
belongs_to :non_poly, foreign_key: "non_poly_two_id", class_name: "NonPolyTwo"
|
|
60
|
+
include Remembered
|
|
61
|
+
end
|
|
62
|
+
class NonPolyOne < ActiveRecord::Base
|
|
63
|
+
has_many :paint_colors
|
|
64
|
+
include Remembered
|
|
65
|
+
end
|
|
66
|
+
class NonPolyTwo < ActiveRecord::Base
|
|
67
|
+
has_many :paint_textures
|
|
68
|
+
include Remembered
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
class EagerLoadPolyAssocsTest < ActiveRecord::TestCase
|
|
72
|
+
NUM_SIMPLE_OBJS = 50
|
|
73
|
+
NUM_SHAPE_EXPRESSIONS = 100
|
|
74
|
+
|
|
75
|
+
def setup
|
|
76
|
+
generate_test_object_graphs
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
teardown do
|
|
80
|
+
[Circle, Square, Triangle, PaintColor, PaintTexture,
|
|
81
|
+
ShapeExpression, NonPolyOne, NonPolyTwo].each(&:delete_all)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def generate_test_object_graphs
|
|
85
|
+
1.upto(NUM_SIMPLE_OBJS) do
|
|
86
|
+
[Circle, Square, Triangle, NonPolyOne, NonPolyTwo].map(&:create!)
|
|
87
|
+
end
|
|
88
|
+
1.upto(NUM_SIMPLE_OBJS) do
|
|
89
|
+
PaintColor.create!(non_poly_one_id: NonPolyOne.sample.id)
|
|
90
|
+
PaintTexture.create!(non_poly_two_id: NonPolyTwo.sample.id)
|
|
91
|
+
end
|
|
92
|
+
1.upto(NUM_SHAPE_EXPRESSIONS) do
|
|
93
|
+
shape_type = [Circle, Square, Triangle].sample
|
|
94
|
+
paint_type = [PaintColor, PaintTexture].sample
|
|
95
|
+
ShapeExpression.create!(shape_type: shape_type.to_s, shape_id: shape_type.sample.id,
|
|
96
|
+
paint_type: paint_type.to_s, paint_id: paint_type.sample.id)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_include_query
|
|
101
|
+
res = ShapeExpression.all.merge!(includes: [ :shape, { paint: :non_poly } ]).to_a
|
|
102
|
+
assert_equal NUM_SHAPE_EXPRESSIONS, res.size
|
|
103
|
+
assert_queries_count(0) do
|
|
104
|
+
res.each do |se|
|
|
105
|
+
assert_not_nil se.paint.non_poly, "this is the association that was loading incorrectly before the change"
|
|
106
|
+
assert_not_nil se.shape, "just making sure other associations still work"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require "cases/helper_cockroachdb"
|
|
2
|
+
|
|
3
|
+
# Load dependencies from ActiveRecord test suite
|
|
4
|
+
require "models/post"
|
|
5
|
+
require "models/author"
|
|
6
|
+
|
|
7
|
+
module CockroachDB
|
|
8
|
+
class LeftOuterJoinAssociationTest < ActiveRecord::TestCase
|
|
9
|
+
fixtures :author_addresses, :authors, :posts
|
|
10
|
+
|
|
11
|
+
# This replaces the same test that's been excluded from
|
|
12
|
+
# LeftOuterJoinAssociationTest. The query has been updated to guarantee the
|
|
13
|
+
# result order.
|
|
14
|
+
# See test/excludes/LeftOuterJoinAssociationTest.rb
|
|
15
|
+
def test_construct_finder_sql_applies_aliases_tables_on_association_conditions
|
|
16
|
+
result = Author.left_outer_joins(:thinking_posts, :welcome_posts).order(:id).to_a
|
|
17
|
+
assert_equal authors(:david), result.first
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# This replaces the same test that's been excluded from
|
|
21
|
+
# LeftOuterJoinAssociationTest. The select query has been updated so the
|
|
22
|
+
# integer columns are casted to strings for concatenation.
|
|
23
|
+
# See test/excludes/LeftOuterJoinAssociationTest.rb
|
|
24
|
+
def test_does_not_override_select
|
|
25
|
+
authors = Author.select("authors.name, #{%{(authors.author_address_id::STRING || ' ' || authors.author_address_extra_id::STRING) as addr_id}}").left_outer_joins(:posts)
|
|
26
|
+
assert_predicate authors, :any?
|
|
27
|
+
assert_respond_to authors.first, :addr_id
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require "cases/helper_cockroachdb"
|
|
2
|
+
|
|
3
|
+
require "support/connection_helper"
|
|
4
|
+
|
|
5
|
+
require "models/bird"
|
|
6
|
+
require "models/parrot"
|
|
7
|
+
require "models/pirate"
|
|
8
|
+
require "models/price_estimate"
|
|
9
|
+
require "models/ship"
|
|
10
|
+
require "models/treasure"
|
|
11
|
+
|
|
12
|
+
module CockroachDB
|
|
13
|
+
class WithAnnotationsTest < ActiveRecord::TestCase
|
|
14
|
+
self.use_transactional_tests = false
|
|
15
|
+
|
|
16
|
+
fixtures :pirates, :treasures, :parrots
|
|
17
|
+
|
|
18
|
+
def test_belongs_to_with_annotation_includes_a_query_comment
|
|
19
|
+
pirate = SpacePirate.where.not(parrot_id: nil).first
|
|
20
|
+
assert pirate, "should have a Pirate record"
|
|
21
|
+
|
|
22
|
+
log = capture_sql do
|
|
23
|
+
pirate.parrot
|
|
24
|
+
end
|
|
25
|
+
assert_not_predicate log, :empty?
|
|
26
|
+
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?
|
|
27
|
+
|
|
28
|
+
assert_queries_match(%r{/\* that tells jokes \*/}) do
|
|
29
|
+
pirate.parrot_with_annotation
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_has_and_belongs_to_many_with_annotation_includes_a_query_comment
|
|
34
|
+
pirate = SpacePirate.first
|
|
35
|
+
assert pirate, "should have a Pirate record"
|
|
36
|
+
|
|
37
|
+
log = capture_sql do
|
|
38
|
+
pirate.parrots.first
|
|
39
|
+
end
|
|
40
|
+
assert_not_predicate log, :empty?
|
|
41
|
+
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?
|
|
42
|
+
|
|
43
|
+
assert_queries_match(%r{/\* that are very colorful \*/}) do
|
|
44
|
+
pirate.parrots_with_annotation.first
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_has_one_with_annotation_includes_a_query_comment
|
|
49
|
+
pirate = SpacePirate.first
|
|
50
|
+
assert pirate, "should have a Pirate record"
|
|
51
|
+
|
|
52
|
+
log = capture_sql do
|
|
53
|
+
pirate.ship
|
|
54
|
+
end
|
|
55
|
+
assert_not_predicate log, :empty?
|
|
56
|
+
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?
|
|
57
|
+
|
|
58
|
+
assert_queries_match(%r{/\* that is a rocket \*/}) do
|
|
59
|
+
pirate.ship_with_annotation
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_has_many_with_annotation_includes_a_query_comment
|
|
64
|
+
pirate = SpacePirate.first
|
|
65
|
+
assert pirate, "should have a Pirate record"
|
|
66
|
+
|
|
67
|
+
log = capture_sql do
|
|
68
|
+
pirate.birds.first
|
|
69
|
+
end
|
|
70
|
+
assert_not_predicate log, :empty?
|
|
71
|
+
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?
|
|
72
|
+
|
|
73
|
+
assert_queries_match(%r{/\* that are also parrots \*/}) do
|
|
74
|
+
pirate.birds_with_annotation.first
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_has_many_through_with_annotation_includes_a_query_comment
|
|
79
|
+
pirate = SpacePirate.first
|
|
80
|
+
assert pirate, "should have a Pirate record"
|
|
81
|
+
|
|
82
|
+
log = capture_sql do
|
|
83
|
+
pirate.treasure_estimates.first
|
|
84
|
+
end
|
|
85
|
+
assert_not_predicate log, :empty?
|
|
86
|
+
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?
|
|
87
|
+
|
|
88
|
+
assert_queries_match(%r{/\* yarrr \*/}) do
|
|
89
|
+
pirate.treasure_estimates_with_annotation.first
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_has_many_through_with_annotation_includes_a_query_comment_when_eager_loading
|
|
94
|
+
pirate = SpacePirate.first
|
|
95
|
+
assert pirate, "should have a Pirate record"
|
|
96
|
+
|
|
97
|
+
log = capture_sql do
|
|
98
|
+
pirate.treasure_estimates.first
|
|
99
|
+
end
|
|
100
|
+
assert_not_predicate log, :empty?
|
|
101
|
+
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?
|
|
102
|
+
|
|
103
|
+
assert_queries_match(%r{/\* yarrr \*/}) do
|
|
104
|
+
SpacePirate.includes(:treasure_estimates_with_annotation, :treasures).first
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "cases/helper_cockroachdb"
|
|
2
|
+
|
|
3
|
+
module CockroachDB
|
|
4
|
+
class BasicsTest < ActiveRecord::TestCase
|
|
5
|
+
# This replaces the same test that's been excluded from BasicsTest. It's
|
|
6
|
+
# exactly the same, except badchar has an entry for CockroachDBAdapter.
|
|
7
|
+
def test_column_names_are_escaped
|
|
8
|
+
conn = ActiveRecord::Base.lease_connection
|
|
9
|
+
classname = conn.class.name[/[^:]*$/]
|
|
10
|
+
badchar = {
|
|
11
|
+
"SQLite3Adapter" => '"',
|
|
12
|
+
"Mysql2Adapter" => "`",
|
|
13
|
+
"PostgreSQLAdapter" => '"',
|
|
14
|
+
"OracleAdapter" => '"',
|
|
15
|
+
"FbAdapter" => '"',
|
|
16
|
+
"CockroachDBAdapter" => '"'
|
|
17
|
+
}.fetch(classname) {
|
|
18
|
+
raise "need a bad char for #{classname}"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
quoted = conn.quote_column_name "foo#{badchar}bar"
|
|
22
|
+
if current_adapter?(:OracleAdapter)
|
|
23
|
+
# Oracle does not allow double quotes in table and column names at all
|
|
24
|
+
# therefore quoting removes them
|
|
25
|
+
assert_equal("#{badchar}foobar#{badchar}", quoted)
|
|
26
|
+
else
|
|
27
|
+
assert_equal("#{badchar}foo#{badchar * 2}bar#{badchar}", quoted)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper"
|
|
4
|
+
require "support/schema_dumping_helper"
|
|
5
|
+
|
|
6
|
+
# Copy of comment_test from ActiveRecord with all but two tests removed.
|
|
7
|
+
# We can get these tests to pass by enabling an experimental feature in
|
|
8
|
+
# setup, so we exclude them from the AR test cases and run them here.
|
|
9
|
+
if ActiveRecord::Base.lease_connection.supports_comments?
|
|
10
|
+
module CockroachDB
|
|
11
|
+
class CommentTest < ActiveRecord::TestCase
|
|
12
|
+
include SchemaDumpingHelper
|
|
13
|
+
|
|
14
|
+
self.use_transactional_tests = false
|
|
15
|
+
|
|
16
|
+
class Commented < ActiveRecord::Base
|
|
17
|
+
self.table_name = "commenteds"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
setup do
|
|
21
|
+
@connection = ActiveRecord::Base.lease_connection
|
|
22
|
+
|
|
23
|
+
@connection.create_table("commenteds", comment: "A table with comment", force: true) do |t|
|
|
24
|
+
t.string "name", comment: "Comment should help clarify the column purpose"
|
|
25
|
+
t.boolean "obvious", comment: "Question is: should you comment obviously named objects?"
|
|
26
|
+
t.string "content"
|
|
27
|
+
t.index "name", comment: %Q["Very important" index that powers all the performance.\nAnd it's fun!]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Commented.reset_column_information
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
teardown do
|
|
34
|
+
@connection.drop_table "commenteds", if_exists: true
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# This test is modified from the original
|
|
38
|
+
# The original changes the column type from a boolean to a string,
|
|
39
|
+
# but once this happens, comment changes don't work, so I'm not altering
|
|
40
|
+
# the type here.
|
|
41
|
+
def test_remove_comment_from_column
|
|
42
|
+
@connection.change_column :commenteds, :obvious, :boolean, comment: nil
|
|
43
|
+
|
|
44
|
+
Commented.reset_column_information
|
|
45
|
+
column = Commented.columns_hash["obvious"]
|
|
46
|
+
|
|
47
|
+
assert_equal :boolean, column.type
|
|
48
|
+
assert_nil column.comment
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_schema_dump_with_comments
|
|
52
|
+
# Do all the stuff from other tests
|
|
53
|
+
@connection.add_column :commenteds, :rating, :integer, comment: "I am running out of imagination"
|
|
54
|
+
@connection.change_column :commenteds, :content, :string, comment: "Whoa, content describes itself!"
|
|
55
|
+
@connection.change_column :commenteds, :content, :string
|
|
56
|
+
@connection.change_column :commenteds, :obvious, :boolean, comment: nil
|
|
57
|
+
@connection.add_index :commenteds, :obvious, name: "idx_obvious", comment: "We need to see obvious comments"
|
|
58
|
+
|
|
59
|
+
# And check that these changes are reflected in dump
|
|
60
|
+
output = dump_table_schema "commenteds"
|
|
61
|
+
assert_match %r[create_table "commenteds",.*\s+comment: "A table with comment"], output
|
|
62
|
+
assert_match %r[t\.string\s+"name",\s+comment: "Comment should help clarify the column purpose"], output
|
|
63
|
+
assert_match %r[t\.boolean\s+"obvious"\n], output
|
|
64
|
+
assert_match %r[t\.string\s+"content",\s+comment: "Whoa, content describes itself!"], output
|
|
65
|
+
if current_adapter?(:OracleAdapter)
|
|
66
|
+
assert_match %r[t\.integer\s+"rating",\s+precision: 38,\s+comment: "I am running out of imagination"], output
|
|
67
|
+
else
|
|
68
|
+
assert_match %r[t\.bigint\s+"rating",\s+comment: "I am running out of imagination"], output
|
|
69
|
+
assert_match %r[t\.index\s+.+\s+comment: "\\\"Very important\\\" index that powers all the performance.\\nAnd it's fun!"], output
|
|
70
|
+
assert_match %r[t\.index\s+.+\s+name: "idx_obvious",\s+comment: "We need to see obvious comments"], output
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper_cockroachdb"
|
|
4
|
+
require "models/account"
|
|
5
|
+
|
|
6
|
+
module CockroachDB
|
|
7
|
+
module ConnectionAdapters
|
|
8
|
+
class TypeTest < ActiveRecord::TestCase
|
|
9
|
+
fixtures :accounts
|
|
10
|
+
class FakeModel < ActiveRecord::Base
|
|
11
|
+
establish_connection(
|
|
12
|
+
adapter: "fake"
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
def test_type_can_be_used_with_various_db
|
|
16
|
+
skip "Fails in CI, see issue #341"
|
|
17
|
+
assert_equal(
|
|
18
|
+
:postgresql,
|
|
19
|
+
ActiveRecord::Type.adapter_name_from(Account)
|
|
20
|
+
)
|
|
21
|
+
assert_equal(
|
|
22
|
+
:fake,
|
|
23
|
+
ActiveRecord::Type.adapter_name_from(FakeModel)
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper_cockroachdb"
|
|
4
|
+
require "support/copy_cat"
|
|
5
|
+
|
|
6
|
+
module CockroachDB
|
|
7
|
+
class ResolverTest < ::ActiveRecord::ConnectionAdapters::PoolConfig::ResolverTest
|
|
8
|
+
CopyCat.copy_methods(self, ::ActiveRecord::ConnectionAdapters::PoolConfig::ResolverTest,
|
|
9
|
+
:test_url_invalid_adapter) do
|
|
10
|
+
# We're not in the ActiveRecord namespace anymore.
|
|
11
|
+
def on_const(node)
|
|
12
|
+
return unless node in [:const, nil, :AdapterNotFound|:Base]
|
|
13
|
+
|
|
14
|
+
insert_before(node.loc.expression, "ActiveRecord::")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def on_str(node)
|
|
18
|
+
return unless node in [:str, /\ADatabase config/]
|
|
19
|
+
|
|
20
|
+
replace(node.loc.expression, node.children.first.sub("abstract,", "abstract, cockroachdb,").inspect)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require "cases/helper_cockroachdb"
|
|
2
|
+
|
|
3
|
+
# Load dependencies from ActiveRecord test suite
|
|
4
|
+
require "support/schema_dumping_helper"
|
|
5
|
+
|
|
6
|
+
module CockroachDB
|
|
7
|
+
class DefaultExpressionTest < ActiveRecord::TestCase
|
|
8
|
+
include SchemaDumpingHelper
|
|
9
|
+
|
|
10
|
+
# This replaces the same test that's been excluded from
|
|
11
|
+
# PostgresqlDefaultExpressionTest. The assertions have updated to match
|
|
12
|
+
# against CockroachDB's current_date() and current_timestamp() functions.
|
|
13
|
+
# See test/excludes/PostgresqlDefaultExpressionTest.rb.
|
|
14
|
+
test "schema dump includes default expression" do
|
|
15
|
+
output = dump_table_schema("defaults")
|
|
16
|
+
|
|
17
|
+
assert_match %r/t\.date\s+"modified_date",\s+default: -> { \"current_date\(\)\" }/, output
|
|
18
|
+
assert_match %r/t\.datetime\s+"modified_time",\s+default: -> { "current_timestamp\(\)" }/, output
|
|
19
|
+
|
|
20
|
+
assert_match %r/t\.date\s+"modified_date_function",\s+default: -> { "now\(\)" }/, output
|
|
21
|
+
assert_match %r/t\.datetime\s+"modified_time_function",\s+default: -> { "now\(\)" }/, output
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class DefaultNumbersTest < ActiveRecord::TestCase
|
|
26
|
+
class DefaultNumber < ActiveRecord::Base; end
|
|
27
|
+
|
|
28
|
+
setup do
|
|
29
|
+
@connection = ActiveRecord::Base.lease_connection
|
|
30
|
+
@connection.create_table :default_numbers do |t|
|
|
31
|
+
t.decimal :decimal_number, precision: 32, scale: 16, default: 0
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
teardown do
|
|
36
|
+
@connection.drop_table :default_numbers, if_exists: true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_default_decimal_zero_with_large_scale
|
|
40
|
+
record = DefaultNumber.new
|
|
41
|
+
assert_equal 0.0, record.decimal_number
|
|
42
|
+
assert_equal 0.0, record.decimal_number_before_type_cast
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require "cases/helper"
|
|
2
|
+
|
|
3
|
+
module CockroachDB
|
|
4
|
+
class DirtyTest < ActiveRecord::TestCase
|
|
5
|
+
self.use_transactional_tests = false
|
|
6
|
+
|
|
7
|
+
class Testings < ActiveRecord::Base; end
|
|
8
|
+
|
|
9
|
+
# This replaces the same test that's been excluded from DirtyTest. We can
|
|
10
|
+
# run it here with use_transactional_tests set to false.
|
|
11
|
+
# See test/excludes/DirtyTest.rb
|
|
12
|
+
def test_field_named_field
|
|
13
|
+
ActiveRecord::Base.lease_connection.create_table :testings do |t|
|
|
14
|
+
t.string :field
|
|
15
|
+
end
|
|
16
|
+
assert_nothing_raised do
|
|
17
|
+
Testings.new.attributes
|
|
18
|
+
end
|
|
19
|
+
ensure
|
|
20
|
+
ActiveRecord::Base.lease_connection.drop_table :testings, if_exists: true
|
|
21
|
+
ActiveRecord::Base.clear_cache!
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|