feat(api): complete phase 2.4 control plane
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
sqliteTable,
|
||||
text,
|
||||
unique,
|
||||
uniqueIndex,
|
||||
} from 'drizzle-orm/sqlite-core';
|
||||
|
||||
const timestamps = {
|
||||
@@ -88,6 +89,7 @@ export const statusSnapshots = sqliteTable(
|
||||
sql`${table.state} in ('fresh', 'stale', 'expired', 'unknown')`,
|
||||
),
|
||||
index('idx_status_snapshots_instance_observed_at').on(table.instanceId, desc(table.observedAt)),
|
||||
uniqueIndex('uq_status_snapshots_instance_category').on(table.instanceId, table.category),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -98,6 +100,12 @@ export const jobs = sqliteTable(
|
||||
parentJobId: text('parent_job_id').references((): AnySQLiteColumn => jobs.id, {
|
||||
onDelete: 'restrict',
|
||||
}),
|
||||
rootJobId: text('root_job_id').references((): AnySQLiteColumn => jobs.id, {
|
||||
onDelete: 'restrict',
|
||||
}),
|
||||
retryOfJobId: text('retry_of_job_id').references((): AnySQLiteColumn => jobs.id, {
|
||||
onDelete: 'restrict',
|
||||
}),
|
||||
operationId: text('operation_id').notNull(),
|
||||
riskLevel: text('risk_level').notNull(),
|
||||
status: text('status').notNull(),
|
||||
@@ -122,12 +130,14 @@ export const jobItems = sqliteTable(
|
||||
jobId: text('job_id')
|
||||
.notNull()
|
||||
.references(() => jobs.id, { onDelete: 'cascade' }),
|
||||
instanceId: text('instance_id')
|
||||
.notNull()
|
||||
.references(() => instances.id, { onDelete: 'restrict' }),
|
||||
instanceId: text('instance_id').notNull(),
|
||||
attemptNumber: integer('attempt_number').notNull().default(1),
|
||||
status: text('status').notNull(),
|
||||
resultCode: text('result_code'),
|
||||
errorJson: text('error_json'),
|
||||
sourceJobItemId: text('source_job_item_id').references((): AnySQLiteColumn => jobItems.id, {
|
||||
onDelete: 'restrict',
|
||||
}),
|
||||
createdAt: text('created_at').notNull(),
|
||||
startedAt: text('started_at'),
|
||||
finishedAt: text('finished_at'),
|
||||
@@ -144,6 +154,44 @@ export const jobItems = sqliteTable(
|
||||
],
|
||||
);
|
||||
|
||||
export const jobAttempts = sqliteTable(
|
||||
'job_attempts',
|
||||
{
|
||||
id: text('id').primaryKey(),
|
||||
jobId: text('job_id')
|
||||
.notNull()
|
||||
.references(() => jobs.id, { onDelete: 'cascade' }),
|
||||
status: text('status').notNull(),
|
||||
startedAt: text('started_at').notNull(),
|
||||
finishedAt: text('finished_at'),
|
||||
createdAt: text('created_at').notNull(),
|
||||
},
|
||||
(table) => [index('idx_job_attempts_job_started_at').on(table.jobId, table.startedAt)],
|
||||
);
|
||||
|
||||
export const operationPreparations = sqliteTable(
|
||||
'operation_preparations',
|
||||
{
|
||||
id: text('id').primaryKey(),
|
||||
operationId: text('operation_id').notNull(),
|
||||
riskLevel: text('risk_level').notNull(),
|
||||
status: text('status').notNull(),
|
||||
targetInstanceId: text('target_instance_id').notNull(),
|
||||
targetRevision: integer('target_revision').notNull(),
|
||||
parameterSchemaId: text('parameter_schema_id').notNull(),
|
||||
parametersDigest: text('parameters_digest').notNull(),
|
||||
tokenDigest: text('token_digest').notNull(),
|
||||
requestedBy: text('requested_by').notNull(),
|
||||
requestId: text('request_id').notNull(),
|
||||
expiresAt: text('expires_at').notNull(),
|
||||
consumedAt: text('consumed_at'),
|
||||
...timestamps,
|
||||
},
|
||||
(table) => [
|
||||
index('idx_operation_preparations_status_expires_at').on(table.status, table.expiresAt),
|
||||
],
|
||||
);
|
||||
|
||||
export const auditEvents = sqliteTable(
|
||||
'audit_events',
|
||||
{
|
||||
@@ -188,5 +236,22 @@ export const secretReferences = sqliteTable(
|
||||
table.provider,
|
||||
table.externalReference,
|
||||
),
|
||||
uniqueIndex('uq_secret_references_instance_purpose')
|
||||
.on(table.instanceId, table.purpose)
|
||||
.where(sql`${table.instanceId} is not null`),
|
||||
],
|
||||
);
|
||||
|
||||
export const secretCleanupTasks = sqliteTable(
|
||||
'secret_cleanup_tasks',
|
||||
{
|
||||
reference: text('reference').primaryKey(),
|
||||
instanceId: text('instance_id').notNull(),
|
||||
purpose: text('purpose').notNull(),
|
||||
provider: text('provider').notNull(),
|
||||
generation: integer('generation').notNull().default(1),
|
||||
queuedAt: text('queued_at').notNull(),
|
||||
updatedAt: text('updated_at').notNull(),
|
||||
},
|
||||
(table) => [index('idx_secret_cleanup_tasks_queued_at').on(table.queuedAt)],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user