fix(backend): make user_devices migration idempotent for fresh DBs
Add CREATE TABLE IF NOT EXISTS for rebreak.user_devices to the hardware_id migration so fresh databases can migrate despite the alphabetical ordering mismatch with 20260430_add_user_devices. Also apply Prettier formatting to mdm.ts.
This commit is contained in:
parent
7bf26a3138
commit
c8f5bfc82e
@ -1,6 +1,26 @@
|
||||
-- Hardware-ID für UserDevices
|
||||
-- Client liefert hardwaregebundene ID; Backend speichert sie separat zur bestehenden deviceId.
|
||||
|
||||
-- Die canonical CREATE TABLE für user_devices lebt in einer späteren Migration.
|
||||
-- Wir erstellen die Tabelle hier idempotent voraus, damit frische Datenbanken
|
||||
-- trotz falscher alphabetischer Reihenfolge sauber migrieren.
|
||||
CREATE TABLE IF NOT EXISTS "rebreak"."user_devices" (
|
||||
"id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
"user_id" UUID NOT NULL,
|
||||
"device_id" TEXT NOT NULL,
|
||||
"platform" TEXT NOT NULL,
|
||||
"model" TEXT,
|
||||
"name" TEXT,
|
||||
"last_seen_at" TIMESTAMP(3) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"created_at" TIMESTAMP(3) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "user_devices_user_id_device_id_key"
|
||||
ON "rebreak"."user_devices"("user_id", "device_id");
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "user_devices_user_id_idx"
|
||||
ON "rebreak"."user_devices"("user_id");
|
||||
|
||||
ALTER TABLE "rebreak"."user_devices"
|
||||
ADD COLUMN IF NOT EXISTS "hardware_id" TEXT;
|
||||
|
||||
|
||||
@ -104,7 +104,9 @@ export async function clearUserDeviceMdmId(
|
||||
/**
|
||||
* Load all iOS devices that have a NanoMDM UDID link.
|
||||
*/
|
||||
export async function getLinkedUserDevices(): Promise<UserDeviceMdmHealthRecord[]> {
|
||||
export async function getLinkedUserDevices(): Promise<
|
||||
UserDeviceMdmHealthRecord[]
|
||||
> {
|
||||
const db = usePrisma();
|
||||
return db.userDevice.findMany({
|
||||
where: { platform: "ios", mdmId: { not: null } },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user