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
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
90 lines
3.0 KiB
JavaScript
90 lines
3.0 KiB
JavaScript
exports.seed = async function(knex) {
|
|
// Get the tenant first
|
|
const tenant = await knex('tenants').select('tenant').first();
|
|
if (!tenant) {
|
|
console.warn('No tenant found, skipping inbound ticket defaults seeding.');
|
|
return;
|
|
}
|
|
const tenantId = tenant.tenant;
|
|
|
|
// Helper function to get IDs for default configuration
|
|
const getDefaultId = async (table, filters, idColumn) => {
|
|
const result = await knex(table).where({ tenant: tenantId, ...filters }).select(idColumn).first();
|
|
if (!result) {
|
|
console.warn(`Warning: Could not find default ID in table '${table}' for filters:`, filters);
|
|
return null;
|
|
}
|
|
return result[idColumn];
|
|
};
|
|
|
|
const defaultBoardId =
|
|
await getDefaultId('boards', { is_default: true }, 'board_id') ||
|
|
await getDefaultId('boards', {}, 'board_id');
|
|
|
|
const defaultStatusId = defaultBoardId
|
|
? (
|
|
await getDefaultId('statuses', { board_id: defaultBoardId, is_default: true, status_type: 'ticket' }, 'status_id') ||
|
|
await getDefaultId('statuses', { board_id: defaultBoardId, status_type: 'ticket' }, 'status_id')
|
|
)
|
|
: null;
|
|
|
|
const [
|
|
defaultPriorityId,
|
|
defaultClientId
|
|
] = await Promise.all([
|
|
getDefaultId('priorities', { item_type: 'ticket' }, 'priority_id'),
|
|
getDefaultId('clients', { client_name: 'Wonderland' }, 'client_id') ||
|
|
getDefaultId('clients', {}, 'client_id')
|
|
]);
|
|
|
|
if (!defaultBoardId || !defaultStatusId || !defaultPriorityId || !defaultClientId) {
|
|
console.warn('Could not find required default values for ticket defaults. Skipping seed.');
|
|
return;
|
|
}
|
|
|
|
// Backfill historical seeded rows where client_id was null.
|
|
const updatedDefaults = await knex('inbound_ticket_defaults')
|
|
.where({ tenant: tenantId })
|
|
.whereNull('client_id')
|
|
.update({
|
|
client_id: defaultClientId,
|
|
updated_at: knex.fn.now()
|
|
});
|
|
if (updatedDefaults > 0) {
|
|
console.log(`✅ Backfilled client_id for ${updatedDefaults} inbound ticket defaults row(s).`);
|
|
}
|
|
|
|
// Check if default already exists
|
|
const existingDefault = await knex('inbound_ticket_defaults')
|
|
.where({ tenant: tenantId, short_name: 'email-general' })
|
|
.first();
|
|
|
|
if (existingDefault) {
|
|
console.log('Default inbound ticket defaults already exist, skipping.');
|
|
return;
|
|
}
|
|
|
|
// Create the default inbound ticket defaults configuration
|
|
await knex('inbound_ticket_defaults').insert({
|
|
id: knex.raw('gen_random_uuid()'),
|
|
tenant: tenantId,
|
|
short_name: 'email-general',
|
|
display_name: 'General Email Support',
|
|
description: 'Default configuration for tickets created from email processing',
|
|
board_id: defaultBoardId,
|
|
status_id: defaultStatusId,
|
|
priority_id: defaultPriorityId,
|
|
client_id: defaultClientId,
|
|
entered_by: null, // System-generated tickets
|
|
category_id: null,
|
|
subcategory_id: null,
|
|
location_id: null,
|
|
is_default: true, // Mark as the default for this tenant
|
|
is_active: true,
|
|
created_at: knex.fn.now(),
|
|
updated_at: knex.fn.now()
|
|
});
|
|
|
|
console.log('✅ Created default inbound ticket defaults configuration');
|
|
};
|