PSA/server/migrations/20250811143629_remove_email_domain_registration.cjs
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

64 lines
2.8 KiB
JavaScript

// Disable transaction for Citus compatibility
// undistribute_table() and DROP TABLE CASCADE are not allowed in transactions
exports.config = { transaction: false };
exports.up = async function(knex) {
// Drop tables related to email domain registration
// These were used for allowing self-registration based on email domains
// Removed for security reasons - registration now only allowed for existing contacts
// Simple and straightforward approach for Citus:
// 1. Drop known foreign keys from pending_registrations (the only distributed table with FKs)
// 2. Undistribute pending_registrations if it's distributed
// 3. Drop all three tables with CASCADE
// Drop foreign keys from pending_registrations (we know these exist from the query results)
await knex.raw('ALTER TABLE IF EXISTS pending_registrations DROP CONSTRAINT IF EXISTS pending_registrations_tenant_foreign');
await knex.raw('ALTER TABLE IF EXISTS pending_registrations DROP CONSTRAINT IF EXISTS pending_registrations_tenant_company_id_foreign');
// Undistribute pending_registrations if it's distributed (required for Citus)
// First check if we're using Citus by checking if the undistribute_table function exists
// NOTE: These are system catalog queries that don't need tenant conditions
try {
const citusCheck = await knex.raw(`
SELECT EXISTS (
SELECT 1 FROM pg_proc
WHERE proname = 'undistribute_table'
) as has_citus
`);
if (citusCheck.rows[0].has_citus) {
// We have Citus, check if the table is distributed
// NOTE: pg_dist_partition is a Citus system catalog, no tenant needed
const distCheck = await knex.raw(`
SELECT EXISTS (
SELECT 1 FROM pg_dist_partition
WHERE logicalrelid = 'pending_registrations'::regclass
) as is_distributed
`);
if (distCheck.rows[0].is_distributed) {
// Table is distributed, undistribute it
await knex.raw('SELECT undistribute_table(\'pending_registrations\')');
// Successfully undistributed pending_registrations table
}
}
} catch (err) {
// Any error here is not critical - continue with dropping tables
// Note: Citus check/undistribute step skipped
}
// Now drop all tables with CASCADE to handle any remaining dependencies
await knex.raw('DROP TABLE IF EXISTS company_email_settings CASCADE');
await knex.raw('DROP TABLE IF EXISTS verification_tokens CASCADE');
await knex.raw('DROP TABLE IF EXISTS pending_registrations CASCADE');
// Successfully dropped email domain registration tables
};
exports.down = async function(knex) {
// NO-OP: Security-driven removal should not be rolled back
// These tables were removed for security reasons and should not be recreated
// Email domain registration tables were removed for security reasons and will not be recreated
return;
};