salix/db/versions/10862-navyHydrangea/01-ventasContablesPk.sql

15 lines
676 B
SQL

USE vn;
-- Eliminar la clave primaria actual
ALTER TABLE bs.ventas_contables DROP PRIMARY KEY;
-- Agregar la nueva clave primaria incluyendo el campo `gasto`
ALTER TABLE bs.ventas_contables ADD PRIMARY KEY (`year`, `month`, `grupo`, `reino_id`, `tipo_id`, `empresa_id`, `gasto`);
DELETE vc.* FROM bs.ventas_contables vc LEFT JOIN vn.expense e ON e.id = vc.gasto WHERE e.id IS NULL;
ALTER TABLE bs.ventas_contables
MODIFY COLUMN gasto VARCHAR(10)
CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL;
ALTER TABLE bs.ventas_contables ADD CONSTRAINT ventas_contables_expense_FK FOREIGN KEY (gasto) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE;