fix(sku): add DB CHECK backstop rejecting empty SKU ID#2300
Conversation
The code-level guard in db::sku::create/replace rejects empty ids, but only on those two paths. The machine_skus PRIMARY KEY blocks NULL yet accepts the empty string, so an empty id could still reach the table via any unvalidated write path. Add a CHECK (id <> '') constraint so the database enforces the invariant regardless of caller. Any pre-existing empty-id SKU is preserved: it is reassigned a generated id and referencing machines are repointed before the constraint is applied, so the migration is non-destructive. Verified via the sqlx_test harness, which rebuilds the migrated template DB from scratch and runs test_sku_create_rejects_empty_id green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
draft because I want to run the migration manually in my dev-env |
done. also verified that the check works by running the migration in an env that doesn't have the code fix in #2253 |
The code-level guard in db::sku::create/replace rejects empty ids, but only on those two paths. The machine_skus PRIMARY KEY blocks NULL yet accepts the empty string, so an empty id could still reach the table via any unvalidated write path.
Add a CHECK (id <> '') constraint so the database enforces the invariant regardless of caller. Any pre-existing empty-id SKU is preserved: it is reassigned a generated id and referencing machines are repointed before the constraint is applied, so the migration is non-destructive.
Verified via the sqlx_test harness, which rebuilds the migrated template DB from scratch and runs test_sku_create_rejects_empty_id green.
Description
Type of Change
Related Issues (Optional)
Breaking Changes
Testing
Additional Notes