-
Notifications
You must be signed in to change notification settings - Fork 197
feat: scope credit grant idempotency key to customer #4716
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -- reverse: create index "chargecreditpurchase_namespace_customer_id_key" to table: "charge_credit_purchases" | ||
| DROP INDEX "chargecreditpurchase_namespace_customer_id_key"; | ||
| -- reverse: drop index "chargecreditpurchase_namespace_key" from table: "charge_credit_purchases" | ||
| CREATE UNIQUE INDEX "chargecreditpurchase_namespace_key" ON "charge_credit_purchases" ("namespace", "key") WHERE ((key IS NOT NULL) AND (deleted_at IS NULL)); | ||
|
tothandras marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| -- drop index "chargecreditpurchase_namespace_key" from table: "charge_credit_purchases" | ||
| DROP INDEX "chargecreditpurchase_namespace_key"; | ||
|
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. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check how this repository handles concurrent Atlas index migrations.
rg -n -C2 --glob '*.sql' \
'atlas:txmode|CREATE (UNIQUE )?INDEX CONCURRENTLY|DROP INDEX CONCURRENTLY' \
tools/migrate/migrations || trueRepository: openmeterio/openmeter Length of output: 159 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the migration file and nearby migration conventions.
sed -n '1,120p' tools/migrate/migrations/20260716152332_rescope-credit-grant-key-to-customer.up.sql
printf '\n--- DOWN ---\n'
sed -n '1,120p' tools/migrate/migrations/20260716152332_rescope-credit-grant-key-to-customer.down.sql
printf '\n--- MIGRATION FILES WITH TX MODE / CONCURRENT INDEX REFERENCES ---\n'
rg -n -C2 'atlas:txmode|CONCURRENTLY|CREATE UNIQUE INDEX|DROP INDEX' tools/migrate/migrations || true
printf '\n--- FILE LIST AROUND THIS MIGRATION ---\n'
git ls-files 'tools/migrate/migrations/*rescope-credit-grant-key-to-customer*'Repository: openmeterio/openmeter Length of output: 50378 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- TARGET UP ---'
cat -n tools/migrate/migrations/20260716152332_rescope-credit-grant-key-to-customer.up.sql
echo
echo '--- TARGET DOWN ---'
cat -n tools/migrate/migrations/20260716152332_rescope-credit-grant-key-to-customer.down.sql
echo
echo '--- NARROW TXMODE / CONCURRENT SEARCH ---'
rg -n -C1 'atlas:txmode|CONCURRENTLY|CREATE UNIQUE INDEX|DROP INDEX' \
tools/migrate/migrations/20260716152332_rescope-credit-grant-key-to-customer.* \
tools/migrate/migrations/*.sql || trueRepository: openmeterio/openmeter Length of output: 50378 🏁 Script executed: #!/bin/bash
set -euo pipefail
file=tools/migrate/migrations/20260716152332_rescope-credit-grant-key-to-customer.up.sql
echo '--- FILE SIZE / LINE COUNT ---'
wc -l "$file"
echo
echo '--- FILE CONTENT ---'
cat -n "$file"
echo
echo '--- MATCHES IN THIS FILE ---'
rg -n 'atlas:txmode|CONCURRENTLY|CREATE UNIQUE INDEX|DROP INDEX' "$file" || true
echo
echo '--- NEARBY MIGRATIONS FOR THIS TABLE/INDEX NAME ---'
rg -n -C2 'chargecreditpurchase|credit-purchase|credit-grant|namespace_key' tools/migrate/migrations/202607*.sql tools/migrate/migrations/202606*.sql || trueRepository: openmeterio/openmeter Length of output: 4659 Build the replacement index concurrently This 🧰 Tools🪛 Squawk (2.59.0)[warning] 2-2: A normal (require-concurrent-index-deletion) 🤖 Prompt for AI AgentsSources: Coding guidelines, Path instructions, Linters/SAST tools |
||
| -- create index "chargecreditpurchase_namespace_customer_id_key" to table: "charge_credit_purchases" | ||
| -- the old (namespace, key) unique index guarantees no (namespace, customer_id, key) duplicates exist, | ||
| -- so widening the key scope cannot fail on existing data | ||
| -- atlas:nolint MF101 | ||
| CREATE UNIQUE INDEX "chargecreditpurchase_namespace_customer_id_key" ON "charge_credit_purchases" ("namespace", "customer_id", "key") WHERE ((key IS NOT NULL) AND (deleted_at IS NULL)); | ||
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.
After the new schema allows two customers in one namespace to use the same key, rolling back tries to recreate the old unique
(namespace, key)index. Any such records make this statement fail, leaving the rollback incomplete.Prompt To Fix With AI