metis-desk/modules/resources/src/api/infrastructure/persistence/network-share-migration.ts
David fe6ec361b7 feat(companies): vincular identidades locales a activos y añadir cuenta de acceso a FolderMapping
- Asociar entornos locales con activos y conservar su trazabilidad.
- Registrar la cuenta de acceso del mapeo con historial de cambios.
- Calcular cobertura documental específica sin alterar la cobertura general.
- Añadir migraciones, validaciones, endpoints protegidos, pruebas y documentación.
2026-10-21 11:25:23 +02:00

23 lines
1.4 KiB
TypeScript

import type { Sequelize } from "sequelize";
/** Solo crea estructura: las carpetas históricas requieren conversión explícita. */
export async function migrateNetworkShares(database: Sequelize) {
await database.query(`CREATE TABLE IF NOT EXISTS resource_network_shares (
resourceId CHAR(36) BINARY NOT NULL PRIMARY KEY,
companyId CHAR(36) BINARY NOT NULL,
templateId CHAR(36) BINARY NOT NULL,
templateKey VARCHAR(100) NOT NULL DEFAULT 'template:shared_folder',
protocol VARCHAR(10) NOT NULL DEFAULT 'smb',
normalizedAddress VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
activeAddress VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL,
UNIQUE KEY network_share_active_address (companyId,activeAddress),
UNIQUE KEY network_share_company (resourceId,companyId),
CONSTRAINT network_share_protocol CHECK (protocol='smb'),
CONSTRAINT network_share_template CHECK (templateKey='template:shared_folder'),
CONSTRAINT network_share_address CHECK (CHAR_LENGTH(normalizedAddress)>0),
CONSTRAINT network_share_active CHECK (activeAddress IS NULL OR BINARY activeAddress=BINARY normalizedAddress),
CONSTRAINT network_share_resource FOREIGN KEY (resourceId,companyId,templateId) REFERENCES resources(id,companyId,templateId),
CONSTRAINT network_share_definition FOREIGN KEY (templateId,templateKey) REFERENCES resource_definitions(id,stockKey)
) ENGINE=InnoDB`);
}