godcrm/backend/database/migrations/knex/017_add_documents_columns.js
GOD CRM Release f89e074dd1
Some checks failed
CI / Lint / Typecheck / Test / Build (push) Has been cancelled
CI / PostgreSQL Integration Tests (push) Has been cancelled
GOD CRM — public scrubbed snapshot
Governed substrate for autonomous agents: scoped identity (passports),
audited actions, MCP workspace. Infra IPs and secrets redacted for public release.
2026-08-10 04:01:45 +03:00

36 lines
1.6 KiB
JavaScript

// backend/database/migrations/knex/017_add_documents_columns.js
// Adds columns for Documents widget v4 (folder_path, table_type, base_id, created_by)
/**
* @param {import('knex').Knex} knex
*/
export async function up(knex) {
// Add documents-related columns to universal_tables.
// Idempotent: on databases where migration 005 already created these columns
// (post-hoc edit drift), skip the ones that exist so a from-scratch run passes.
const has = {
folder_path: await knex.schema.hasColumn('universal_tables', 'folder_path'),
table_type: await knex.schema.hasColumn('universal_tables', 'table_type'),
base_id: await knex.schema.hasColumn('universal_tables', 'base_id'),
created_by: await knex.schema.hasColumn('universal_tables', 'created_by'),
};
if (Object.values(has).every(Boolean)) return;
await knex.schema.alterTable('universal_tables', (table) => {
if (!has.folder_path) table.text('folder_path'); // Path like 'databases/documents/'
if (!has.table_type) table.string('table_type', 50); // 'documents_registry' | 'documents_atoms' | null
if (!has.base_id) table.string('base_id', 50); // Unique base identifier
if (!has.created_by) table.integer('created_by').unsigned(); // User who created the table
});
}
/**
* @param {import('knex').Knex} knex
*/
export async function down(knex) {
await knex.schema.alterTable('universal_tables', (table) => {
table.dropColumn('folder_path');
table.dropColumn('table_type');
table.dropColumn('base_id');
table.dropColumn('created_by');
});
}