sourcegraph/doc/dev/background-information/sql
Keegan Carruthers-Smith cbd12608b5
database: run tenant_id migration outside of a transaction (#64410)
We hit a deadlock when deploying this migration to s2. This is because
within our transaction of the migration we likely didn't obtain table
locks in the same order as a transaction in our application code.

So this commit introduces a new migration metadata field
"noTransaction". The documentation for migrator says you should create a
migration per needed transactions. However, this would require us to
create 100s of migrations. We believe the better approach is introducing
this field and barely advertising it.

When reading the code which actually runs migrations, there is no extra
logic done outside of BEGIN; run_migration; COMMIT; so this change is
safe.

We update the migrations to avoid duplicating the function name we
introduce in case something goes wrong (now that the transaction could
leak out the function name).

Test Plan: The actual migrations are tested by go test. I added a test
assertion that we don't call Transact, but to be honest that is super
sketchy. However, we couldn't actually find any test fixtures which
actually run against the DB. So that would require a much deeper
investment for how simple the code change is.

Co-authored-by: Erik Seliger <erikseliger@me.com>
2024-08-13 07:08:19 +02:00
..
batch_operations.md insights: batch insert series points again (#43030) 2022-10-17 15:09:10 +00:00
index.md Backport dev docs changes that happened in docsite v2 (#61931) 2024-04-16 16:51:00 +02:00
locking_behavior.md codeintel: Rockskip for symbols (#28719) 2022-03-02 21:13:28 -07:00
materialized_cache.md Renaming code intel test (#39509) 2022-07-27 19:12:07 +02:00
migrations_overview.md database: run tenant_id migration outside of a transaction (#64410) 2024-08-13 07:08:19 +02:00
migrations.md Docs: Replace hyphens in text with em-dashes (#42367) 2023-01-31 13:18:49 +01:00
upgrades_and_migrator_design.md Backport dev docs changes that happened in docsite v2 (#61931) 2024-04-16 16:51:00 +02:00