You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
check_info
[
{"conname"=>"users_email_null", "constraintdef"=>"CHECK (email IS NOT NULL) NOT VALID", "valid"=>false},
{"conname"=>"users_email_null", "constraintdef"=>"CHECK (email IS NOT NULL) NOT VALID", "valid"=>false}
]
Updating to use DISTINCT "fixes" the issue, but that is very likely not the right fix for this issue and is now approaching my edge of knowledge.
check_info = exec_query(<<-SQL, "SCHEMA")
SELECT DISTINCT conname, pg_get_constraintdef(c.oid, true) AS constraintdef, c.convalidated AS valid
FROM pg_constraint c
JOIN pg_class t ON c.conrelid = t.oid
WHERE c.contype = 'c'
AND t.relname = #{scope[:name]}
SQL
Expected behavior
Dumping the db schema should not duplicate check constraints when multiple schemas are present in the database
ApplicationRecord.connection.check_constraints("users")
=> [#<struct ActiveRecord::ConnectionAdapters::CheckConstraintDefinition table_name="users", expression="email IS NOT NULL", options={:name=>"users_email_null", :validate=>false}>]
Actual behavior
Dumping the db schema creates a duplicate check constraints entry when multiple schemas are present in the database
ApplicationRecord.connection.check_constraints("users")
=> [#<struct ActiveRecord::ConnectionAdapters::CheckConstraintDefinition table_name="users", expression="email IS NOT NULL", options={:name=>"users_email_null", :validate=>false}>, #<struct ActiveRecord::ConnectionAdapters::CheckConstraintDefinition table_name="users", expression="email IS NOT NULL", options={:name=>"users_email_null", :validate=>false}>]
System configuration
Rails version: 7.0.2.3
Ruby version: 3.1.1p18
The text was updated successfully, but these errors were encountered:
frank-west-iii
changed the title
Duplicate check constraints being generated in schema:dump with multiple db schemas containing same table name
Duplicate check constraints being generated in schema:dump with multiple db schemas
Apr 14, 2022
Steps to reproduce
I've create a repo with more information and reproduction steps here: https://github.com/frank-west-iii/check_demo
Additional tracing info:
rails/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
Line 535 in a9bbc92
Updating to use DISTINCT "fixes" the issue, but that is very likely not the right fix for this issue and is now approaching my edge of knowledge.
Expected behavior
Dumping the db schema should not duplicate check constraints when multiple schemas are present in the database
Actual behavior
Dumping the db schema creates a duplicate check constraints entry when multiple schemas are present in the database
System configuration
Rails version: 7.0.2.3
Ruby version: 3.1.1p18
The text was updated successfully, but these errors were encountered: