salix/db/versions/10896-salmonOrchid/03-gastos_resumen.sql

32 lines
1.5 KiB
MySQL
Raw Normal View History

2024-02-23 12:29:36 +00:00
DELETE FROM vn2008.gastos_resumen
WHERE Id_Gasto IN (
SELECT DISTINCT g.Id_Gasto
FROM vn2008.gastos_resumen g
LEFT JOIN expense e ON e.id = g.Id_Gasto COLLATE utf8mb3_general_ci
WHERE e.id IS NULL
);
ALTER TABLE `vn2008`.`gastos_resumen` DROP FOREIGN KEY gastos_resumen_expense_FK;
2024-02-21 06:35:57 +00:00
ALTER TABLE IF EXISTS `vn2008`.`gastos_resumen` RENAME `vn`.`expenseManual`;
2024-02-23 12:29:36 +00:00
ALTER TABLE `vn`.`expenseManual`
2024-02-20 13:22:07 +00:00
CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) NOT NULL,
CHANGE COLUMN IF EXISTS `importe` `amount` decimal(10,2) DEFAULT NULL,
CHANGE COLUMN IF EXISTS `empresa_id` `companyFk` int(11) NOT NULL;
2024-02-23 12:45:48 +00:00
ALTER TABLE `vn`.`expenseManual` MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL;
2024-02-20 13:22:07 +00:00
2024-02-23 12:45:48 +00:00
ALTER TABLE `vn`.`expenseManual` DROP PRIMARY KEY;
2024-02-20 13:22:07 +00:00
2024-02-23 12:45:48 +00:00
ALTER TABLE `vn`.`expenseManual` MODIFY COLUMN companyFk int(10) unsigned NULL;
2024-02-22 07:25:38 +00:00
2024-02-23 12:45:48 +00:00
ALTER TABLE `vn`.`expenseManual` ADD CONSTRAINT expenseManual_expense_FK FOREIGN KEY IF NOT EXISTS (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE;
2024-02-23 12:29:36 +00:00
2024-02-23 12:45:48 +00:00
UPDATE `vn`.`expenseManual`
2024-02-22 07:25:38 +00:00
SET companyFK= NULL
2024-02-22 07:36:14 +00:00
WHERE companyFk= 0;
2024-02-22 07:25:38 +00:00
2024-02-23 12:45:48 +00:00
ALTER TABLE `vn`.`expenseManual` ADD CONSTRAINT expenseManual_company_FK FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company(id) ON DELETE CASCADE ON UPDATE CASCADE;
2024-02-23 12:29:36 +00:00
2024-02-23 12:45:48 +00:00
ALTER TABLE `vn`.`expenseManual` ADD COLUMN id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY FIRST;
2024-02-20 13:22:07 +00:00
2024-02-23 12:45:48 +00:00
ALTER TABLE `vn`.`expenseManual` ADD CONSTRAINT expenseManual_unique UNIQUE KEY IF NOT EXISTS (expenseFk,`year`,`month`,companyFk);