salix/db/versions/10995-navyErica/02-agencyWorkCenterCreate.sql

19 lines
1.0 KiB
MySQL
Raw Normal View History

2024-04-25 07:46:15 +00:00
CREATE TABLE IF NOT EXISTS `vn`.`agencyWorkCenter` (
2024-04-22 15:17:17 +00:00
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`agencyFk` smallint(5) unsigned NOT NULL,
`workCenterFk` int(11) NOT NULL,
`editorFk` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `agencyWorkCenter_unique` (`agencyFk`,`workCenterFk`),
KEY `agencyWorkCenter_workCenter_FK` (`workCenterFk`),
KEY `agencyWorkCenter_user_FK` (`editorFk`),
CONSTRAINT `agencyWorkCenter_agency_FK` FOREIGN KEY (`agencyFk`) REFERENCES `agency` (`id`) ON DELETE CASCADE,
CONSTRAINT `agencyWorkCenter_user_FK` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `agencyWorkCenter_workCenter_FK` FOREIGN KEY (`workCenterFk`) REFERENCES `workCenter` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
2024-04-22 15:17:17 +00:00
INSERT INTO vn.agencyWorkCenter (agencyFk, workCenterFk)
SELECT a.id, wc.id
2024-05-13 09:04:50 +00:00
FROM vn.agency a
JOIN vn.warehouse w ON w.id = a.warehouseFk
JOIN vn.workCenter wc ON wc.warehouseFk = w.id;