#!/usr/bin/env node /** * Schema validation script - checks model definitions without DB connection * * Usage: * node scripts/validate_partner_schema.js [--env ] * * Options: * --env Path to environment file (default: ./environment.env) */ 'use strict'; const path = require('path'); // Parse command line arguments const args = process.argv.slice(2); let envFile = './environment.env'; for (let i = 0; i < args.length; i++) { if (args[i] === '--env' && args[i + 1]) { envFile = args[i + 1]; i++; } } // Load environment variables const envPath = path.resolve(process.cwd(), envFile); console.log(`Loading environment from: ${envPath}`); require('dotenv').config({ path: envPath }); console.log('šŸ” Validating Partner Schema Definitions...\n'); // Check Partner model try { const { Partner, PartnerSystemUser } = require('../model/partner'); console.log('šŸ“‹ Partner Schema Fields:'); const partnerFields = Object.keys(Partner.schema.paths); console.log(' Partner fields:', partnerFields); // Check for removed fields const hasPartnerName = partnerFields.includes('partnerName'); const hasConfiguration = partnerFields.includes('configuration'); console.log(' āœ… partnerName field:', hasPartnerName ? 'FOUND (should be removed)' : 'NOT FOUND (correct)'); console.log(' āœ… configuration field:', hasConfiguration ? 'FOUND (should be removed)' : 'NOT FOUND (correct)'); console.log('\nšŸ“‹ PartnerSystemUser Schema Fields:'); const systemUserFields = Object.keys(PartnerSystemUser.schema.paths); console.log(' PartnerSystemUser fields:', systemUserFields); // Check for field changes const hasCustomer = systemUserFields.includes('customer'); const hasCustomerId = systemUserFields.includes('customerId'); const hasApplicatorId = systemUserFields.includes('applicatorId'); const hasOrganizationId = systemUserFields.includes('organizationId'); const hasAccessToken = systemUserFields.includes('accessToken'); const hasRefreshToken = systemUserFields.includes('refreshToken'); console.log(' āœ… customer field:', hasCustomer ? 'EXISTS (correct)' : 'MISSING'); console.log(' āœ… customerId field:', hasCustomerId ? 'FOUND (should be removed)' : 'NOT FOUND (correct)'); console.log(' āœ… applicatorId field:', hasApplicatorId ? 'FOUND (should be removed)' : 'NOT FOUND (correct)'); console.log(' āœ… organizationId field:', hasOrganizationId ? 'FOUND (should be removed)' : 'NOT FOUND (correct)'); console.log(' āœ… accessToken field:', hasAccessToken ? 'FOUND (should be removed)' : 'NOT FOUND (correct)'); console.log(' āœ… refreshToken field:', hasRefreshToken ? 'FOUND (should be removed)' : 'NOT FOUND (correct)'); console.log('\nšŸŽÆ Validation Results:'); const isPartnerValid = !hasPartnerName && !hasConfiguration; const isSystemUserValid = hasCustomer && !hasCustomerId && !hasApplicatorId && !hasOrganizationId && !hasAccessToken && !hasRefreshToken; if (isPartnerValid && isSystemUserValid) { console.log(' āœ… All schema changes are CORRECT'); console.log(' āœ… Redundant fields have been removed'); console.log(' āœ… Field naming is consistent'); console.log('\nšŸŽ‰ Schema validation PASSED!'); } else { console.log(' āŒ Schema issues detected'); if (!isPartnerValid) console.log(' - Partner schema has redundant fields'); if (!isSystemUserValid) console.log(' - PartnerSystemUser schema has field issues'); console.log('\nāš ļø Schema validation FAILED!'); } } catch (error) { console.error('āŒ Schema validation failed:', error.message); process.exit(1); }