Portal: add nullable System Name to LicenseKey with per-account unique index

Adds systemName (as typed, trimmed) and systemNameLower (case-folded) to
LicenseKey plus a unique index on (userId, systemNameLower) so names are
case-insensitively unique per account when non-null. Additive and
reversible; migration tested up/down. Regenerates the Prisma client.
This commit is contained in:
NeilClack
2026-09-29 09:51:48 -05:00
parent 179df1e252
commit 1d76e8dff9
6 changed files with 101 additions and 8 deletions
@@ -0,0 +1,6 @@
-- AlterTable
ALTER TABLE "LicenseKey" ADD COLUMN "systemName" TEXT,
ADD COLUMN "systemNameLower" TEXT;
-- CreateIndex
CREATE UNIQUE INDEX "LicenseKey_userId_systemNameLower_key" ON "LicenseKey"("userId", "systemNameLower");
+7
View File
@@ -205,10 +205,17 @@ model LicenseKey {
userId String?
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
email String?
// Human-readable label set only by the Kiosk (e.g. "Living Room"). Trimmed,
// 1-40 chars. Never a reference or foreign key; the License Key is the only
// identifier. `systemNameLower` is a case-folded copy used to enforce
// per-account, case-insensitive uniqueness when non-null.
systemName String?
systemNameLower String?
// Legacy subscription level. Retained in the database but unmanaged; hidden
// from the client and left NULL.
level String? @ignore
@@unique([userId, systemNameLower])
@@index([userId])
@@index([email])
}