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
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
116 lines
3.1 KiB
JavaScript
116 lines
3.1 KiB
JavaScript
const OWNER_CLIENT_FK = 'contracts_owner_client_id_fkey';
|
|
const OWNER_CLIENT_INDEX = 'idx_contracts_tenant_owner_client_id';
|
|
|
|
const ensureSequentialMode = async (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 $$;
|
|
`);
|
|
};
|
|
|
|
const hasColumn = async (knex, tableName, columnName) => {
|
|
try {
|
|
return await knex.schema.hasColumn(tableName, columnName);
|
|
} catch (error) {
|
|
console.warn(`Unable to check column ${columnName} on ${tableName}:`, error);
|
|
return false;
|
|
}
|
|
};
|
|
|
|
const hasConstraint = async (knex, constraintName) => {
|
|
try {
|
|
const row = await knex('pg_constraint')
|
|
.select('conname')
|
|
.where({ conname: constraintName })
|
|
.first();
|
|
return Boolean(row);
|
|
} catch (error) {
|
|
console.warn(`Unable to check constraint ${constraintName}:`, error);
|
|
return false;
|
|
}
|
|
};
|
|
|
|
const hasIndex = async (knex, indexName) => {
|
|
try {
|
|
const row = await knex('pg_indexes')
|
|
.select('indexname')
|
|
.where({ indexname: indexName })
|
|
.first();
|
|
return Boolean(row);
|
|
} catch (error) {
|
|
console.warn(`Unable to check index ${indexName}:`, error);
|
|
return false;
|
|
}
|
|
};
|
|
|
|
exports.up = async function up(knex) {
|
|
await ensureSequentialMode(knex);
|
|
|
|
const tableName = 'contracts';
|
|
const tableExists = await knex.schema.hasTable(tableName);
|
|
if (!tableExists) {
|
|
console.log('⊘ Skipping contract owner migration: contracts table not found');
|
|
return;
|
|
}
|
|
|
|
const ownerClientColumnExists = await hasColumn(knex, tableName, 'owner_client_id');
|
|
if (!ownerClientColumnExists) {
|
|
await knex.schema.alterTable(tableName, (table) => {
|
|
table.uuid('owner_client_id').nullable();
|
|
});
|
|
}
|
|
|
|
if (!await hasIndex(knex, OWNER_CLIENT_INDEX)) {
|
|
await knex.raw(`
|
|
CREATE INDEX IF NOT EXISTS ${OWNER_CLIENT_INDEX}
|
|
ON ${tableName} (tenant, owner_client_id);
|
|
`);
|
|
}
|
|
|
|
if (!await hasConstraint(knex, OWNER_CLIENT_FK)) {
|
|
await knex.raw(`
|
|
ALTER TABLE ${tableName}
|
|
ADD CONSTRAINT ${OWNER_CLIENT_FK}
|
|
FOREIGN KEY (tenant, owner_client_id)
|
|
REFERENCES clients(tenant, client_id);
|
|
`);
|
|
}
|
|
|
|
console.log('✓ Added contracts.owner_client_id for client-owned contract migration');
|
|
};
|
|
|
|
exports.down = async function down(knex) {
|
|
await ensureSequentialMode(knex);
|
|
|
|
const tableName = 'contracts';
|
|
const tableExists = await knex.schema.hasTable(tableName);
|
|
if (!tableExists) {
|
|
console.log('⊘ contracts table not found, nothing to roll back');
|
|
return;
|
|
}
|
|
|
|
if (await hasConstraint(knex, OWNER_CLIENT_FK)) {
|
|
await knex.raw(`ALTER TABLE ${tableName} DROP CONSTRAINT ${OWNER_CLIENT_FK};`);
|
|
}
|
|
|
|
if (await hasIndex(knex, OWNER_CLIENT_INDEX)) {
|
|
await knex.raw(`DROP INDEX IF EXISTS ${OWNER_CLIENT_INDEX};`);
|
|
}
|
|
|
|
if (await hasColumn(knex, tableName, 'owner_client_id')) {
|
|
await knex.schema.alterTable(tableName, (table) => {
|
|
table.dropColumn('owner_client_id');
|
|
});
|
|
}
|
|
|
|
console.log('✓ Removed contracts.owner_client_id');
|
|
};
|
|
|
|
exports.config = { transaction: false };
|