-
Notifications
You must be signed in to change notification settings - Fork 146
fix/temporary tables #1257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix/temporary tables #1257
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| name: Add replica identity on tables without primary key |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| do $$ | ||
| declare | ||
| ledger record; | ||
| vsql varchar; | ||
| begin | ||
| set search_path = '{{ .Schema }}'; | ||
|
|
||
| for ledger in select * from _system.ledgers where bucket = current_schema loop | ||
| vsql = 'ALTER TABLE transactions REPLICA IDENTITY USING INDEX transactions_ledger'; | ||
| execute vsql; | ||
|
|
||
| vsql = 'ALTER TABLE accounts REPLICA IDENTITY USING INDEX accounts_ledger'; | ||
| execute vsql; | ||
|
|
||
| vsql = 'ALTER TABLE logs REPLICA IDENTITY USING INDEX logs_ledger'; | ||
| execute vsql; | ||
| end loop; | ||
|
Comment on lines
+8
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, read the complete migration file to see full context
cat internal/storage/bucket/migrations/45-add-replica-identity/up.sqlRepository: formancehq/ledger Length of output: 546 🏁 Script executed: # Search for where these indexes are created to understand if they're per-ledger
rg -n "CREATE.*INDEX.*(transactions_ledger|accounts_ledger|logs_ledger)" --type sql -B2 -A2Repository: formancehq/ledger Length of output: 43 🏁 Script executed: # Look for other migrations to understand table and ledger structure
ls -la internal/storage/bucket/migrations/ | head -20Repository: formancehq/ledger Length of output: 1491 🏁 Script executed: # Search for how ledger is used in similar migration patterns
rg -n "for ledger in select" internal/storage/bucket/migrations/ -A10Repository: formancehq/ledger Length of output: 9897 🏁 Script executed: # Search for the index creation for these specific indexes
rg -n "CREATE.*INDEX.*transactions_ledger|accounts_ledger|logs_ledger" internal/storage/bucket/migrations/ --type sqlRepository: formancehq/ledger Length of output: 1472 🏁 Script executed: # Also check the initial schema to see if these indexes are defined there
cat internal/storage/bucket/migrations/0-init-schema/up.sql | grep -n "transactions_ledger\|accounts_ledger\|logs_ledger"Repository: formancehq/ledger Length of output: 276 The The indexes Remove the loop and execute the three 🤖 Prompt for AI Agents |
||
| end | ||
| $$; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical:
ON COMMIT DROPwill destroytmp_volumesafter the first batchCOMMITat Line 47, breaking all subsequent loop iterations.Since the DO block issues intermediate
COMMITstatements (Line 47) for batch processing, each commit ends the current transaction and starts a new one. TheON COMMIT DROPclause causes PostgreSQL to drop the temp table at each commit boundary. The second batch iteration will fail with a "relation tmp_volumes does not exist" error.Remove
ON COMMIT DROPto match the pattern used in migration 17 (plain temp table + explicit drop after the loop):Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents