salix/db/versions/.archive/10408-purpleIvy/00-firstScript.sql

32 lines
1.6 KiB
SQL

CREATE TABLE IF NOT EXISTS vn.roadmap (
id int(10) unsigned auto_increment NOT NULL,
tractorPlate varchar(10) DEFAULT NULL NULL,
trailerPlate varchar(12) DEFAULT NULL NULL,
phone varchar(15) DEFAULT NULL NULL,
supplierFk int(11) DEFAULT NULL NULL,
etd datetime DEFAULT NULL NULL,
observations varchar(255) DEFAULT NULL NULL,
created timestamp DEFAULT current_timestamp() NULL,
userFk int(10) unsigned DEFAULT NULL NULL,
CONSTRAINT PRIMARY KEY (id),
FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) ON DELETE RESTRICT ON UPDATE CASCADE,
FOREIGN KEY (userFk) REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE CASCADE
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;
ALTER TABLE vn.expeditionTruck ADD IF NOT EXISTS roadmapFk int(10) unsigned NULL,
ADD IF NOT EXISTS warehouseFk smallint(6) unsigned NULL,
ADD IF NOT EXISTS created timestamp DEFAULT current_timestamp() NULL,
ADD IF NOT EXISTS userFk int(10) unsigned NULL,
CHANGE roadmapFk roadmapFk int(10) unsigned NULL AFTER id,
CHANGE warehouseFk warehouseFk smallint(6) unsigned NULL AFTER roadmapFk;
ALTER TABLE vn.expeditionTruck ADD CONSTRAINT expeditionTruck_FK_1 FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE RESTRICT ON UPDATE CASCADE,
ADD CONSTRAINT expeditionTruck_FK_2 FOREIGN KEY (roadmapFk) REFERENCES vn.roadmap(id) ON DELETE RESTRICT ON UPDATE CASCADE,
ADD CONSTRAINT expeditionTruck_FK_3 FOREIGN KEY (userFk) REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE vn.warehouse ADD IF NOT EXISTS isHalt tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Almacén en el que descargan nuestros troncales';