feat(SQL): Adding working schema script

This commit is contained in:
Josepablo Cruz
2026-04-01 13:11:07 -06:00
parent 005fad6048
commit 4fcd3f01a5
13 changed files with 6221 additions and 65 deletions

View File

@@ -1,55 +0,0 @@
-- Creation of basic User Types
INSERT INTO user_types (name, description) VALUES ('root','An easy way to identify the root user of the system');
INSERT INTO user_types (name, description) VALUES ('company_owner','Company Owner');
INSERT INTO user_types (name, description) VALUES ('company_manager','Company Level manager');
INSERT INTO user_types (name, description) VALUES ('staff','Company Level Staff Memeber');
INSERT INTO user_types (name, description) VALUES ('driver','Company Level Driver Member');
INSERT INTO user_types (name, description) VALUES ('observer','Read Only member');
-- Creation of first user
INSERT INTO users (user_type,name,last_name,created_at,updated_at) VALUES (1,'Pablo','Cruz',NOW(),NOW()); -- root -> root
-- Creation of basic roles
INSERT INTO roles (name, description, created_at, updated_at) VALUES ("root","Root role with no restricted access",NOW(),NOW());
INSERT INTO roles (name, description, created_at, updated_at) VALUES ("system_admin","System Level Admin",NOW(),NOW());
INSERT INTO roles (name, description, created_at, updated_at) VALUES ("system_developer","System Level Developer",NOW(),NOW());
INSERT INTO roles (name, description, created_at, updated_at) VALUES ("system_reader","System Level Read Only",NOW(),NOW());
INSERT INTO roles (name, description, created_at, updated_at) VALUES ("system_staff","System Level staff member",NOW(),NOW());
INSERT INTO roles (name, description, created_at, updated_at) VALUES ("company_owner","Unrestricted access to company resources",NOW(),NOW());
INSERT INTO roles (name, description, created_at, updated_at) VALUES ("company_manager","Access as manager to company resources",NOW(),NOW());
INSERT INTO roles (name, description, created_at, updated_at) VALUES ("staff","Access as staff to company resources",NOW(),NOW());
INSERT INTO roles (name, description, created_at, updated_at) VALUES ("driver","Simple access to company resources",NOW(),NOW());
INSERT INTO roles (name, description, created_at, updated_at) VALUES ("observer","Limited access to only read company resources",NOW(),NOW());
-- Creation of basic permissions
INSERT INTO permissions (name, description) VALUES ("root","Root role with no restricted access");
INSERT INTO permissions (name, description) VALUES ("system.admin","System Level Admin");
INSERT INTO permissions (name, description) VALUES ("system.developer","System Level Developer");
INSERT INTO permissions (name, description) VALUES ("system.reader","System Level Reader");
INSERT INTO permissions (name, description) VALUES ("system.staff","System Level Staff Member");
INSERT INTO permissions (name, description) VALUES ("company.owner","Unrestricted access to company resources");
INSERT INTO permissions (name, description) VALUES ("company.manager","Admin access to company resources");
INSERT INTO permissions (name, description) VALUES ("company.staff","Staff access to company resources");
INSERT INTO permissions (name, description) VALUES ("company.driver","Driver with simple access to company resources");
INSERT INTO permissions (name, description) VALUES ("company.observer","Observer with simple access to company resources");
-- Link of basic roles with its permissions
INSERT INTO role_permissions (role_id, permission_id) VALUES( 1, 1 ); -- root -> root
INSERT INTO role_permissions (role_id, permission_id) VALUES( 2, 2 );
INSERT INTO role_permissions (role_id, permission_id) VALUES( 3, 3 );
INSERT INTO role_permissions (role_id, permission_id) VALUES( 4, 4 );
INSERT INTO role_permissions (role_id, permission_id) VALUES( 5, 5 );
INSERT INTO role_permissions (role_id, permission_id) VALUES( 6, 6 );
INSERT INTO role_permissions (role_id, permission_id) VALUES( 7, 7 );
INSERT INTO role_permissions (role_id, permission_id) VALUES( 8, 8 );
INSERT INTO role_permissions (role_id, permission_id) VALUES( 9, 9 );
INSERT INTO role_permissions (role_id, permission_id) VALUES( 10, 10 );
-- Link of Root User with its role
INSERT INTO user_roles (user_id, role_id, created_at ) VALUES (1,1,NOW()); -- root -> root
-- Create Root Auth Identity and credentials
INSERT INTO auth_identities (user_id, provider, identifier, is_primary, is_verified, created_at, updated_at ) VALUES (1,"email","josepablo134@gmail.com",1,1,NOW(),NOW()); -- root access with email
INSERT INTO auth_credentials (identity_id, password, created_at, updated_at) VALUES (1, "PasswordGoesHere", NOW(), NOW());

View File

@@ -0,0 +1,621 @@
-- MySQL Script generated by MySQL Workbench
-- Wed 01 Apr 2026 01:09:41 PM CST
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema u947463964_etaviaporte
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema u947463964_etaviaporte
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `u947463964_etaviaporte` DEFAULT CHARACTER SET utf8 ;
USE `u947463964_etaviaporte` ;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`users` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(512) NOT NULL,
`last_name` VARCHAR(512) NOT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`auth_identities`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`auth_identities` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` INT UNSIGNED NOT NULL,
`provider` VARCHAR(512) NOT NULL COMMENT 'type of identifier: email, phone, etc',
`identifier` VARCHAR(512) NOT NULL COMMENT 'email, phone, etc',
`password_hash` VARCHAR(512) NULL,
`is_primary` TINYINT NOT NULL DEFAULT 0,
`is_verified` TINYINT NOT NULL DEFAULT 0,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'when phone or email, password goes here.',
PRIMARY KEY (`id`),
INDEX `fk_auth_identities_users_idx` (`user_id` ASC) VISIBLE,
UNIQUE INDEX `provider_UNIQUE` (`provider` ASC, `identifier` ASC) VISIBLE,
CONSTRAINT `fk_auth_identities_users`
FOREIGN KEY (`user_id`)
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`roles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`roles` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(512) NOT NULL,
`description` TEXT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC) VISIBLE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`permissions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`permissions` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(512) NOT NULL,
`description` TEXT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC) VISIBLE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`role_permissions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`role_permissions` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`role_id` INT UNSIGNED NOT NULL,
`permission_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_role_permissions_roles1_idx` (`role_id` ASC) VISIBLE,
INDEX `fk_role_permissions_permissions1_idx` (`permission_id` ASC) VISIBLE,
UNIQUE INDEX `role_id_UNIQUE` (`role_id` ASC, `permission_id` ASC) VISIBLE,
CONSTRAINT `fk_role_permissions_roles1`
FOREIGN KEY (`role_id`)
REFERENCES `u947463964_etaviaporte`.`roles` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_role_permissions_permissions1`
FOREIGN KEY (`permission_id`)
REFERENCES `u947463964_etaviaporte`.`permissions` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`user_roles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`user_roles` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` INT UNSIGNED NOT NULL,
`role_id` INT UNSIGNED NOT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`expires_at` DATETIME NULL,
PRIMARY KEY (`id`),
INDEX `fk_user_roles_users1_idx` (`user_id` ASC) VISIBLE,
INDEX `fk_user_roles_roles1_idx` (`role_id` ASC) VISIBLE,
UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC, `role_id` ASC) VISIBLE,
CONSTRAINT `fk_user_roles_users1`
FOREIGN KEY (`user_id`)
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_user_roles_roles1`
FOREIGN KEY (`role_id`)
REFERENCES `u947463964_etaviaporte`.`roles` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`verification_tokens`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`verification_tokens` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`auth_identity_id` INT UNSIGNED NOT NULL,
`token_hash` VARCHAR(255) NOT NULL COMMENT 'Verification token for email/phone/notification mechanisms to either validate or reset passwords',
`purpose` ENUM('email_verification', 'phone_verification', 'password_reset') NOT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`expires_at` DATETIME NOT NULL,
`used_at` DATETIME NULL,
PRIMARY KEY (`id`),
INDEX `fk_verification_tokens_auth_identities1_idx` (`auth_identity_id` ASC) VISIBLE,
UNIQUE INDEX `token_hash_UNIQUE` (`token_hash` ASC) VISIBLE,
CONSTRAINT `fk_verification_tokens_auth_identities1`
FOREIGN KEY (`auth_identity_id`)
REFERENCES `u947463964_etaviaporte`.`auth_identities` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`sessions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`sessions` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` INT UNSIGNED NOT NULL,
`session_token_hash` VARCHAR(255) NOT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`expires_at` DATETIME NOT NULL,
`revoked_at` DATETIME NULL,
PRIMARY KEY (`id`),
INDEX `fk_sessions_users1_idx` (`user_id` ASC) VISIBLE,
UNIQUE INDEX `session_token_hash_UNIQUE` (`session_token_hash` ASC) VISIBLE,
CONSTRAINT `fk_sessions_users1`
FOREIGN KEY (`user_id`)
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`companies`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`companies` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`owner_id` INT UNSIGNED NOT NULL,
`name` VARCHAR(512) NOT NULL,
`description` TEXT NULL,
`privacy_enabled` TINYINT NOT NULL DEFAULT 0,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`disabled` TINYINT NOT NULL DEFAULT 0 COMMENT 'This field allows blocking publications based on business rules',
`disabled_at` VARCHAR(45) NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `owner_id_UNIQUE` (`owner_id` ASC) VISIBLE,
CONSTRAINT `fk_companies_users1`
FOREIGN KEY (`owner_id`)
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`locations`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`locations` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`company_id` INT UNSIGNED NOT NULL,
`type` ENUM('loading', 'unloading', 'both') NOT NULL DEFAULT 'both',
`state` VARCHAR(128) NOT NULL,
`city` VARCHAR(128) NOT NULL,
`country` VARCHAR(128) NOT NULL,
`zipcode` VARCHAR(10) NOT NULL,
`address_line1` VARCHAR(512) NOT NULL,
`address_line2` VARCHAR(512) NULL,
`lat` VARCHAR(128) NULL,
`lng` VARCHAR(128) NULL,
`name` VARCHAR(512) NULL,
`description` TEXT NULL,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX `fk_locations_companies1_idx` (`company_id` ASC) VISIBLE,
CONSTRAINT `fk_locations_companies1`
FOREIGN KEY (`company_id`)
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`loads`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`loads` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`company_id` INT UNSIGNED NOT NULL,
`created_by` INT UNSIGNED NOT NULL,
`origin_id` INT UNSIGNED NULL,
`destination_id` INT UNSIGNED NULL,
`status` ENUM('Draft', 'Published', 'Completed', 'Closed', 'Cancel') NOT NULL DEFAULT 'Draft',
`product` VARCHAR(100) NOT NULL COMMENT 'Maiz, Trigo, etc',
`sector` VARCHAR(100) NOT NULL COMMENT 'Automotriz, Agricola, etc',
`truck_type` VARCHAR(100) NOT NULL,
`privacy_enabled` TINYINT NOT NULL DEFAULT 0,
`est_loading_date` DATE NULL,
`est_unloading_date` DATE NULL,
`weight` INT UNSIGNED NULL,
`notes` TEXT NULL,
`estimated_cost` INT UNSIGNED NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`disabled` TINYINT NOT NULL DEFAULT 0 COMMENT 'This field allows blocking publications based on business rules',
`disabled_at` DATETIME NULL,
PRIMARY KEY (`id`),
INDEX `fk_loads_users1_idx` (`created_by` ASC) VISIBLE,
INDEX `fk_loads_companies1_idx` (`company_id` ASC) VISIBLE,
INDEX `fk_loads_locations1_idx` (`origin_id` ASC) VISIBLE,
INDEX `fk_loads_locations2_idx` (`destination_id` ASC) VISIBLE,
CONSTRAINT `fk_loads_users1`
FOREIGN KEY (`created_by`)
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_loads_companies1`
FOREIGN KEY (`company_id`)
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_loads_locations1`
FOREIGN KEY (`origin_id`)
REFERENCES `u947463964_etaviaporte`.`locations` (`id`)
ON DELETE SET NULL
ON UPDATE NO ACTION,
CONSTRAINT `fk_loads_locations2`
FOREIGN KEY (`destination_id`)
REFERENCES `u947463964_etaviaporte`.`locations` (`id`)
ON DELETE SET NULL
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`vehicles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicles` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`company_id` INT UNSIGNED NOT NULL,
`driver_id` INT UNSIGNED NULL,
`load_id` INT UNSIGNED NULL,
`VIN` VARCHAR(45) NOT NULL,
`truck_plate` VARCHAR(45) NOT NULL,
`trailer_plate_1` VARCHAR(45) NULL,
`trailer_plate_2` VARCHAR(45) NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX `fk_vehicles_companies1_idx` (`company_id` ASC) VISIBLE,
UNIQUE INDEX `driver_id_UNIQUE` (`driver_id` ASC) VISIBLE,
UNIQUE INDEX `load_id_UNIQUE` (`load_id` ASC) VISIBLE,
CONSTRAINT `fk_vehicles_companies1`
FOREIGN KEY (`company_id`)
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_vehicles_users1`
FOREIGN KEY (`driver_id`)
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
ON DELETE SET NULL
ON UPDATE NO ACTION,
CONSTRAINT `fk_vehicles_loads1`
FOREIGN KEY (`load_id`)
REFERENCES `u947463964_etaviaporte`.`loads` (`id`)
ON DELETE SET NULL
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`load_shipments`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`load_shipments` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`load_id` INT UNSIGNED NOT NULL,
`status` ENUM('Assigned', 'Loading', 'Transit', 'Unloading', 'Delivered') NOT NULL DEFAULT 'Assigned',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`last_lat` VARCHAR(128) NULL,
`last_lng` VARCHAR(128) NULL,
PRIMARY KEY (`id`),
INDEX `fk_load_shipment_loads1_idx` (`load_id` ASC) VISIBLE,
UNIQUE INDEX `load_id_UNIQUE` (`load_id` ASC) VISIBLE,
CONSTRAINT `fk_load_shipment_loads1`
FOREIGN KEY (`load_id`)
REFERENCES `u947463964_etaviaporte`.`loads` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`shipment_evidences`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`shipment_evidences` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`load_id` INT UNSIGNED NOT NULL,
`type` ENUM('loading', 'unloading') NOT NULL,
`attachment_id` VARCHAR(255) NOT NULL COMMENT 'ID of BLOB resource',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE INDEX `load_id_UNIQUE` (`load_id` ASC, `type` ASC) VISIBLE,
CONSTRAINT `fk_shipment_evidence_loads1`
FOREIGN KEY (`load_id`)
REFERENCES `u947463964_etaviaporte`.`loads` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`shipment_proposals`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`shipment_proposals` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`load_id` INT UNSIGNED NOT NULL,
`created_by` INT UNSIGNED NOT NULL,
`vehicle_id` INT UNSIGNED NULL,
`notes` TEXT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX `fk_shipment_proposals_loads1_idx` (`load_id` ASC) VISIBLE,
INDEX `fk_shipment_proposals_user_roles1_idx` (`created_by` ASC) VISIBLE,
INDEX `fk_shipment_proposals_vehicles1_idx` (`vehicle_id` ASC) VISIBLE,
CONSTRAINT `fk_shipment_proposals_loads1`
FOREIGN KEY (`load_id`)
REFERENCES `u947463964_etaviaporte`.`loads` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_shipment_proposals_user_roles1`
FOREIGN KEY (`created_by`)
REFERENCES `u947463964_etaviaporte`.`user_roles` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_shipment_proposals_vehicles1`
FOREIGN KEY (`vehicle_id`)
REFERENCES `u947463964_etaviaporte`.`vehicles` (`id`)
ON DELETE SET NULL
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`shipment_agreements`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`shipment_agreements` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`load_id` INT UNSIGNED NOT NULL,
`proposal_id` INT UNSIGNED NOT NULL,
`accepted_by` INT UNSIGNED NOT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX `fk_shipment_proposal_agreement_loads1_idx` (`load_id` ASC) VISIBLE,
INDEX `fk_shipment_proposal_agreement_shipment_proposals1_idx` (`proposal_id` ASC) VISIBLE,
INDEX `fk_shipment_proposal_agreement_user_roles1_idx` (`accepted_by` ASC) VISIBLE,
UNIQUE INDEX `load_id_UNIQUE` (`load_id` ASC) VISIBLE,
CONSTRAINT `fk_shipment_proposal_agreement_loads1`
FOREIGN KEY (`load_id`)
REFERENCES `u947463964_etaviaporte`.`loads` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_shipment_proposal_agreement_shipment_proposals1`
FOREIGN KEY (`proposal_id`)
REFERENCES `u947463964_etaviaporte`.`shipment_proposals` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_shipment_proposal_agreement_user_roles1`
FOREIGN KEY (`accepted_by`)
REFERENCES `u947463964_etaviaporte`.`user_roles` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`meta_sectors`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`meta_sectors` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`sector` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `sector_UNIQUE` (`sector` ASC) VISIBLE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`meta_truck_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`meta_truck_types` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`type` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `meta_truck_typescol_UNIQUE` (`type` ASC) VISIBLE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`meta_products`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`meta_products` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`product` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `product_UNIQUE` (`product` ASC) VISIBLE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`meta_cities`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`meta_cities` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`city` VARCHAR(100) NOT NULL,
`state` VARCHAR(100) NOT NULL,
`country` VARCHAR(100) NOT NULL,
`zipcode` VARCHAR(100) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`company_sectors`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_sectors` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`company_id` INT UNSIGNED NOT NULL,
`sector` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `sector_UNIQUE` (`company_id` ASC, `sector` ASC) VISIBLE,
CONSTRAINT `fk_company_sectors_companies1`
FOREIGN KEY (`company_id`)
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`company_truck_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_truck_types` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`company_id` INT UNSIGNED NOT NULL,
`truck_type` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `company_id_UNIQUE` (`company_id` ASC, `truck_type` ASC) VISIBLE,
CONSTRAINT `fk_company_truck_types_companies1`
FOREIGN KEY (`company_id`)
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`location_categories`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`location_categories` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`location_id` INT UNSIGNED NOT NULL,
`category_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `location_id_UNIQUE` (`location_id` ASC, `category_id` ASC) VISIBLE,
INDEX `fk_location_categories_company_sectors1_idx` (`category_id` ASC) VISIBLE,
CONSTRAINT `fk_location_categories_locations1`
FOREIGN KEY (`location_id`)
REFERENCES `u947463964_etaviaporte`.`locations` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_location_categories_company_sectors1`
FOREIGN KEY (`category_id`)
REFERENCES `u947463964_etaviaporte`.`company_sectors` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`truck_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`truck_types` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`vehicle_id` INT UNSIGNED NOT NULL,
`type_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `vehicle_id_UNIQUE` (`vehicle_id` ASC, `type_id` ASC) VISIBLE,
INDEX `fk_vehicle_types_company_truck_types1_idx` (`type_id` ASC) VISIBLE,
CONSTRAINT `fk_vehicle_types_vehicles1`
FOREIGN KEY (`vehicle_id`)
REFERENCES `u947463964_etaviaporte`.`vehicles` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_vehicle_types_company_truck_types1`
FOREIGN KEY (`type_id`)
REFERENCES `u947463964_etaviaporte`.`company_truck_types` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`user_locations`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`user_locations` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` INT UNSIGNED NOT NULL,
`location_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC, `location_id` ASC) VISIBLE,
INDEX `fk_user_locations_locations1_idx` (`location_id` ASC) VISIBLE,
CONSTRAINT `fk_user_locations_users1`
FOREIGN KEY (`user_id`)
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_user_locations_locations1`
FOREIGN KEY (`location_id`)
REFERENCES `u947463964_etaviaporte`.`locations` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`load_templates`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`load_templates` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`company_id` INT UNSIGNED NOT NULL,
`created_by` INT UNSIGNED NOT NULL,
`name` VARCHAR(100) NOT NULL COMMENT 'User friendly name to identify the template',
`product` VARCHAR(100) NULL,
`sector` VARCHAR(100) NULL,
`truck_type` VARCHAR(100) NULL,
`weight` INT UNSIGNED NULL,
`notes` TEXT NULL,
`estimated_cost` INT UNSIGNED NULL,
`origin_id` INT UNSIGNED NULL,
`destination_id` INT UNSIGNED NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE INDEX `company_id_UNIQUE` (`company_id` ASC, `created_by` ASC, `name` ASC) VISIBLE,
INDEX `fk_load_templates_locations1_idx` (`origin_id` ASC) VISIBLE,
INDEX `fk_load_templates_locations2_idx` (`destination_id` ASC) VISIBLE,
INDEX `fk_load_templates_users1_idx` (`created_by` ASC) VISIBLE,
CONSTRAINT `fk_load_templates_companies1`
FOREIGN KEY (`company_id`)
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_load_templates_locations1`
FOREIGN KEY (`origin_id`)
REFERENCES `u947463964_etaviaporte`.`locations` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_load_templates_locations2`
FOREIGN KEY (`destination_id`)
REFERENCES `u947463964_etaviaporte`.`locations` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_load_templates_users1`
FOREIGN KEY (`created_by`)
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

View File

@@ -1,5 +1,5 @@
-- MySQL Script generated by MySQL Workbench
-- Tue 31 Mar 2026 11:38:07 PM CST
-- Tue 31 Mar 2026 11:55:20 PM CST
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering

View File

@@ -1,18 +0,0 @@
-- Creation of root and backoffice
INSERT INTO applications (name, slug, description) VALUES ('root/backoffice','root_backoffice',"This is the application with no restrictions to all resources");
INSERT INTO permissions (application_id, name, description) VALUES (1, 'root', "No restrictions");
INSERT INTO roles (application_id, name, description) VALUES (1, 'root', "No restrictions");
INSERT INTO role_permissions (role_id, permission_id) VALUES (1,1);
INSERT INTO users (name, last_name) VALUES ('root','root');
INSERT INTO auth_identities (user_id, provider, identifier, password_hash, is_primary, is_verified) VALUES (1,'email','root@root.com','invalid_password_hash',1,1);
INSERT INTO user_roles (user_id, role_id) VALUES (1,1);
INSERT INTO user_permissions (user_id, permission_id) VALUES (1,1);
INSERT INTO user_applications (user_id, application_id) VALUES (1,1);