Merge SERVICE role into AGENT
Every AGENT now gets an auto-generated API key on creation, shown once in a modal. AGENTs log in with password and authenticate to the API with X-Api-Key. pre-push.sql defensively migrates any residual SERVICE rows to AGENT before Prisma rewrites the enum. Goddard is no longer baked into the seed — create agents via Admin → Users. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
-- Idempotent SQL applied BEFORE `prisma db push`.
|
||||
-- Flips any residual SERVICE-role users to AGENT before Prisma rewrites the Role enum.
|
||||
-- Safe no-op on fresh databases or databases already migrated past the SERVICE role.
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM pg_type t
|
||||
JOIN pg_enum e ON e.enumtypid = t.oid
|
||||
WHERE t.typname = 'Role' AND e.enumlabel = 'SERVICE'
|
||||
) THEN
|
||||
EXECUTE 'UPDATE "User" SET "role" = ''AGENT'' WHERE "role"::text = ''SERVICE''';
|
||||
END IF;
|
||||
END $$;
|
||||
@@ -11,7 +11,6 @@ enum Role {
|
||||
ADMIN
|
||||
AGENT
|
||||
USER
|
||||
SERVICE
|
||||
}
|
||||
|
||||
enum TicketStatus {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import bcrypt from 'bcryptjs';
|
||||
import crypto from 'crypto';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
@@ -20,25 +19,6 @@ async function main() {
|
||||
},
|
||||
});
|
||||
|
||||
// Goddard — n8n service account
|
||||
const apiKey = `sk_${crypto.randomBytes(32).toString('hex')}`;
|
||||
await prisma.user.upsert({
|
||||
where: { username: 'goddard' },
|
||||
update: {},
|
||||
create: {
|
||||
username: 'goddard',
|
||||
email: 'goddard@internal',
|
||||
displayName: 'Goddard',
|
||||
passwordHash: await bcrypt.hash(crypto.randomBytes(32).toString('hex'), 12),
|
||||
role: 'SERVICE',
|
||||
apiKey,
|
||||
},
|
||||
});
|
||||
|
||||
const existingGoddard = await prisma.user.findUnique({ where: { username: 'goddard' } });
|
||||
console.log(`\nGoddard API key: ${existingGoddard?.apiKey ?? apiKey}`);
|
||||
console.log('(This key is only displayed once on first seed — copy it now)\n');
|
||||
|
||||
// Sample CTI structure
|
||||
const theWrightServer = await prisma.category.upsert({
|
||||
where: { name: 'TheWrightServer' },
|
||||
|
||||
Reference in New Issue
Block a user