fix(tenants): set NOT-NULL kind in create_tenant; add regression test #221

Merged
nrupard merged 1 commit from fix/pms-287-create-tenant-kind into main 2026-06-13 19:59:23 +02:00
Owner

Summary

Fixes TenantService::create_tenant, which omitted the NOT-NULL tenants.kind column. Closes PMS-287.

Migration 019_tenant_kind adds kind NOT NULL and then drops the column default ("the column is otherwise required and callers always set it explicitly"). create_tenant's INSERT did not, so it failed with SQLSTATE 23502 and POST /api/v1/tenants 500'd. Latent because no test exercised that insert path - tests/tenants.rs provisions via ensure_personal_tenant and seed helpers, both of which set kind. Surfaced while writing the PMS-236 isolation suite.

Change

  • src/modules/tenants/service.rs: add kind to the INSERT with the value 'org' (the admin/multi-user org-create path; self-signup uses kind='personal').
  • tests/tenants.rs: new create_tenant_sets_org_kind - calls create_tenant, asserts it succeeds and the row reads back kind = 'org'. Fails on the pre-fix code (the .expect panics on the 23502).

Verification

  • cargo test -p mokosh-server --test tenants create_tenant_sets_org_kind: 1 passed.
  • cargo fmt --all --check clean; cargo clippy --test tenants clean.
## Summary Fixes `TenantService::create_tenant`, which omitted the NOT-NULL `tenants.kind` column. Closes PMS-287. Migration `019_tenant_kind` adds `kind NOT NULL` and then drops the column default ("the column is otherwise required and callers always set it explicitly"). `create_tenant`'s INSERT did not, so it failed with SQLSTATE `23502` and `POST /api/v1/tenants` 500'd. Latent because no test exercised that insert path - `tests/tenants.rs` provisions via `ensure_personal_tenant` and seed helpers, both of which set `kind`. Surfaced while writing the PMS-236 isolation suite. ## Change - `src/modules/tenants/service.rs`: add `kind` to the INSERT with the value `'org'` (the admin/multi-user org-create path; self-signup uses `kind='personal'`). - `tests/tenants.rs`: new `create_tenant_sets_org_kind` - calls `create_tenant`, asserts it succeeds and the row reads back `kind = 'org'`. Fails on the pre-fix code (the `.expect` panics on the 23502). ## Verification - `cargo test -p mokosh-server --test tenants create_tenant_sets_org_kind`: 1 passed. - `cargo fmt --all --check` clean; `cargo clippy --test tenants` clean.
fix(tenants): set NOT-NULL kind in create_tenant; add regression test
Some checks failed
E2E / Playwright against staging (pull_request) Failing after 37s
Check / fmt + clippy + compile + tests (pull_request) Failing after 2m34s
Create release / Create release from merged PR (pull_request) Has been skipped
f7f8b7d5d1
create_tenant's INSERT omitted the tenants.kind column. Migration 019_tenant_kind adds kind NOT NULL and then drops its default ("callers always set it explicitly"), so the insert failed with SQLSTATE 23502 and POST /api/v1/tenants 500'd. The defect was latent because no test exercised the create_tenant insert: tests/tenants.rs provisioned tenants via ensure_personal_tenant and seed helpers, both of which set kind. It surfaced while writing the PMS-236 isolation suite.

Set kind = 'org' explicitly in the INSERT (this is the admin/multi-user org-create path; self-signup uses kind='personal'). Add an integration test that calls create_tenant and asserts it succeeds and the row is kind='org', so a future missing-column regression fails CI.

#PMS-287
nrupard deleted branch fix/pms-287-create-tenant-kind 2026-06-13 19:59:23 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/mokosh-server!221
No description provided.