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
66 lines
2.7 KiB
JavaScript
66 lines
2.7 KiB
JavaScript
/**
|
|
* This migration updates the billing_method column in service_catalog and service_types tables:
|
|
* 1. Drops ALL check constraints on billing_method columns
|
|
* 2. Changes column type to TEXT with no constraints
|
|
* 3. Migrates existing 'per_unit' values to 'usage'
|
|
*/
|
|
|
|
exports.up = async function(knex) {
|
|
// Drop ALL possible check constraints on service_catalog
|
|
await knex.raw('ALTER TABLE service_catalog DROP CONSTRAINT IF EXISTS billing_method_check');
|
|
await knex.raw('ALTER TABLE service_catalog DROP CONSTRAINT IF EXISTS service_catalog_billing_method_check');
|
|
|
|
// Drop ALL possible check constraints on service_types
|
|
await knex.raw('ALTER TABLE service_types DROP CONSTRAINT IF EXISTS billing_method_check');
|
|
await knex.raw('ALTER TABLE service_types DROP CONSTRAINT IF EXISTS service_types_billing_method_check');
|
|
|
|
// Change service_catalog.billing_method to TEXT (no constraints)
|
|
await knex.raw('ALTER TABLE service_catalog ALTER COLUMN billing_method TYPE TEXT');
|
|
|
|
// Change service_types.billing_method to TEXT (no constraints)
|
|
await knex.raw('ALTER TABLE service_types ALTER COLUMN billing_method TYPE TEXT');
|
|
|
|
// NOW migrate existing data: change 'per_unit' to 'usage'
|
|
await knex('service_catalog')
|
|
.where('billing_method', 'per_unit')
|
|
.update({ billing_method: 'usage' });
|
|
|
|
await knex('service_types')
|
|
.where('billing_method', 'per_unit')
|
|
.update({ billing_method: 'usage' });
|
|
|
|
const [{ count: serviceCatalogResidualCount }] = await knex('service_catalog')
|
|
.where('billing_method', 'per_unit')
|
|
.count('* as count');
|
|
const [{ count: serviceTypesResidualCount }] = await knex('service_types')
|
|
.where('billing_method', 'per_unit')
|
|
.count('* as count');
|
|
|
|
if (Number(serviceCatalogResidualCount) > 0 || Number(serviceTypesResidualCount) > 0) {
|
|
throw new Error(
|
|
`Billing method normalization failed; residual per_unit rows remain (service_catalog=${serviceCatalogResidualCount}, service_types=${serviceTypesResidualCount})`
|
|
);
|
|
}
|
|
};
|
|
|
|
exports.down = async function(knex) {
|
|
// Revert data migration: change 'usage' back to 'per_unit'
|
|
await knex('service_catalog')
|
|
.where('billing_method', 'usage')
|
|
.update({ billing_method: 'per_unit' });
|
|
|
|
await knex('service_types')
|
|
.where('billing_method', 'usage')
|
|
.update({ billing_method: 'per_unit' });
|
|
|
|
// Revert column type changes
|
|
// Note: If there were specific enum constraints before, they would need to be re-added here
|
|
await knex.schema.alterTable('service_catalog', function(table) {
|
|
table.text('billing_method').notNullable().alter();
|
|
});
|
|
|
|
await knex.schema.alterTable('service_types', function(table) {
|
|
table.text('billing_method').notNullable().alter();
|
|
});
|
|
};
|