Change ticket IDs from UUID to sequential integers
Backend: - tickets.id: uuid → integer GENERATED ALWAYS AS IDENTITY - transactions.ticket_id, custom_field_values.ticket_id: uuid → integer - Routes convert string params to Number() for DB queries - ScripEngine.prepare takes ticketId: number - ActionPayload.ticketId: string → number Frontend: - Ticket.id: string → number, Transaction.ticket_id: string → number - API functions accept number params - formatTicketId() helper returns TKT-0001 format - Ticket rows display TKT-XXXX, detail page uses formatTicketId Migration: drops FKs, clears data, alters column types, re-adds FKs
This commit is contained in:
@@ -24,7 +24,7 @@ export const lifecycles = pgTable('lifecycles', {
|
||||
});
|
||||
|
||||
export const tickets = pgTable('tickets', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
id: integer('id').primaryKey().generatedAlwaysAsIdentity(),
|
||||
subject: text('subject').notNull(),
|
||||
queue_id: uuid('queue_id').notNull().references(() => queues.id),
|
||||
status: text('status').notNull(),
|
||||
@@ -41,7 +41,7 @@ export const tickets = pgTable('tickets', {
|
||||
|
||||
export const transactions = pgTable('transactions', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
ticket_id: uuid('ticket_id').notNull().references(() => tickets.id, { onDelete: 'cascade' }),
|
||||
ticket_id: integer('ticket_id').notNull().references(() => tickets.id, { onDelete: 'cascade' }),
|
||||
transaction_type: text('transaction_type').notNull(),
|
||||
field: text('field'),
|
||||
old_value: text('old_value'),
|
||||
@@ -103,7 +103,7 @@ export const queueCustomFields = pgTable('queue_custom_fields', {
|
||||
export const customFieldValues = pgTable('custom_field_values', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
custom_field_id: uuid('custom_field_id').notNull().references(() => customFields.id, { onDelete: 'cascade' }),
|
||||
ticket_id: uuid('ticket_id').notNull().references(() => tickets.id, { onDelete: 'cascade' }),
|
||||
ticket_id: integer('ticket_id').notNull().references(() => tickets.id, { onDelete: 'cascade' }),
|
||||
value: text('value').notNull(),
|
||||
created_at: timestamp('created_at', { withTimezone: true }).defaultNow(),
|
||||
}, (table) => ({
|
||||
|
||||
@@ -61,7 +61,7 @@ export function createTicketsRouter(db: Db): Hono {
|
||||
|
||||
// GET /:id — get ticket with custom field values
|
||||
router.get('/:id', async (c) => {
|
||||
const id = c.req.param('id');
|
||||
const id = Number(c.req.param('id'));
|
||||
|
||||
const ticket = await db.query.tickets.findFirst({
|
||||
where: eq(tickets.id, id),
|
||||
@@ -92,7 +92,7 @@ export function createTicketsRouter(db: Db): Hono {
|
||||
|
||||
// PATCH /:id — update ticket
|
||||
router.patch('/:id', async (c) => {
|
||||
const id = c.req.param('id');
|
||||
const id = Number(c.req.param('id'));
|
||||
const body = await c.req.json();
|
||||
const parsed = UpdateTicketSchema.parse(body);
|
||||
|
||||
@@ -186,7 +186,7 @@ export function createTicketsRouter(db: Db): Hono {
|
||||
|
||||
// POST /:id/preview — dry-run scrips
|
||||
router.post('/:id/preview', async (c) => {
|
||||
const id = c.req.param('id');
|
||||
const id = Number(c.req.param('id'));
|
||||
const body = await c.req.json();
|
||||
const parsed = UpdateTicketSchema.parse(body);
|
||||
|
||||
@@ -221,7 +221,7 @@ export function createTicketsRouter(db: Db): Hono {
|
||||
|
||||
// GET /:id/transactions — list transactions for ticket
|
||||
router.get('/:id/transactions', async (c) => {
|
||||
const id = c.req.param('id');
|
||||
const id = Number(c.req.param('id'));
|
||||
|
||||
const result = await db.query.transactions.findMany({
|
||||
where: eq(transactions.ticket_id, id),
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface ActionPayload {
|
||||
scripName: string;
|
||||
actionType: string;
|
||||
actionConfig: Record<string, unknown>;
|
||||
ticketId?: string;
|
||||
ticketId?: number;
|
||||
recipients?: string[];
|
||||
subject?: string;
|
||||
body?: string;
|
||||
@@ -97,7 +97,7 @@ export class SetCustomField implements ActionExecutor {
|
||||
async execute(payload: ActionPayload): Promise<{ success: boolean; message: string }> {
|
||||
const fieldId = payload.field_id ?? String(payload.actionConfig['field_id'] ?? '');
|
||||
const value = payload.value ?? String(payload.actionConfig['value'] ?? '');
|
||||
const ticketId = payload.ticketId ?? String(payload.actionConfig['ticket_id'] ?? '');
|
||||
const ticketId = payload.ticketId ?? Number(payload.actionConfig['ticket_id'] ?? 0);
|
||||
|
||||
if (!fieldId || !value || !ticketId) {
|
||||
return { success: false, message: 'SetCustomField: missing field_id, value, or ticket_id' };
|
||||
@@ -121,7 +121,7 @@ export class CreateTransaction implements ActionExecutor {
|
||||
constructor(private db: Db) {}
|
||||
|
||||
async execute(payload: ActionPayload): Promise<{ success: boolean; message: string }> {
|
||||
const ticketId = payload.ticketId ?? String(payload.actionConfig['ticket_id'] ?? '');
|
||||
const ticketId = payload.ticketId ?? Number(payload.actionConfig['ticket_id'] ?? 0);
|
||||
const transactionType = String(payload.actionConfig['transaction_type'] ?? '');
|
||||
const field = payload.actionConfig['field'] as string | undefined ?? null;
|
||||
const oldValue = payload.actionConfig['old_value'] as string | undefined ?? null;
|
||||
|
||||
@@ -35,7 +35,7 @@ export class ScripEngine {
|
||||
}
|
||||
|
||||
async prepare(
|
||||
ticketId: string,
|
||||
ticketId: number,
|
||||
transactions: Transaction[],
|
||||
): Promise<PreparedScrip[]> {
|
||||
const ticketRecord = await this.db.query.tickets.findFirst({
|
||||
|
||||
Reference in New Issue
Block a user