PSA/server/migrations/20250217204649_update_contact_based_comments.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

55 lines
2.1 KiB
JavaScript

const { getCommentTenants } = require('./20250217204647_get_comment_tenants.cjs');
exports.up = async function(knex) {
await knex.raw(`
DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM pg_extension WHERE extname = 'citus'
) THEN
EXECUTE 'SET citus.multi_shard_modify_mode TO ''sequential''';
END IF;
END $$;
`);
await knex.transaction(async (trx) => {
const tenants = await getCommentTenants(knex);
// Process each tenant separately to maintain proper sharding
for (const tenant of tenants) {
// Get comments with contact info for this tenant
// --- Query Commented Out: Relies on c.contact_id which was dropped in a previous migration ---
/*
const contactComments = await knex('comments as c')
.select('c.comment_id', 'c.contact_id', 'c.tenant', 'u.user_id') // c.contact_id does not exist
.leftJoin('users as u', function() {
this.on('u.contact_id', '=', 'c.contact_id') // c.contact_id does not exist
.andOn('u.tenant', '=', 'c.tenant');
})
.where('c.tenant', tenant)
.andWhere('u.user_type', 'client')
// Update contact-based comments
for (const comment of contactComments) {
if (!comment.contact_id) continue; // c.contact_id does not exist
await knex('comments')
.where('comment_id', comment.comment_id)
.andWhere('tenant', tenant)
.update({
user_id: comment.user_id, // This might be incorrect if user_id wasn't populated before contact_id drop
author_type: 'client' // This was likely handled by migration 20250217202724
});
}
*/
// --- End Commented Out Block ---
console.log(`Skipping potentially redundant contact-based comment update for tenant ${tenant} in migration 20250217204649 as contact_id column no longer exists.`);
}
});
};
exports.down = async function(knex) {
// No need for down migration as the data changes are handled
// in the column changes migration's down function
};
exports.config = { transaction: false };