PSA/server/scripts/verify-plan-service-migration.js
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

170 lines
5.6 KiB
JavaScript

#!/usr/bin/env node
/**
* Script to verify the plan service configuration migration
*
* This script checks:
* 1. All plan services have been migrated to the new tables
* 2. Configuration types match the original plan types
* 3. All required data is present in the type-specific configuration tables
*
* Usage: node scripts/verify-plan-service-migration.js
*/
const knex = require('knex');
const config = require('../knexfile.cjs');
async function verifyMigration() {
console.log('Verifying plan service configuration migration...');
// Create knex instance
const db = knex(config.development);
try {
// Get all tenants
const tenants = await db('tenants').select('tenant');
let totalPlans = 0;
let totalOldServices = 0;
let totalNewConfigurations = 0;
let missingConfigurations = 0;
let typeMismatches = 0;
// Process each tenant separately
for (const { tenant } of tenants) {
console.log(`\nVerifying tenant: ${tenant}`);
// Get all billing plans for this tenant
const plans = await db('contract_lines')
.where({ tenant })
.select('*');
totalPlans += plans.length;
console.log(`Found ${plans.length} billing plans`);
// Process each plan
for (const plan of plans) {
// Get original services
const oldServices = await db('plan_services')
.where({
'contract_line_id': plan.contract_line_id,
'tenant': tenant
})
.select('*');
totalOldServices += oldServices.length;
// Get new configurations
const newConfigurations = await db('plan_service_configuration')
.where({
'contract_line_id': plan.contract_line_id,
'tenant': tenant
})
.select('*');
totalNewConfigurations += newConfigurations.length;
console.log(`Plan ${plan.contract_line_name} (${plan.contract_line_id}): ${oldServices.length} old services, ${newConfigurations.length} new configurations`);
// Check for missing configurations
if (oldServices.length !== newConfigurations.length) {
console.log(` WARNING: Service count mismatch for plan ${plan.contract_line_name}`);
missingConfigurations += Math.abs(oldServices.length - newConfigurations.length);
}
// Check configuration types
for (const config of newConfigurations) {
// Verify configuration type matches plan type
if (plan.contract_line_type !== config.configuration_type) {
console.log(` WARNING: Type mismatch for service ${config.service_id} in plan ${plan.contract_line_name}`);
console.log(` Plan type: ${plan.contract_line_type}, Configuration type: ${config.configuration_type}`);
typeMismatches++;
}
// Verify type-specific configuration exists
let typeConfigExists = false;
switch (config.configuration_type) {
case 'Fixed':
const fixedConfig = await db('plan_service_fixed_config')
.where({
'config_id': config.config_id,
'tenant': tenant
})
.first();
typeConfigExists = !!fixedConfig;
break;
case 'Hourly':
const hourlyConfig = await db('plan_service_hourly_config')
.where({
'config_id': config.config_id,
'tenant': tenant
})
.first();
typeConfigExists = !!hourlyConfig;
break;
case 'Usage':
const usageConfig = await db('plan_service_usage_config')
.where({
'config_id': config.config_id,
'tenant': tenant
})
.first();
typeConfigExists = !!usageConfig;
break;
case 'Bucket':
const bucketConfig = await db('plan_service_bucket_config')
.where({
'config_id': config.config_id,
'tenant': tenant
})
.first();
typeConfigExists = !!bucketConfig;
break;
}
if (!typeConfigExists) {
console.log(` WARNING: Missing type-specific configuration for service ${config.service_id} in plan ${plan.contract_line_name}`);
}
}
}
}
// Print summary
console.log('\n=== Migration Verification Summary ===');
console.log(`Total plans: ${totalPlans}`);
console.log(`Total old services: ${totalOldServices}`);
console.log(`Total new configurations: ${totalNewConfigurations}`);
if (missingConfigurations > 0) {
console.log(`WARNING: ${missingConfigurations} configurations are missing`);
} else {
console.log('All services have been migrated successfully');
}
if (typeMismatches > 0) {
console.log(`WARNING: ${typeMismatches} type mismatches found`);
} else {
console.log('All configuration types match the original plan types');
}
if (missingConfigurations === 0 && typeMismatches === 0) {
console.log('\nMigration verification PASSED');
} else {
console.log('\nMigration verification FAILED');
}
} catch (error) {
console.error('Error verifying migration:', error);
process.exit(1);
} finally {
// Close the database connection
await db.destroy();
}
}
// Run the verification function
verifyMigration();