PSA/server/migrations/20260104120000_add_response_state_to_tickets.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

60 lines
2.1 KiB
JavaScript

/**
* Add response_state field to tickets table
*
* This field tracks who needs to respond next on a ticket:
* - 'awaiting_client': Support has responded, waiting for client
* - 'awaiting_internal': Client has responded, waiting for support
* - null: No response state tracking needed (new tickets, closed tickets)
*
* The field is automatically updated when comments are posted and
* cleared when tickets are closed.
*
* NOTE: This migration modifies a distributed table (tickets) and must run
* outside a transaction to work with Citus.
*/
exports.up = async function(knex) {
// Create the enum type
console.log('Creating ticket_response_state enum type...');
await knex.raw(`
CREATE TYPE ticket_response_state AS ENUM ('awaiting_client', 'awaiting_internal');
`);
// Add the column to tickets table
console.log('Adding response_state column to tickets table...');
await knex.schema.alterTable('tickets', (table) => {
table.specificType('response_state', 'ticket_response_state').nullable();
});
// Add index for filtering queries
// Note: Citus does not support partial indexes on distributed tables,
// so we use a plain multi-column index instead
console.log('Creating index on (tenant, response_state)...');
await knex.raw(`
CREATE INDEX idx_tickets_response_state
ON tickets(tenant, response_state);
`);
console.log('Migration complete: response_state added to tickets');
};
exports.down = async function(knex) {
// Drop the index
console.log('Dropping index idx_tickets_response_state...');
await knex.raw(`DROP INDEX IF EXISTS idx_tickets_response_state;`);
// Drop the column
console.log('Removing response_state column from tickets...');
await knex.schema.alterTable('tickets', (table) => {
table.dropColumn('response_state');
});
// Drop the enum type
console.log('Dropping ticket_response_state enum type...');
await knex.raw(`DROP TYPE IF EXISTS ticket_response_state;`);
console.log('Migration rollback complete');
};
// Required for Citus: ALTER TABLE on distributed tables must run outside a transaction
exports.config = { transaction: false };