utils/migrate-to-enterprise: initial commit #444
No reviewers
Labels
No labels
Compat/Breaking
Component/Enclave-Builder
Component/Infrastructure
Deploy/BYOC
Deploy/Full-managed
Deploy/Self-hosted
Interface/API
Interface/CLI
Interface/Git
Interface/Web
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority/Critical
Priority/High
Priority/Low
Priority/Medium
Reviewed/Confirmed
Reviewed/Duplicate
Reviewed/Invalid
Reviewed/Won't Fix
Status/Abandoned
Status/Blocked
Status/Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
public/platform!444
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "ryansquared/migrate-to-enterprise.sh"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Review findings — changes requested
I found several correctness blockers in
utils/migrate-to-enterprise.sh:Critical — the SQL is never sent to PostgreSQL (
:74).docker execomits-i, so the heredoc is not attached to stdin.psqlexits successfully and the script printsDone.without validating or changing anything. A direct probe showeddocker exec ... psqlproduced no output, whiledocker exec -i ... psqlexecuted the query.Critical — adding
-istill leaves invalid SQL (:77-79).psqldoes not interpolate:'org_id'inside the dollar-quotedDO $$ ... $$body. With stdin attached, PostgreSQL receives the colon literally and reportssyntax error at or near ":". Pass the value outside the block (for example viaset_config/current_setting) or restructure the SQL.High — the advertised row-count/cardinality safeguards are absent (
:82,113-137).affected_rowsis unused,LIMIT 1masks multiple open ledger segments, the ledger row is not locked, and neither update checks that exactly one row changed. A concurrent rollover can therefore leave an open legacy ledger segment after conversion. Lock/revalidate the ledger state and raise unless each expected update affects exactly one row.High — conversion races the legacy tier-change path (
src/api/src/subscriptions.rs:886-1073). Tier change readsbilling_sourcebefore opening its transaction. If it readslegacy_creditsbefore this migration commits, it can later overwrite the unlimitedmax_appsand insert a new open ledger segment while leaving the source asenterprise. Both paths need a shared organization-level lock or equivalent in-transaction guarded revalidation.Medium — “active” currently means any non-canceled status (
:99-104). This includespast_due, but enterprise deployment requires status exactlyactive(src/api/src/main.rs:2227-2233). Converting a legacypast_duerow removes it from legacy maintenance while leaving an unusable enterprise entitlement. Requireactiveor explicitly normalize the intended status under lock.Checks run against head
b6b2c2d661698b0b4fae5d86e562ca1c5b0c2af6:git diff --check,bash -n, direct Docker/stdin probes, a read-only nonexistent-UUID execution, schema inspection, and an independent review. The first four findings should be addressed before merge; a focused execution test would have caught both critical failures.Re-reviewed head
1fe8ab4158e010ccd236d3fc28baf606b3cdd945. Thedocker exec -iand UUID interpolation issues are fixed. Three items remain:LIMIT 1is insufficient: non-STRICTPL/pgSQLSELECT INTOstill silently picks one row. UseINTO STRICT/an explicit count, lock the open ledger row, and abort unless each expected update affects exactly one row.legacy_creditsbefore migration, then overwritemax_appsand open a new ledger segment after migration commits. Use a shared organization-level lock or revalidatebilling_sourceinside the tier-change transaction before writing.past_due/other non-canceled statuses, but enterprise deployment permits onlyactive. Requirestatus = 'active'or explicitly normalize the intended status under lock.These remain blockers before merge.