feat(Docker): Adding a working Dockerfile and compose to prototype

This commit is contained in:
Josepablo Cruz
2026-04-01 14:03:20 -06:00
parent 4fcd3f01a5
commit bd3fddbbc2
13 changed files with 723 additions and 51 deletions

View File

@@ -1,34 +0,0 @@
-- Creation of init content. Scheme assumed to be empty
--
INSERT INTO roles (name, description) VALUES ('owner', "Owner of the company"); -- 1
INSERT INTO roles (name, description) VALUES ('manager', "Manager of the company"); -- 2
INSERT INTO roles (name, description) VALUES ('driver', "Driver user type"); -- 3
INSERT INTO roles (name, description) VALUES ('staff', "Member of the staff"); -- 4
INSERT INTO roles (name, description) VALUES ('warehouse', "Observer type of member"); -- 5
INSERT INTO permissions (name, description) VALUES ('owner', "Compatibility with Legacy while refactor in progress"); -- 1
INSERT INTO permissions (name, description) VALUES ('manager', "Compatibility with Legacy while refactor in progress"); -- 2
INSERT INTO permissions (name, description) VALUES ('driver', "Compatibility with Legacy while refactor in progress"); -- 3
INSERT INTO permissions (name, description) VALUES ('staff', "Compatibility with Legacy while refactor in progress"); -- 4
INSERT INTO permissions (name, description) VALUES ('warehouse', "Compatibility with Legacy while refactor in progress"); -- 5
INSERT INTO permissions (name, description) VALUES ('user.update', "Update user data"); -- 6
INSERT INTO permissions (name, description) VALUES ('user.create', "Create new users"); -- 7
INSERT INTO permissions (name, description) VALUES ('user.delete', "Delete users"); -- 8
INSERT INTO permissions (name, description) VALUES ('company.update', "Update company data"); -- 9
INSERT INTO permissions (name, description) VALUES ('company.delete', "Delete company"); -- 10
INSERT INTO permissions (name, description) VALUES ('loads.create', "Create loads"); -- 11
INSERT INTO permissions (name, description) VALUES ('loads.update', "Update loads data"); -- 12
INSERT INTO permissions (name, description) VALUES ('loads.delete', "Delete loads"); -- 13
INSERT INTO permissions (name, description) VALUES ('proposals.delete', "Delete loads"); -- 13
INSERT INTO permissions (name, description) VALUES ('proposals.delete', "Delete loads"); -- 13
INSERT INTO permissions (name, description) VALUES ('proposals.delete', "Delete loads"); -- 13
INSERT INTO role_permissions (role_id, permission_id) VALUES (1,1);
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);

View File

@@ -0,0 +1,21 @@
-- Creation of init content. Scheme assumed to be empty
--
USE `u947463964_etaviaporte` ;
INSERT INTO `roles` (`name`, `description`) VALUES ('owner', 'Owner of the company');
INSERT INTO `roles` (`name`, `description`) VALUES ('manager', 'Manager of the company');
INSERT INTO `roles` (`name`, `description`) VALUES ('driver', 'Driver user type');
INSERT INTO `roles` (`name`, `description`) VALUES ('staff', 'Member of the staff');
INSERT INTO `roles` (`name`, `description`) VALUES ('warehouse', 'Observer type of member');
INSERT INTO `permissions` (`name`, `description`) VALUES ('owner', 'Compatibility with Legacy while refactor in progress');
INSERT INTO `permissions` (`name`, `description`) VALUES ('manager', 'Compatibility with Legacy while refactor in progress');
INSERT INTO `permissions` (`name`, `description`) VALUES ('driver', 'Compatibility with Legacy while refactor in progress');
INSERT INTO `permissions` (`name`, `description`) VALUES ('staff', 'Compatibility with Legacy while refactor in progress');
INSERT INTO `permissions` (`name`, `description`) VALUES ('warehouse', 'Compatibility with Legacy while refactor in progress');
INSERT INTO `role_permissions` (`role_id`, `permission_id`) VALUES (1,1);
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);

View File

@@ -1,5 +1,5 @@
-- MySQL Script generated by MySQL Workbench
-- Wed 01 Apr 2026 01:09:41 PM CST
-- Wed 01 Apr 2026 01:34:28 PM CST
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering

View File

@@ -7,14 +7,18 @@ ARG VCS_REF
RUN apk add --no-cache mariadb mysql-client mariadb-server-utils pwgen && \
rm -f /var/cache/apk/*
RUN mkdir /schemas
COPY schemas /schemas
ADD scripts/run.sh /scripts/run.sh
RUN mkdir /schemas && mkdir /scripts
RUN mkdir /docker-entrypoint-initdb.d && \
mkdir /scripts/pre-exec.d && \
mkdir /scripts/pre-init.d && \
chmod -R 755 /scripts
mkdir /scripts/pre-init.d
#
# Populate content here
#
ADD scripts/run.sh /scripts/run.sh
# COPY docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
RUN chmod -R 755 /scripts
EXPOSE 3306

View File

@@ -1,10 +1,6 @@
# ETAv2SQL
# MySQL Databse schema
![etaviaporte](./Models/assets/Modelv2.0.0.png)
# Docker
# Docker Container to deploy MySQL with schema and content init
## Build Docker image
@@ -20,3 +16,27 @@ docker logs -f eta-db
```
Container will generate automatically a SQL root password
### Environment Variables
You can setup a database name and grant access to it with user/password using the following env vars
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_PASSWORD
```{.sh}
docker run --name eta-db -e MYSQL_DATABASE=u947463964_etaviaporte -e MYSQL_USER=etaapi -e MYSQL_PASSWORD="secret_password" -d -p3306:3306 eta/eta-db
```
### Schemas and SQL scripts
You can add schemas and sql scripts to the container to setup the database on startup by mounting a directory with sql scripts on `/docker-entrypoint-initdb.d`
```{.sh}
docker run --name eta-db -e MYSQL_DATABASE=u947463964_etaviaporte -e MYSQL_USER=etaapi -e MYSQL_PASSWORD="secret_password" -v ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d -d -p3306:3306 eta/eta-db
```
### Known Issues
- When loading a script, errors my araise when using `"` instead of `'` and when comments appear at the end of a command

View File

@@ -70,13 +70,14 @@ EOF
fi
fi
/usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < $tfile
/usr/bin/mariadbd --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < $tfile
rm -f $tfile
for f in /docker-entrypoint-initdb.d/*; do
echo
case "$f" in
*.sql) echo "$0: running $f"; /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
*.sql) echo "$0: running $f"; /usr/bin/mariadbd --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | /usr/bin/mariadbd --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
*) echo "$0: ignoring or entrypoint initdb empty $f" ;;
esac
echo
@@ -86,7 +87,7 @@ EOF
echo 'MySQL init process done. Ready for start up.'
echo
echo "exec /usr/bin/mysqld --user=mysql --console --skip-name-resolve --skip-networking=0" "$@"
echo "exec /usr/bin/mariadbd --user=mysql --console --skip-name-resolve --skip-networking=0" "$@"
# Saving plain password
echo $MYSQL_ROOT_PASSWORD > /schemas/password.txt
@@ -101,4 +102,4 @@ do
fi
done
exec /usr/bin/mysqld --user=mysql --console --skip-name-resolve --skip-networking=0 $@
exec /usr/bin/mariadbd --user=mysql --console --skip-name-resolve --skip-networking=0 $@

5
db/service/Makefile Normal file
View File

@@ -0,0 +1,5 @@
.PHONY: prepare
prepare:
rm initdb/*.sql
cp ../Models/schemas/eta_rbac.sql ./initdb/00-schema.sql
cp ../Models/init/eta_rbac_init.sql ./initdb/01-initdb.sql

13
db/service/compose.yml Normal file
View File

@@ -0,0 +1,13 @@
services:
eta-db:
image: eta/eta-db
container_name: eta-db
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: u947463964_etaviaporte
MYSQL_USER: etaapi
MYSQL_PASSWORD: secret_password
volumes:
# Solve problems related to SELinux `permission denied` when accessing the path
- ./initdb:/docker-entrypoint-initdb.d:Z

View File

View File

@@ -0,0 +1,621 @@
-- MySQL Script generated by MySQL Workbench
-- Wed 01 Apr 2026 01:34:28 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

@@ -0,0 +1,21 @@
-- Creation of init content. Scheme assumed to be empty
--
USE `u947463964_etaviaporte` ;
INSERT INTO `roles` (`name`, `description`) VALUES ('owner', 'Owner of the company');
INSERT INTO `roles` (`name`, `description`) VALUES ('manager', 'Manager of the company');
INSERT INTO `roles` (`name`, `description`) VALUES ('driver', 'Driver user type');
INSERT INTO `roles` (`name`, `description`) VALUES ('staff', 'Member of the staff');
INSERT INTO `roles` (`name`, `description`) VALUES ('warehouse', 'Observer type of member');
INSERT INTO `permissions` (`name`, `description`) VALUES ('owner', 'Compatibility with Legacy while refactor in progress');
INSERT INTO `permissions` (`name`, `description`) VALUES ('manager', 'Compatibility with Legacy while refactor in progress');
INSERT INTO `permissions` (`name`, `description`) VALUES ('driver', 'Compatibility with Legacy while refactor in progress');
INSERT INTO `permissions` (`name`, `description`) VALUES ('staff', 'Compatibility with Legacy while refactor in progress');
INSERT INTO `permissions` (`name`, `description`) VALUES ('warehouse', 'Compatibility with Legacy while refactor in progress');
INSERT INTO `role_permissions` (`role_id`, `permission_id`) VALUES (1,1);
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);