Module: ActiveRecord::ConnectionAdapters::CockroachDB::DatabaseStatements
- Included in:
- ActiveRecord::ConnectionAdapters::CockroachDBAdapter
- Defined in:
- lib/active_record/connection_adapters/cockroachdb/database_statements.rb
Instance Method Summary collapse
-
#insert_fixtures_set(fixture_set, tables_to_delete = []) ⇒ Object
Overridden to avoid using transactions for schema creation.
Instance Method Details
#insert_fixtures_set(fixture_set, tables_to_delete = []) ⇒ Object
Overridden to avoid using transactions for schema creation.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_record/connection_adapters/cockroachdb/database_statements.rb', line 22 def insert_fixtures_set(fixture_set, tables_to_delete = []) fixture_inserts = build_fixture_statements(fixture_set) table_deletes = tables_to_delete.map { |table| "DELETE FROM #{quote_table_name(table)}" } statements = (table_deletes + fixture_inserts).join(";") # Since [rails pull request #52428][1], `#execute_batch` does not # trigger a cache clear anymore. However, `#insert_fixtures_set` # relies on that clear to ensure consistency. In the postgresql # adapter, this is ensured by a call to `#execute` rather than # `#execute_batch` in `#disable_referential_integrity`. Since # we are not always calling `#disable_referential_integrity`, # we need to ensure that the cache is cleared when running # our statements by calling `#execute` instead of `#execute_batch`. # # [1]: https://github.com/rails/rails/pull/52428 begin # much faster without disabling referential integrity, worth trying. transaction(requires_new: true) do execute(statements, "Fixtures Load") end rescue disable_referential_integrity do execute(statements, "Fixtures Load") end end end |