task-d.7.8

This commit is contained in:
phaichayon
2026-07-03 10:19:03 +07:00
parent 110c2f9e7f
commit 9b05743b1e
18 changed files with 1980 additions and 16 deletions

View File

@@ -57,6 +57,88 @@ export const memberships = pgTable('memberships', {
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull()
});
export const setupRuns = pgTable('setup_runs', {
id: text('id').primaryKey(),
status: text('status').default('not_started').notNull(),
mode: text('mode').default('production').notNull(),
targetOrganizationId: text('target_organization_id'),
startedBy: text('started_by').notNull(),
completedBy: text('completed_by'),
startedAt: timestamp('started_at', { withTimezone: true }).defaultNow().notNull(),
completedAt: timestamp('completed_at', { withTimezone: true }),
lastError: text('last_error'),
metadata: jsonb('metadata').$type<Record<string, unknown> | null>(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull()
});
export const setupRunSteps = pgTable(
'setup_run_steps',
{
id: text('id').primaryKey(),
setupRunId: text('setup_run_id').notNull(),
stepKey: text('step_key').notNull(),
status: text('status').default('not_started').notNull(),
inputHash: text('input_hash'),
outputJson: jsonb('output_json').$type<Record<string, unknown> | null>(),
errorsJson: jsonb('errors_json').$type<unknown[] | null>(),
warningsJson: jsonb('warnings_json').$type<unknown[] | null>(),
startedAt: timestamp('started_at', { withTimezone: true }),
completedAt: timestamp('completed_at', { withTimezone: true }),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull()
},
(table) => ({
setupRunStepIdx: uniqueIndex('setup_run_steps_run_step_idx').on(
table.setupRunId,
table.stepKey
)
})
);
export const seedManifests = pgTable('seed_manifests', {
id: text('id').primaryKey(),
setupRunId: text('setup_run_id'),
organizationId: text('organization_id'),
name: text('name').notNull(),
version: text('version').notNull(),
type: text('type').notNull(),
checksum: text('checksum').notNull(),
status: text('status').default('pending').notNull(),
source: text('source').notNull(),
appliedBy: text('applied_by'),
appliedAt: timestamp('applied_at', { withTimezone: true }),
reportJson: jsonb('report_json').$type<Record<string, unknown> | null>(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull()
});
export const seedManifestItems = pgTable(
'seed_manifest_items',
{
id: text('id').primaryKey(),
seedManifestId: text('seed_manifest_id').notNull(),
itemKey: text('item_key').notNull(),
sourceFile: text('source_file').notNull(),
checksum: text('checksum').notNull(),
status: text('status').default('pending').notNull(),
importedCount: integer('imported_count').default(0).notNull(),
updatedCount: integer('updated_count').default(0).notNull(),
skippedCount: integer('skipped_count').default(0).notNull(),
errorCount: integer('error_count').default(0).notNull(),
warningCount: integer('warning_count').default(0).notNull(),
reportJson: jsonb('report_json').$type<Record<string, unknown> | null>(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull()
},
(table) => ({
seedManifestItemIdx: uniqueIndex('seed_manifest_items_manifest_item_idx').on(
table.seedManifestId,
table.itemKey
)
})
);
export const crmRoleProfiles = pgTable(
'crm_role_profiles',
{