PSA/server/migrations/20250208103014_update_invoice_date_columns.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.2 KiB
JavaScript

/**
* Update invoice date columns to use appropriate date types
* invoice_date and due_date should be date type since they represent business days
* created_at, updated_at, and finalized_at remain timestamptz for audit purposes
*/
exports.up = function(knex) {
return knex.schema.alterTable('invoices', function(table) {
// First create new columns of type date
knex.raw('ALTER TABLE invoices ADD COLUMN invoice_date_new date');
knex.raw('ALTER TABLE invoices ADD COLUMN due_date_new date');
// Convert existing data
knex.raw(`
UPDATE invoices
SET invoice_date_new = invoice_date::date,
due_date_new = due_date::date
`);
// Drop old columns and rename new ones
knex.raw('ALTER TABLE invoices DROP COLUMN invoice_date');
knex.raw('ALTER TABLE invoices DROP COLUMN due_date');
knex.raw('ALTER TABLE invoices RENAME COLUMN invoice_date_new TO invoice_date');
knex.raw('ALTER TABLE invoices RENAME COLUMN due_date_new TO due_date');
// Add NOT NULL constraints back
knex.raw('ALTER TABLE invoices ALTER COLUMN invoice_date SET NOT NULL');
knex.raw('ALTER TABLE invoices ALTER COLUMN due_date SET NOT NULL');
});
};
exports.down = function(knex) {
return knex.schema.alterTable('invoices', function(table) {
// First create new columns of type timestamptz
knex.raw('ALTER TABLE invoices ADD COLUMN invoice_date_old timestamp with time zone');
knex.raw('ALTER TABLE invoices ADD COLUMN due_date_old timestamp with time zone');
// Convert existing data
knex.raw(`
UPDATE invoices
SET invoice_date_old = invoice_date::timestamp with time zone,
due_date_old = due_date::timestamp with time zone
`);
// Drop old columns and rename new ones
knex.raw('ALTER TABLE invoices DROP COLUMN invoice_date');
knex.raw('ALTER TABLE invoices DROP COLUMN due_date');
knex.raw('ALTER TABLE invoices RENAME COLUMN invoice_date_old TO invoice_date');
knex.raw('ALTER TABLE invoices RENAME COLUMN due_date_old TO due_date');
// Add NOT NULL constraints back
knex.raw('ALTER TABLE invoices ALTER COLUMN invoice_date SET NOT NULL');
knex.raw('ALTER TABLE invoices ALTER COLUMN due_date SET NOT NULL');
});
};