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
88 lines
3.6 KiB
JavaScript
88 lines
3.6 KiB
JavaScript
// server/migrations/20250502181500_add_initial_system_workflows.cjs
|
|
const { v4: uuidv4 } = require('uuid'); // Use require for uuid
|
|
|
|
// Define the specific registration ID for the QBO workflow
|
|
const QBO_REGISTRATION_ID = 'a1b2c3d4-e5f6-7890-1234-567890abcdef'; // Static UUID for this system workflow
|
|
|
|
// Placeholder QBO Workflow Definition (same as in the seed)
|
|
const qboSyncWorkflowDefinition = {
|
|
metadata: {
|
|
name: 'QBO Customer Sync',
|
|
description: 'Syncs customer data with QuickBooks Online.',
|
|
version: '1.0.0',
|
|
author: 'System',
|
|
tags: ['qbo', 'sync', 'customer'],
|
|
},
|
|
executeFn: `
|
|
async function execute(context) {
|
|
console.log('Executing QBO Customer Sync workflow...');
|
|
const customerData = context.eventPayload?.customer;
|
|
if (!customerData) {
|
|
console.warn('No customer data found in event payload.');
|
|
return { success: false, message: 'Missing customer data.' };
|
|
}
|
|
console.log('Syncing customer:', customerData.id);
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
console.log('QBO Customer Sync completed for:', customerData.id);
|
|
return { success: true, message: 'Customer synced successfully.' };
|
|
}
|
|
`,
|
|
};
|
|
|
|
exports.up = async function(knex) { // Changed to exports.up, removed types
|
|
// Check if the registration already exists
|
|
const existingReg = await knex('system_workflow_registrations')
|
|
.where({ registration_id: QBO_REGISTRATION_ID })
|
|
.first();
|
|
|
|
if (!existingReg) {
|
|
// Insert System Workflow Registration
|
|
await knex('system_workflow_registrations').insert([
|
|
{
|
|
registration_id: QBO_REGISTRATION_ID,
|
|
name: qboSyncWorkflowDefinition.metadata.name,
|
|
description: qboSyncWorkflowDefinition.metadata.description,
|
|
category: 'system',
|
|
tags: qboSyncWorkflowDefinition.metadata.tags, // Pass array directly for TEXT[] column
|
|
version: qboSyncWorkflowDefinition.metadata.version,
|
|
status: 'active',
|
|
definition: JSON.stringify(qboSyncWorkflowDefinition), // Keep stringify for object
|
|
created_by: null, // Use null for system user
|
|
created_at: new Date().toISOString(),
|
|
updated_at: new Date().toISOString(),
|
|
},
|
|
]);
|
|
|
|
// Insert System Workflow Version
|
|
await knex('system_workflow_registration_versions').insert([
|
|
{
|
|
version_id: uuidv4(), // Version ID can be dynamic
|
|
registration_id: QBO_REGISTRATION_ID,
|
|
version: qboSyncWorkflowDefinition.metadata.version,
|
|
is_current: true,
|
|
definition: qboSyncWorkflowDefinition.executeFn,
|
|
created_by: null, // Use null for system user
|
|
created_at: new Date().toISOString(),
|
|
// updated_at is handled by trigger in the schema migration
|
|
},
|
|
]);
|
|
console.log('Inserted initial QBO system workflow via migration.');
|
|
} else {
|
|
console.log('QBO system workflow already exists, skipping insertion in migration.');
|
|
}
|
|
};
|
|
|
|
exports.down = async function(knex) { // Changed to exports.down, removed types
|
|
// Remove the specific system workflow added by this migration
|
|
// Also remove any potential attachments to avoid foreign key issues if attachments were added elsewhere
|
|
await knex('system_workflow_event_attachments')
|
|
.where({ workflow_id: QBO_REGISTRATION_ID })
|
|
.del();
|
|
await knex('system_workflow_registration_versions')
|
|
.where({ registration_id: QBO_REGISTRATION_ID })
|
|
.del();
|
|
await knex('system_workflow_registrations')
|
|
.where({ registration_id: QBO_REGISTRATION_ID })
|
|
.del();
|
|
console.log('Removed QBO system workflow via migration rollback.');
|
|
}; |