PSA/server/scripts/rollback-tenant.ts
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

71 lines
1.8 KiB
JavaScript

#!/usr/bin/env node
/**
* CLI script to rollback/delete a tenant
*/
import { rollbackTenant } from '../../ee/server/src/lib/testing/tenant-creation';
import knex from 'knex';
import { parse } from 'ts-command-line-args';
import * as dotenv from 'dotenv';
import * as path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Load environment variables
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
interface Args {
tenantId: string;
help?: boolean;
}
const args = parse<Args>(
{
tenantId: { type: String, description: 'Tenant ID to rollback/delete' },
help: { type: Boolean, optional: true, alias: 'h', description: 'Show help' }
},
{
helpArg: 'help',
headerContentSections: [
{
header: 'Rollback Tenant',
content: 'Deletes a tenant and all associated data'
}
]
}
);
async function main() {
// Create database connection
// For local development, use localhost instead of Docker service names
const isDocker = process.env.DOCKER_ENV === 'true';
const dbHost = isDocker ? (process.env.PGBOUNCER_HOST || 'pgbouncer') : 'localhost';
const dbPort = isDocker ? (process.env.PGBOUNCER_PORT || '6432') : '5432';
const db = knex({
client: 'pg',
connection: {
host: dbHost,
port: parseInt(dbPort),
database: process.env.DB_NAME_SERVER || 'server',
user: process.env.DB_USER || 'postgres',
password: process.env.DB_PASSWORD_ADMIN || process.env.POSTGRES_PASSWORD || 'abcd1234!'
}
});
try {
await rollbackTenant(db, args.tenantId);
console.log('\n✅ Tenant rolled back successfully!');
} catch (error) {
console.error('\n❌ Failed to rollback tenant:', error);
process.exit(1);
} finally {
await db.destroy();
}
}
main();