Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ jobs:
fail-fast: false
matrix:
# https://www.cockroachlabs.com/docs/releases/release-support-policy
crdb: [v23.2, v24.1, v24.3]
crdb: [v24.3]
ruby: ["3.4"]
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
sql_cache: [15, 25, 35]
store: [20, 40, 60, 80]
name: "${{ matrix.sql_cache }}% SQL&Cache, ${{ matrix.store }}% Store"
steps:
- name: Set Up Actions
uses: actions/checkout@v4
Expand Down Expand Up @@ -75,9 +77,8 @@ jobs:

# Start a CockroachDB server and wait for it to become ready.
rm -f "$urlfile"
rm -rf cockroach-data
# Start CockroachDB.
cockroach start-single-node --max-sql-memory=25% --cache=25% --insecure --host=localhost --spatial-libs=./cockroach-$full_version.linux-amd64/lib --listening-url-file="$urlfile" >/dev/null 2>&1 &
cockroach start-single-node --insecure --max-sql-memory=${{ matrix.sql_cache }}% --cache=${{ matrix.sql_cache }}% --store=type=mem,size=${{ matrix.store }}% --host=localhost --spatial-libs=./cockroach-$full_version.linux-amd64/lib --listening-url-file="$urlfile" >/dev/null 2>&1 &
# Ensure CockroachDB is stopped on script exit.
# Wait until CockroachDB has started.
for i in {0..3}; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ def insert_fixtures_set(fixture_set, tables_to_delete = [])
table_deletes = tables_to_delete.map { |table| "DELETE FROM #{quote_table_name(table)}" }
statements = table_deletes + fixture_inserts

disable_referential_integrity do
execute_batch(statements, "Fixtures Load")
begin # much faster without disabling referential integrity, worth trying.
transaction(requires_new: true) do
execute_batch(statements, "Fixtures Load")
end
rescue
disable_referential_integrity do
execute_batch(statements, "Fixtures Load")
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ def check_all_foreign_keys_valid!
def disable_referential_integrity
foreign_keys = all_foreign_keys

foreign_keys.each do |foreign_key|
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
# is performance critical and we know the foreign key exist.
at = create_alter_table foreign_key.from_table
at.drop_foreign_key foreign_key.name

execute schema_creation.accept(at)
schema_creation.accept(at)
end
execute_batch(statements, "Disable referential integrity -> remove foreign keys")

yield

Expand All @@ -66,11 +67,16 @@ def disable_referential_integrity
# 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
foreign_keys.each do |foreign_key|
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] }

add_foreign_key(foreign_key.from_table, foreign_key.to_table, **foreign_key.options)
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
Expand Down
Loading