metis-desk/modules/resources/src/api/infrastructure/persistence/network-share-migration.ts

23 lines
1.4 KiB
TypeScript
Raw Normal View History

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`);
}