PSA/server/migrations/20260428120000_create_workflow_step_usage_periods.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

/**
* Create tenant-scoped workflow step quota usage counters by billing period.
*/
exports.up = async function up(knex) {
await knex.schema.createTable('workflow_step_usage_periods', (table) => {
table.uuid('tenant').notNullable();
table.timestamp('period_start', { useTz: true }).notNullable();
table.timestamp('period_end', { useTz: true }).notNullable();
table.text('period_source').notNullable();
table.uuid('stripe_subscription_id');
table.integer('effective_limit');
table.integer('used_count').notNullable().defaultTo(0);
table.text('limit_source').notNullable();
table.text('tier').notNullable();
table.jsonb('metadata_json');
table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(knex.fn.now());
table.timestamp('updated_at', { useTz: true }).notNullable().defaultTo(knex.fn.now());
table.primary(['tenant', 'period_start', 'period_end']);
table.foreign('tenant').references('tenants.tenant').onDelete('CASCADE');
table.index(['tenant', 'period_end'], 'idx_workflow_step_usage_periods_tenant_period_end');
table.index(['period_end'], 'idx_workflow_step_usage_periods_period_end');
});
await knex.schema.raw(`
ALTER TABLE workflow_step_usage_periods
ADD CONSTRAINT workflow_step_usage_periods_period_bounds_check
CHECK (period_start < period_end)
`);
await knex.schema.raw(`
ALTER TABLE workflow_step_usage_periods
ADD CONSTRAINT workflow_step_usage_periods_used_count_check
CHECK (used_count >= 0)
`);
await knex.schema.raw(`
ALTER TABLE workflow_step_usage_periods
ADD CONSTRAINT workflow_step_usage_periods_effective_limit_check
CHECK (effective_limit IS NULL OR effective_limit > 0)
`);
const dbUserServer = process.env.DB_USER_SERVER;
if (dbUserServer) {
const escapedUser = dbUserServer.replace(/"/g, '""');
await knex.schema.raw(`
GRANT ALL PRIVILEGES ON TABLE workflow_step_usage_periods TO "${escapedUser}";
`);
}
};
exports.down = async function down(knex) {
await knex.schema.dropTableIfExists('workflow_step_usage_periods');
};