-- MySQL Script generated by MySQL Workbench
-- Wed 01 Apr 2026 05:30:16 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`.`applications`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`applications` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(512) NOT NULL,
  `slug` 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 `slug_UNIQUE` (`slug` ASC) VISIBLE,
  UNIQUE INDEX `name_UNIQUE` (`name` ASC) VISIBLE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`roles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`roles` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `application_id` INT UNSIGNED NOT NULL,
  `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` (`application_id` ASC, `name` ASC) VISIBLE,
  INDEX `fk_roles_applications1_idx` (`application_id` ASC) VISIBLE,
  CONSTRAINT `fk_roles_applications1`
    FOREIGN KEY (`application_id`)
    REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`permissions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`permissions` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `application_id` INT UNSIGNED NOT NULL,
  `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` (`application_id` ASC, `name` ASC) VISIBLE,
  INDEX `fk_permissions_applications1_idx` (`application_id` ASC) VISIBLE,
  CONSTRAINT `fk_permissions_applications1`
    FOREIGN KEY (`application_id`)
    REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
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,
  `application_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,
  INDEX `fk_role_permissions_applications1_idx` (`application_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,
  CONSTRAINT `fk_role_permissions_applications1`
    FOREIGN KEY (`application_id`)
    REFERENCES `u947463964_etaviaporte`.`applications` (`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,
  `application_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,
  INDEX `fk_user_roles_applications1_idx` (`application_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,
  CONSTRAINT `fk_user_roles_applications1`
    FOREIGN KEY (`application_id`)
    REFERENCES `u947463964_etaviaporte`.`applications` (`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,
  `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` DATETIME NULL,
  PRIMARY KEY (`id`))
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` DECIMAL(10,8) NULL,
  `lng` DECIMAL(10,8) 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', 'Cancelled') 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,
  `status` ENUM('Available', 'Busy') NOT NULL DEFAULT 'Available',
  `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,
  UNIQUE INDEX `VIN_UNIQUE` (`company_id` ASC, `VIN` ASC) VISIBLE,
  UNIQUE INDEX `truck_plate_UNIQUE` (`company_id` ASC, `truck_plate` 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` DECIMAL(10,8) NULL,
  `last_lng` DECIMAL(10,8) 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_vehicles1_idx` (`vehicle_id` ASC) VISIBLE,
  INDEX `fk_shipment_proposals_users1_idx` (`created_by` 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_vehicles1`
    FOREIGN KEY (`vehicle_id`)
    REFERENCES `u947463964_etaviaporte`.`vehicles` (`id`)
    ON DELETE SET NULL
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_shipment_proposals_users1`
    FOREIGN KEY (`created_by`)
    REFERENCES `u947463964_etaviaporte`.`users` (`id`)
    ON DELETE CASCADE
    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,
  UNIQUE INDEX `load_id_UNIQUE` (`load_id` ASC) VISIBLE,
  INDEX `fk_shipment_agreements_users1_idx` (`accepted_by` 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_agreements_users1`
    FOREIGN KEY (`accepted_by`)
    REFERENCES `u947463964_etaviaporte`.`users` (`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,
  `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 `sector_UNIQUE` (`sector` ASC) VISIBLE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`meta_vehicle_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`meta_vehicle_types` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `type` VARCHAR(100) 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`),
  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,
  `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 `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,
  `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`.`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_vehicle_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_vehicle_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`.`vehicle_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicle_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_vehicle_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 CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_load_templates_locations1`
    FOREIGN KEY (`origin_id`)
    REFERENCES `u947463964_etaviaporte`.`locations` (`id`)
    ON DELETE SET NULL
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_load_templates_locations2`
    FOREIGN KEY (`destination_id`)
    REFERENCES `u947463964_etaviaporte`.`locations` (`id`)
    ON DELETE SET NULL
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_load_templates_users1`
    FOREIGN KEY (`created_by`)
    REFERENCES `u947463964_etaviaporte`.`users` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`user_applications`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`user_applications` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` INT UNSIGNED NOT NULL,
  `application_id` INT UNSIGNED NOT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC, `application_id` ASC) VISIBLE,
  INDEX `fk_user_applications_applications1_idx` (`application_id` ASC) VISIBLE,
  CONSTRAINT `fk_user_applications_users1`
    FOREIGN KEY (`user_id`)
    REFERENCES `u947463964_etaviaporte`.`users` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_user_applications_applications1`
    FOREIGN KEY (`application_id`)
    REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`company_users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_users` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` INT UNSIGNED NOT NULL,
  `company_id` INT UNSIGNED NOT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC) VISIBLE,
  INDEX `fk_company_users_companies1_idx` (`company_id` ASC) VISIBLE,
  CONSTRAINT `fk_company_users_users1`
    FOREIGN KEY (`user_id`)
    REFERENCES `u947463964_etaviaporte`.`users` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_company_users_companies1`
    FOREIGN KEY (`company_id`)
    REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`privacy_groups`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`privacy_groups` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `company_id` INT UNSIGNED NOT NULL,
  `name` VARCHAR(128) 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`),
  UNIQUE INDEX `company_id_UNIQUE` (`company_id` ASC, `name` ASC) VISIBLE,
  CONSTRAINT `fk_privacy_groups_companies1`
    FOREIGN KEY (`company_id`)
    REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`privacy_group_companies`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`privacy_group_companies` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `company_id` INT UNSIGNED NOT NULL,
  `group_id` INT UNSIGNED NOT NULL,
  `allowed_company_id` INT UNSIGNED NOT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `group_id_UNIQUE` (`group_id` ASC, `allowed_company_id` ASC) VISIBLE,
  INDEX `fk_privacy_companies_companies1_idx` (`company_id` ASC) VISIBLE,
  INDEX `fk_privacy_companies_companies2_idx` (`allowed_company_id` ASC) VISIBLE,
  CONSTRAINT `fk_privacy_companies_companies1`
    FOREIGN KEY (`company_id`)
    REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_privacy_companies_companies2`
    FOREIGN KEY (`allowed_company_id`)
    REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_privacy_companies_privacy_groups1`
    FOREIGN KEY (`group_id`)
    REFERENCES `u947463964_etaviaporte`.`privacy_groups` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`loads_alert_emails`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`loads_alert_emails` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `load_id` INT UNSIGNED NOT NULL,
  `email` VARCHAR(512) NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_loads_alert_emails_loads1_idx` (`load_id` ASC) VISIBLE,
  UNIQUE INDEX `load_id_UNIQUE` (`load_id` ASC, `email` ASC) VISIBLE,
  CONSTRAINT `fk_loads_alert_emails_loads1`
    FOREIGN KEY (`load_id`)
    REFERENCES `u947463964_etaviaporte`.`loads` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`warehouse_alert_emails`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`warehouse_alert_emails` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `warehouse_id` INT UNSIGNED NOT NULL,
  `email` VARCHAR(512) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `warehouse_id_UNIQUE` (`warehouse_id` ASC, `email` ASC) VISIBLE,
  INDEX `fk_warehouse_alert_emails_locations1_idx` (`warehouse_id` ASC) VISIBLE,
  CONSTRAINT `fk_warehouse_alert_emails_locations1`
    FOREIGN KEY (`warehouse_id`)
    REFERENCES `u947463964_etaviaporte`.`locations` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`company_status`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_status` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `company_id` INT UNSIGNED NOT NULL,
  `status` ENUM('Registered', 'InReview', 'Enabled', 'Disabled') NOT NULL DEFAULT 'Registered',
  `notes` TEXT 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_company_status_companies1_idx` (`company_id` ASC) VISIBLE,
  UNIQUE INDEX `company_id_UNIQUE` (`company_id` ASC) VISIBLE,
  CONSTRAINT `fk_company_status_companies1`
    FOREIGN KEY (`company_id`)
    REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`company_documents`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_documents` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `company_id` INT UNSIGNED NOT NULL,
  `document_id` VARCHAR(255) NOT NULL,
  `name` VARCHAR(512) NOT NULL,
  `status` ENUM('New', 'InReview', 'Approved', 'Rejected') NOT NULL DEFAULT 'New',
  `status_notes` TEXT NOT NULL COMMENT 'Add metadata like user who reviewed and reason behind the status assigned',
  `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_company_documents_companies1_idx` (`company_id` ASC) VISIBLE,
  UNIQUE INDEX `name_UNIQUE` (`company_id` ASC, `name` ASC) VISIBLE,
  CONSTRAINT `fk_company_documents_companies1`
    FOREIGN KEY (`company_id`)
    REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`apikeys`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`apikeys` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `application_id` INT UNSIGNED NOT NULL,
  `name` VARCHAR(512) NOT NULL,
  `description` TEXT NULL,
  `key_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 NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `key_hash_UNIQUE` (`key_hash` ASC) VISIBLE,
  CONSTRAINT `fk_apikeys_applications1`
    FOREIGN KEY (`application_id`)
    REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`apikey_permissions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`apikey_permissions` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `application_id` INT UNSIGNED NOT NULL,
  `permission_id` INT UNSIGNED NOT NULL,
  `apikey_id` INT UNSIGNED NOT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  INDEX `fk_apikey_permissions_permissions1_idx` (`permission_id` ASC) VISIBLE,
  INDEX `fk_apikey_permissions_apikeys1_idx` (`apikey_id` ASC) VISIBLE,
  UNIQUE INDEX `apikey_id_UNIQUE` (`apikey_id` ASC, `permission_id` ASC) VISIBLE,
  CONSTRAINT `fk_apikey_permissions_applications1`
    FOREIGN KEY (`application_id`)
    REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_apikey_permissions_permissions1`
    FOREIGN KEY (`permission_id`)
    REFERENCES `u947463964_etaviaporte`.`permissions` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_apikey_permissions_apikeys1`
    FOREIGN KEY (`apikey_id`)
    REFERENCES `u947463964_etaviaporte`.`apikeys` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `u947463964_etaviaporte`.`vehicle_documents`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicle_documents` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `company_id` INT UNSIGNED NOT NULL,
  `vehicle_id` INT UNSIGNED NOT NULL,
  `document_id` VARCHAR(255) NOT NULL,
  `name` VARCHAR(512) NOT NULL,
  `status` ENUM('New', 'InReview', 'Approved', 'Rejected') NOT NULL DEFAULT 'New',
  `status_notes` TEXT 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_vehicle_documents_companies1_idx` (`company_id` ASC) VISIBLE,
  INDEX `fk_vehicle_documents_vehicles1_idx` (`vehicle_id` ASC) VISIBLE,
  UNIQUE INDEX `name_UNIQUE` (`company_id` ASC, `name` ASC) VISIBLE,
  CONSTRAINT `fk_vehicle_documents_companies1`
    FOREIGN KEY (`company_id`)
    REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
    ON DELETE CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_vehicle_documents_vehicles1`
    FOREIGN KEY (`vehicle_id`)
    REFERENCES `u947463964_etaviaporte`.`vehicles` (`id`)
    ON DELETE CASCADE
    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;
