PSA/server/migrations/20250917130000_create_itil_standard_priorities.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

162 lines
4.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Migration to populate ITIL standard priorities in standard_priorities table
* ITIL priorities are calculated from Impact × Urgency matrix
* This migration adds the standard ITIL priorities to the reference table
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function(knex) {
// ITIL standard priority definitions
// Using order numbers 100-104 to separate from custom priorities (1-4)
const itilPriorities = [
{
priority_name: 'P1 - Critical',
color: '#DC2626', // Red
order_number: 100,
is_itil_standard: true,
itil_priority_level: 1,
item_type: 'ticket'
},
{
priority_name: 'P2 - High',
color: '#EA580C', // Orange
order_number: 101,
is_itil_standard: true,
itil_priority_level: 2,
item_type: 'ticket'
},
{
priority_name: 'P3 - Medium',
color: '#F59E0B', // Amber
order_number: 102,
is_itil_standard: true,
itil_priority_level: 3,
item_type: 'ticket'
},
{
priority_name: 'P4 - Low',
color: '#3B82F6', // Blue
order_number: 103,
is_itil_standard: true,
itil_priority_level: 4,
item_type: 'ticket'
},
{
priority_name: 'P5 - Planning',
color: '#6B7280', // Gray
order_number: 104,
is_itil_standard: true,
itil_priority_level: 5,
item_type: 'ticket'
}
];
// Insert each priority
for (const priority of itilPriorities) {
// Check if already exists (by name and item_type)
const existing = await knex('standard_priorities')
.where('priority_name', priority.priority_name)
.where('item_type', priority.item_type)
.first();
if (existing) {
// Update existing to mark as ITIL standard
await knex('standard_priorities')
.where('priority_id', existing.priority_id)
.update({
is_itil_standard: true,
itil_priority_level: priority.itil_priority_level,
color: priority.color,
order_number: priority.order_number,
updated_at: knex.fn.now()
});
} else {
// Insert new priority
await knex('standard_priorities').insert({
priority_id: knex.raw('gen_random_uuid()'),
priority_name: priority.priority_name,
color: priority.color,
order_number: priority.order_number,
is_itil_standard: priority.is_itil_standard,
itil_priority_level: priority.itil_priority_level,
item_type: priority.item_type,
created_at: knex.fn.now(),
updated_at: knex.fn.now()
});
}
}
// Also ensure we have standard custom priorities for comparison
// Using order numbers 1-4 for custom priorities
const customPriorities = [
{
priority_name: 'Critical',
color: '#EF4444',
order_number: 1,
is_itil_standard: false,
item_type: 'ticket'
},
{
priority_name: 'High',
color: '#F97316',
order_number: 2,
is_itil_standard: false,
item_type: 'ticket'
},
{
priority_name: 'Medium',
color: '#EAB308',
order_number: 3,
is_itil_standard: false,
item_type: 'ticket'
},
{
priority_name: 'Low',
color: '#3B82F6',
order_number: 4,
is_itil_standard: false,
item_type: 'ticket'
}
];
// Insert custom priorities if they don't exist
for (const priority of customPriorities) {
const existing = await knex('standard_priorities')
.where('priority_name', priority.priority_name)
.where('item_type', priority.item_type)
.where('is_itil_standard', false)
.first();
if (!existing) {
await knex('standard_priorities').insert({
priority_id: knex.raw('gen_random_uuid()'),
priority_name: priority.priority_name,
color: priority.color,
order_number: priority.order_number,
is_itil_standard: priority.is_itil_standard,
itil_priority_level: null,
item_type: priority.item_type,
created_at: knex.fn.now(),
updated_at: knex.fn.now()
});
}
}
};
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function(knex) {
// Remove ITIL standard priorities
await knex('standard_priorities')
.where('is_itil_standard', true)
.del();
// Reset the is_itil_standard flag on remaining priorities
await knex('standard_priorities')
.update({
is_itil_standard: false,
itil_priority_level: null
});
};