use vn; -- Crear columna en deviceProduction ALTER TABLE vn.deviceProduction ADD stateFk varchar(50) DEFAULT 'idle'; -- Crear columna en deviceLog ALTER TABLE vn.deviceLog ADD deviceProductionFk INT(10) NULL; -- vn.deviceProductionLog definition CREATE TABLE `deviceProductionLog` ( `id` int(11) NOT NULL AUTO_INCREMENT, `originFk` int(11) NOT NULL, `userFk` int(10) unsigned DEFAULT NULL, `deviceProduction` int(10) unsigned NOT NULL, `action` set('insert','update','delete','retired') COLLATE utf8mb3_unicode_ci NOT NULL, `created` timestamp NULL DEFAULT current_timestamp(), `oldInstance` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `newInstance` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `changedModel` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `changedModelId` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -- Preguntar sobre elimnar estos campos ALTER TABLE vn.deviceProduction DROP FOREIGN KEY departmentFgn; ALTER TABLE vn.deviceProduction DROP COLUMN departmentFk; ALTER TABLE vn.deviceProduction DROP COLUMN isOutOfService; -- Crear tabla CREATE TABLE vn.deviceProductionState ( code varchar(50) NOT NULL, description varchar(50) NOT NULL, CONSTRAINT deviceProductionState_PK PRIMARY KEY (code) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -- Rellenar tabla INSERT INTO vn.deviceProductionState (code, description) VALUES('idle', 'inactivo'); INSERT INTO vn.deviceProductionState (code, description) VALUES('active', 'activo'); INSERT INTO vn.deviceProductionState (code, description) VALUES('maintenance', 'mantenimiento'); INSERT INTO vn.deviceProductionState (code, description) VALUES('retired', 'retirada'); -- FK deviceProductionStateFk ALTER TABLE vn.deviceProduction ADD CONSTRAINT deviceProduction_FK FOREIGN KEY (stateFk) REFERENCES vn.deviceProductionState(code);