Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3ef4421
feat: bump to Rails 8.1
BuonOmo Oct 9, 2025
22f79b7
fix: add `cast_type` to `Column.new`
BuonOmo Oct 16, 2025
0ed7b7c
fix(test): don't alter backtrace from gems
BuonOmo Oct 17, 2025
c26a1b3
fix(oid): freeze spatial oid
BuonOmo Oct 17, 2025
bb34d48
fix: update run_command execution
BuonOmo Oct 17, 2025
1bf0a3f
fix: use class level native_database_type
BuonOmo Oct 23, 2025
a452092
fix(test): default is now serialized
BuonOmo Oct 24, 2025
8c8e256
fix(schema): hidden columns
BuonOmo Oct 30, 2025
8072f97
fix(ci): smaller summary without skips
BuonOmo Oct 30, 2025
41622c0
fix(test): us english names
BuonOmo Oct 30, 2025
b7d0656
fix(test): coerced value for generate column
BuonOmo Oct 30, 2025
96c5cb6
fix(referential-integrity): make sure fks are added back
BuonOmo Nov 3, 2025
8d86cf2
refactor: cleanup old code
BuonOmo Nov 3, 2025
14f0180
feat(referential-integrity): handle autocommit_before_ddl
BuonOmo Nov 4, 2025
2a03ac5
feat(ci): more complete error output
BuonOmo Nov 4, 2025
3fc2227
fix(test): test_remove_foreign_key_on_8_0
BuonOmo Nov 4, 2025
81699b3
fix(test): type_map not ractor shareable
BuonOmo Nov 4, 2025
5b50d10
fix(test): flaky test_truncate_tables_with_query_cache
BuonOmo Nov 17, 2025
271e8de
fix: proper override for `Column` and `Spatial`
BuonOmo Nov 18, 2025
d8ae08e
fix(test): test_payload_name_on_eager_load
BuonOmo Nov 18, 2025
907fab1
feat(ci): timeout for flaky.yml
BuonOmo Nov 18, 2025
618ed04
fix(ci): Remove retrying logic
BuonOmo Nov 19, 2025
9aef11e
feat: support close_prepared
BuonOmo Nov 19, 2025
1770c41
fix: make sure we eagerly compute SerializeCastValue
BuonOmo Nov 19, 2025
ae9c973
fix: ensure type_map gets sql type details
BuonOmo Nov 19, 2025
df34946
feat: make type_map ractor shareable
BuonOmo Nov 19, 2025
6d3dad0
fix(test): flaky encryption
BuonOmo Nov 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ def check_all_foreign_keys_valid!
def disable_referential_integrity
foreign_keys = all_foreign_keys

remove_foreign_keys(foreign_keys)

# Prefixes and suffixes are added in add_foreign_key
# in AR7+ so we need to temporarily disable them here,
# otherwise prefixes/suffixes will be erroneously added.
old_prefix = ActiveRecord::Base.table_name_prefix
old_suffix = ActiveRecord::Base.table_name_suffix

begin
yield
ensure
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
add_foreign_keys(foreign_keys) # Never raises.

ActiveRecord::Base.table_name_prefix = old_prefix if defined?(old_prefix)
ActiveRecord::Base.table_name_suffix = old_suffix if defined?(old_suffix)
end
end

private

def remove_foreign_keys(foreign_keys)
statements = foreign_keys.map do |foreign_key|
# We do not use the `#remove_foreign_key` method here because it
# checks for foreign keys existance in the schema cache. This method
Expand All @@ -46,45 +69,28 @@ def disable_referential_integrity
schema_creation.accept(at)
end
execute_batch(statements, "Disable referential integrity -> remove foreign keys")
end

yield

# Prefixes and suffixes are added in add_foreign_key
# in AR7+ so we need to temporarily disable them here,
# otherwise prefixes/suffixes will be erroneously added.
old_prefix = ActiveRecord::Base.table_name_prefix
old_suffix = ActiveRecord::Base.table_name_suffix
# NOTE: This method should never raise, otherwise we risk polluting table name
# prefixes and suffixes. The good thing is: if this happens, tests will crash
# hard, no way we miss it.
Comment on lines +91 to +92
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the test retry logic was actually proving me wrong. But now that it is removed, we are fine (see later commit)

def add_foreign_keys(foreign_keys)
# We avoid using `foreign_key_exists?` here because it checks the schema cache
# for every key. This method is performance critical for the test suite, hence
# we use the `#all_foreign_keys` method that only make one query to the database.
already_inserted_foreign_keys = all_foreign_keys
statements = foreign_keys.map do |foreign_key|
next if already_inserted_foreign_keys.any? { |fk| fk.from_table == foreign_key.from_table && fk.options[:name] == foreign_key.options[:name] }

ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
options = foreign_key_options(foreign_key.from_table, foreign_key.to_table, foreign_key.options)
at = create_alter_table foreign_key.from_table
at.add_foreign_key foreign_key.to_table, options

begin
# Avoid having PG:DuplicateObject error if a test is ran in transaction.
# TODO: verify that there is no cache issue related to running this (e.g: fk
# still in cache but not in db)
#
# We avoid using `foreign_key_exists?` here because it checks the schema cache
# for every key. This method is performance critical for the test suite, hence
# we use the `#all_foreign_keys` method that only make one query to the database.
already_inserted_foreign_keys = all_foreign_keys
statements = foreign_keys.map do |foreign_key|
next if already_inserted_foreign_keys.any? { |fk| fk.from_table == foreign_key.from_table && fk.options[:name] == foreign_key.options[:name] }

options = foreign_key_options(foreign_key.from_table, foreign_key.to_table, foreign_key.options)
at = create_alter_table foreign_key.from_table
at.add_foreign_key foreign_key.to_table, options

schema_creation.accept(at)
end
execute_batch(statements.compact, "Disable referential integrity -> add foreign keys")
ensure
ActiveRecord::Base.table_name_prefix = old_prefix
ActiveRecord::Base.table_name_suffix = old_suffix
schema_creation.accept(at)
end
execute_batch(statements.compact, "Disable referential integrity -> add foreign keys")
end

private

# NOTE: Copy/paste of the `#foreign_keys(table)` method adapted
# to return every single foreign key in the database.
def all_foreign_keys
Expand Down