PSA/server/migrations/20250307201232_create_workflow_task_inbox.cjs
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

84 lines
3.3 KiB
JavaScript

/**
* Migration to create workflow task inbox tables
*/
exports.up = async function(knex) {
// Create workflow_task_definitions table
await knex.schema.createTable('workflow_task_definitions', (table) => {
table.string('task_definition_id').primary();
table.string('tenant').notNullable();
table.string('task_type', 100).notNullable();
table.string('name').notNullable();
table.text('description');
table.string('form_id').notNullable();
table.string('default_priority', 50).defaultTo('medium');
table.integer('default_sla_days').defaultTo(3);
table.timestamp('created_at').notNullable().defaultTo(knex.fn.now());
table.timestamp('updated_at').notNullable().defaultTo(knex.fn.now());
// Add unique constraint for tenant and task_type
table.unique(['tenant', 'task_type']);
// Add foreign key to form_definitions
table.foreign('form_id').references('form_id').inTable('workflow_form_definitions');
});
// Create workflow_tasks table
await knex.schema.createTable('workflow_tasks', (table) => {
table.string('task_id').primary();
table.string('tenant').notNullable();
table.string('execution_id').notNullable();
table.string('event_id');
table.string('task_definition_id').notNullable();
table.string('title').notNullable();
table.text('description');
table.string('status', 50).notNullable().defaultTo('pending');
table.string('priority', 50).notNullable().defaultTo('medium');
table.timestamp('due_date');
table.jsonb('context_data');
table.jsonb('assigned_roles');
table.jsonb('assigned_users');
table.timestamp('created_at').notNullable().defaultTo(knex.fn.now());
table.timestamp('updated_at').notNullable().defaultTo(knex.fn.now());
table.string('created_by');
table.timestamp('claimed_at');
table.string('claimed_by');
table.timestamp('completed_at');
table.string('completed_by');
table.jsonb('response_data');
// Add foreign key to task_definitions
table.foreign('task_definition_id').references('task_definition_id').inTable('workflow_task_definitions');
// Add indexes for common queries
table.index(['tenant', 'status']);
table.index(['tenant', 'execution_id']);
table.index(['tenant', 'due_date']);
});
// Create workflow_task_history table for audit trail
await knex.schema.createTable('workflow_task_history', (table) => {
table.string('history_id').primary();
table.string('task_id').notNullable();
table.string('tenant').notNullable();
table.string('action', 50).notNullable();
table.string('from_status', 50);
table.string('to_status', 50);
table.string('user_id');
table.timestamp('timestamp').notNullable().defaultTo(knex.fn.now());
table.jsonb('details');
// Add foreign key to tasks
table.foreign('task_id').references('task_id').inTable('workflow_tasks').onDelete('CASCADE');
// Add index for task_id
table.index(['tenant', 'task_id']);
});
};
exports.down = async function(knex) {
// Drop tables in reverse order to handle foreign key constraints
await knex.schema.dropTableIfExists('workflow_task_history');
await knex.schema.dropTableIfExists('workflow_tasks');
await knex.schema.dropTableIfExists('workflow_task_definitions');
};