PSA/server/migrations/20241224010921_rename_storage_tables.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

96 lines
3.7 KiB
JavaScript

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function(knex) {
// Drop existing foreign key constraints
await knex.schema.table('file_stores', table => {
table.dropForeign(['tenant', 'deleted_by']);
table.dropForeign(['tenant', 'uploaded_by']);
table.dropForeign(['tenant']);
});
await knex.schema.table('storage_buckets', table => {
table.dropForeign(['tenant', 'provider_id']);
table.dropForeign(['tenant']);
});
// Rename tables and columns
await knex.schema.renameTable('file_stores', 'external_files');
await knex.schema.renameTable('storage_buckets', 'storage_configurations');
// Rename columns in external_files (previously file_stores)
await knex.schema.table('external_files', table => {
table.renameColumn('uploaded_by', 'uploaded_by_id');
table.renameColumn('deleted_by', 'deleted_by_id');
});
// Rename columns in storage_configurations (previously storage_buckets)
await knex.schema.table('storage_configurations', table => {
table.renameColumn('bucket_id', 'configuration_id');
table.renameColumn('bucket_name', 'name');
table.renameColumn('bucket_path', 'path');
});
// Recreate foreign key constraints for external_files
await knex.schema.table('external_files', table => {
table.foreign(['tenant', 'deleted_by_id']).references(['tenant', 'user_id']).inTable('users');
table.foreign(['tenant', 'uploaded_by_id']).references(['tenant', 'user_id']).inTable('users');
table.foreign(['tenant']).references('tenant').inTable('tenants');
});
// Recreate foreign key constraints for storage_configurations
await knex.schema.table('storage_configurations', table => {
table.foreign(['tenant', 'provider_id']).references(['tenant', 'provider_id']).inTable('storage_providers');
table.foreign(['tenant']).references('tenant').inTable('tenants');
});
};
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function(knex) {
// Drop foreign key constraints
await knex.schema.table('external_files', table => {
table.dropForeign(['tenant', 'deleted_by_id']);
table.dropForeign(['tenant', 'uploaded_by_id']);
table.dropForeign(['tenant']);
});
await knex.schema.table('storage_configurations', table => {
table.dropForeign(['tenant', 'provider_id']);
table.dropForeign(['tenant']);
});
// Rename columns back in external_files
await knex.schema.table('external_files', table => {
table.renameColumn('uploaded_by_id', 'uploaded_by');
table.renameColumn('deleted_by_id', 'deleted_by');
});
// Rename columns back in storage_configurations
await knex.schema.table('storage_configurations', table => {
table.renameColumn('configuration_id', 'bucket_id');
table.renameColumn('name', 'bucket_name');
table.renameColumn('path', 'bucket_path');
});
// Rename tables back
await knex.schema.renameTable('external_files', 'file_stores');
await knex.schema.renameTable('storage_configurations', 'storage_buckets');
// Recreate original foreign key constraints for file_stores
await knex.schema.table('file_stores', table => {
table.foreign(['tenant', 'deleted_by']).references(['tenant', 'user_id']).inTable('users');
table.foreign(['tenant', 'uploaded_by']).references(['tenant', 'user_id']).inTable('users');
table.foreign(['tenant']).references('tenant').inTable('tenants');
});
// Recreate original foreign key constraints for storage_buckets
await knex.schema.table('storage_buckets', table => {
table.foreign(['tenant', 'provider_id']).references(['tenant', 'provider_id']).inTable('storage_providers');
table.foreign(['tenant']).references('tenant').inTable('tenants');
});
};