feat(SQL): Adding subscriptions and resource counter tables
This commit is contained in:
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 615 KiB After Width: | Height: | Size: 1.4 MiB |
Binary file not shown.
@@ -26,20 +26,22 @@ This document translates SQL constraints from the schema into software requireme
|
||||
4. A permission shall always belong to an existing application.
|
||||
5. A permission name shall be unique within its application.
|
||||
6. A permission record shall include `created_at` and `updated_at` timestamps.
|
||||
7. A role-permission assignment shall reference an existing role, permission, and application.
|
||||
7. A role-permission assignment shall reference an existing role and permission.
|
||||
8. The pair `(role_id, permission_id)` shall be unique.
|
||||
9. Deleting an application, role, or permission shall delete related role-permission assignments.
|
||||
10. A user-role assignment shall reference an existing user, role, and application.
|
||||
11. The pair `(user_id, role_id)` shall be unique.
|
||||
12. Deleting a user, role, or application shall delete related user-role assignments.
|
||||
13. A user shall be allowed to have multiple roles as long as each `(user_id, role_id)` pair is unique.
|
||||
9. A role-permission assignment shall include `created_at` and `updated_at` timestamps.
|
||||
10. Deleting an application, role, or permission shall delete related role-permission assignments.
|
||||
11. A user-role assignment shall reference an existing user and role.
|
||||
12. The pair `(user_id, role_id)` shall be unique.
|
||||
13. A user-role assignment shall include `created_at` and `updated_at`, and may include `expires_at`.
|
||||
14. Deleting a user, role, or application shall delete related user-role assignments.
|
||||
15. A user shall be allowed to have multiple roles as long as each `(user_id, role_id)` pair is unique.
|
||||
|
||||
## 4. Verification and Sessions
|
||||
|
||||
1. A verification token shall belong to an existing auth identity.
|
||||
2. A verification token shall include unique `token_hash`.
|
||||
3. Verification token purpose shall be one of: `email_verification`, `phone_verification`, `password_reset`.
|
||||
4. A verification token shall include `created_at` and `expires_at`.
|
||||
4. A verification token shall include `created_at`, `updated_at`, and `expires_at`.
|
||||
5. Deleting an auth identity shall delete related verification tokens.
|
||||
6. A session shall belong to an existing user.
|
||||
7. A session shall include unique `session_token_hash`.
|
||||
@@ -49,54 +51,57 @@ This document translates SQL constraints from the schema into software requireme
|
||||
## 5. Companies and Locations
|
||||
|
||||
1. A company shall include `name`.
|
||||
2. Company `privacy_enabled` shall default to `0`.
|
||||
3. Company `disabled` shall default to `0`.
|
||||
4. A location shall belong to an existing company.
|
||||
5. A location shall include `state`, `city`, `country`, `zipcode`, and `address_line1`.
|
||||
6. Location type shall be one of: `loading`, `unloading`, `both`.
|
||||
7. Location type shall default to `both`.
|
||||
8. Location coordinates, when present, shall be stored as decimal latitude and longitude values.
|
||||
9. Deleting a company shall delete its locations.
|
||||
2. Company type shall be one of: `NotSet`, `Shipper`, `Carrier`.
|
||||
3. Company type shall default to `NotSet`.
|
||||
4. Company `privacy_enabled` shall default to `0`.
|
||||
5. Company `disabled` shall default to `0`.
|
||||
6. Company `disabled_reason`, when present, shall be stored as up to 255 characters.
|
||||
7. A location shall belong to an existing company.
|
||||
8. A location shall include `state`, `city`, `country`, `zipcode`, and `address_line1`.
|
||||
9. Location type shall be one of: `loading`, `unloading`, `both`.
|
||||
10. Location type shall default to `both`.
|
||||
11. Location coordinates, when present, shall be stored as decimal latitude and longitude values.
|
||||
12. Deleting a company shall delete its locations.
|
||||
|
||||
## 6. Loads, Vehicles, and Shipment Lifecycle
|
||||
|
||||
1. A load shall belong to an existing company and an existing creator user.
|
||||
2. Load status shall be one of: `Draft`, `Published`, `Completed`, `Closed`, `Cancelled`.
|
||||
3. Load status shall default to `Draft`.
|
||||
4. A load shall include `product`, `sector`, and `truck_type`.
|
||||
4. A load shall include `product`, `sector`, and `vehicle_type`.
|
||||
5. Load `privacy_enabled` shall default to `0`.
|
||||
6. Load `disabled` shall default to `0`.
|
||||
7. If an origin or destination location is deleted, the corresponding load reference shall be set to `NULL`.
|
||||
8. Deleting the load creator user shall delete the load.
|
||||
9. Deleting the load company shall delete the load.
|
||||
10. A vehicle shall belong to an existing company.
|
||||
11. A vehicle shall include `VIN` and `truck_plate`.
|
||||
11. A vehicle shall include `VIN` and `vehicle_plate`.
|
||||
12. Vehicle status shall be one of: `Available`, `Busy`.
|
||||
13. Vehicle status shall default to `Available`.
|
||||
14. A company shall not repeat the same vehicle VIN (`(company_id, VIN)` unique).
|
||||
15. A company shall not repeat the same truck plate (`(company_id, truck_plate)` unique).
|
||||
15. A company shall not repeat the same vehicle plate (`(company_id, vehicle_plate)` unique).
|
||||
16. A driver shall be assigned to at most one vehicle at a time (`driver_id` unique).
|
||||
17. A load shall be assigned to at most one vehicle at a time (`load_id` unique).
|
||||
18. If a driver user is deleted, the vehicle driver reference shall be set to `NULL`.
|
||||
19. If an assigned load is deleted, the vehicle load reference shall be set to `NULL`.
|
||||
20. Deleting a company shall delete its vehicles.
|
||||
21. A load shipment shall belong to an existing load.
|
||||
22. A load shipment status shall be one of: `Assigned`, `Loading`, `Transit`, `Unloading`, `Delivered`.
|
||||
23. A load shipment status shall default to `Assigned`.
|
||||
24. Shipment tracking coordinates, when present, shall be stored as decimal latitude and longitude values.
|
||||
25. Each load shall have at most one load shipment (`load_id` unique).
|
||||
26. Deleting a load shall delete its load shipment.
|
||||
27. A shipment evidence record shall belong to an existing load.
|
||||
28. Shipment evidence type shall be one of: `loading`, `unloading`.
|
||||
29. A load shall have at most one evidence per evidence type (`(load_id, type)` unique).
|
||||
30. Deleting a load shall delete shipment evidences.
|
||||
31. A shipment proposal shall belong to an existing load and an existing user (`created_by`).
|
||||
32. If a proposed vehicle is deleted, the shipment proposal vehicle reference shall be set to `NULL`.
|
||||
33. Deleting a load shall delete shipment proposals.
|
||||
34. Deleting the creator user shall delete shipment proposals.
|
||||
35. A shipment agreement shall reference an existing load, shipment proposal, and accepting user.
|
||||
36. A load shall have at most one shipment agreement (`load_id` unique).
|
||||
37. Deleting a load, shipment proposal, or accepting user shall delete shipment agreements.
|
||||
21. A shipment proposal shall belong to an existing load and an existing user (`created_by`).
|
||||
22. If a proposed vehicle is deleted, the shipment proposal vehicle reference shall be set to `NULL`.
|
||||
23. Deleting a load shall delete shipment proposals.
|
||||
24. Deleting the creator user shall delete shipment proposals.
|
||||
25. A shipment agreement shall reference an existing load, shipment proposal, and accepting user.
|
||||
26. A load shall have at most one shipment agreement (`load_id` unique).
|
||||
27. Deleting a load, shipment proposal, or accepting user shall delete shipment agreements.
|
||||
28. A load shipment shall belong to an existing load.
|
||||
29. A load shipment status shall be one of: `Assigned`, `Loading`, `Transit`, `Unloading`, `Delivered`.
|
||||
30. A load shipment status shall default to `Assigned`.
|
||||
31. Shipment tracking coordinates, when present, shall be stored as decimal latitude and longitude values.
|
||||
32. Each load shall have at most one load shipment (`load_id` unique).
|
||||
33. Deleting a load shall delete related load shipments.
|
||||
34. A shipment evidence record shall belong to an existing load.
|
||||
35. Shipment evidence type shall be one of: `loading`, `unloading`.
|
||||
36. A load shall have at most one evidence per evidence type (`(load_id, type)` unique).
|
||||
37. Deleting a load shall delete related shipment evidences.
|
||||
|
||||
## 7. Master Data and Categorization
|
||||
|
||||
@@ -110,19 +115,24 @@ This document translates SQL constraints from the schema into software requireme
|
||||
8. A city record shall include `created_at` and `updated_at` timestamps.
|
||||
9. A company sector shall belong to an existing company.
|
||||
10. A company shall not repeat the same sector (`(company_id, sector)` unique).
|
||||
11. Deleting a company shall delete its company sectors.
|
||||
12. A company vehicle type shall belong to an existing company.
|
||||
13. A company shall not repeat the same vehicle type (`(company_id, truck_type)` unique).
|
||||
14. Deleting a company shall delete its company vehicle types.
|
||||
15. A location-category assignment shall reference an existing location and existing company sector.
|
||||
16. A location shall not repeat the same category (`(location_id, category_id)` unique).
|
||||
17. Deleting a location or company sector shall delete related location-category assignments.
|
||||
18. A vehicle-type assignment shall reference an existing vehicle and existing company vehicle type.
|
||||
19. A vehicle shall not repeat the same type (`(vehicle_id, type_id)` unique).
|
||||
20. Deleting a vehicle or company vehicle type shall delete related vehicle-type assignments.
|
||||
21. A user-location assignment shall reference an existing user and existing location.
|
||||
22. A user shall not repeat the same location (`(user_id, location_id)` unique).
|
||||
23. Deleting a user or location shall delete related user-location assignments.
|
||||
11. A company sector record shall include `created_at` and `updated_at` timestamps.
|
||||
12. Deleting a company shall delete its company sectors.
|
||||
13. A company vehicle type shall belong to an existing company.
|
||||
14. A company shall not repeat the same vehicle type (`(company_id, vehicle_type)` unique).
|
||||
15. A company vehicle type record shall include `created_at` and `updated_at` timestamps.
|
||||
16. Deleting a company shall delete its company vehicle types.
|
||||
17. A company-location-sector assignment shall reference an existing location and existing company sector.
|
||||
18. A location shall not repeat the same sector (`(location_id, sector_id)` unique).
|
||||
19. A company-location-sector record shall include `created_at` and `updated_at` timestamps.
|
||||
20. Deleting a location or company sector shall delete related company-location-sector assignments.
|
||||
21. A vehicle-type assignment shall reference an existing vehicle and existing company vehicle type.
|
||||
22. A vehicle shall not repeat the same type (`(vehicle_id, type_id)` unique).
|
||||
23. A vehicle-type assignment shall include `created_at` and `updated_at` timestamps.
|
||||
24. Deleting a vehicle or company vehicle type shall delete related vehicle-type assignments.
|
||||
25. A user-location assignment shall reference an existing user and existing location.
|
||||
26. A user shall not repeat the same location (`(user_id, location_id)` unique).
|
||||
27. A user-location assignment shall include `created_at` and `updated_at` timestamps.
|
||||
28. Deleting a user or location shall delete related user-location assignments.
|
||||
|
||||
## 8. Templates, Memberships, and Privacy
|
||||
|
||||
@@ -135,26 +145,30 @@ This document translates SQL constraints from the schema into software requireme
|
||||
7. A user-application assignment shall reference an existing user and existing application.
|
||||
8. A user shall be allowed to be added to multiple applications.
|
||||
9. A user shall not be assigned to the same application more than once (`(user_id, application_id)` unique).
|
||||
10. Deleting a user or application shall delete related user-application assignments.
|
||||
11. A company-user assignment shall reference an existing user and existing company.
|
||||
12. A company-user assignment shall include `created_at`.
|
||||
13. A user shall be assigned to only one company (`user_id` unique in `company_users`).
|
||||
14. Deleting a user or company shall delete related company-user assignments.
|
||||
15. A privacy group shall belong to an existing company.
|
||||
16. Privacy group names shall be unique per company (`(company_id, name)` unique).
|
||||
17. Deleting a company shall delete its privacy groups.
|
||||
18. A privacy group company rule shall reference an existing company, privacy group, and allowed company.
|
||||
19. An allowed company shall not be repeated within the same privacy group (`(group_id, allowed_company_id)` unique).
|
||||
20. Deleting a company or privacy group shall delete related privacy group company rules.
|
||||
10. A user-application assignment shall include `created_at` and `updated_at` timestamps.
|
||||
11. Deleting a user or application shall delete related user-application assignments.
|
||||
12. A company-user assignment shall reference an existing user and existing company.
|
||||
13. A company-user assignment shall include `created_at` and `updated_at` timestamps.
|
||||
14. A user shall be assigned to only one company (`user_id` unique in `company_users`).
|
||||
15. Deleting a user or company shall delete related company-user assignments.
|
||||
16. A privacy group shall belong to an existing company.
|
||||
17. Privacy group names shall be unique per company (`(company_id, name)` unique).
|
||||
18. Deleting a company shall delete its privacy groups.
|
||||
19. A privacy group company rule shall reference an existing company, privacy group, and allowed company.
|
||||
20. An allowed company shall not be repeated within the same privacy group (`(group_id, allowed_company_id)` unique).
|
||||
21. A privacy group company rule shall include `created_at` and `updated_at` timestamps.
|
||||
22. Deleting a company or privacy group shall delete related privacy group company rules.
|
||||
|
||||
## 9. Alert Email Constraints
|
||||
|
||||
1. A load alert email record shall belong to an existing load.
|
||||
2. The same email shall not be repeated for the same load (`(load_id, email)` unique).
|
||||
3. Deleting a load shall delete load alert emails.
|
||||
4. A warehouse alert email record shall belong to an existing warehouse location.
|
||||
5. The same email shall not be repeated for the same warehouse (`(warehouse_id, email)` unique).
|
||||
6. Deleting a warehouse location shall delete warehouse alert emails.
|
||||
3. A load alert email record shall include `created_at` and `updated_at` timestamps.
|
||||
4. Deleting a load shall delete load alert emails.
|
||||
5. A warehouse alert email record shall belong to an existing warehouse location.
|
||||
6. The same email shall not be repeated for the same warehouse (`(warehouse_id, email)` unique).
|
||||
7. A warehouse alert email record shall include `created_at` and `updated_at` timestamps.
|
||||
8. Deleting a warehouse location shall delete warehouse alert emails.
|
||||
|
||||
## 10. Identity and Access Interpretation
|
||||
|
||||
@@ -168,29 +182,30 @@ This document translates SQL constraints from the schema into software requireme
|
||||
2. A company shall have at most one company status record (`company_id` unique).
|
||||
3. Company status shall be one of: `Registered`, `InReview`, `Enabled`, `Disabled`.
|
||||
4. Company status shall default to `Registered`.
|
||||
5. A company status record shall include `notes` (NOT NULL).
|
||||
5. A company status record may include `notes`.
|
||||
6. A company status record shall include `created_at` and `updated_at` timestamps.
|
||||
7. Deleting a company shall delete related company status records.
|
||||
8. A company document shall belong to an existing company.
|
||||
9. A company document shall include `document_id` and `name`.
|
||||
10. Company document status shall be one of: `New`, `InReview`, `Approved`, `Rejected`.
|
||||
11. Company document status shall default to `New`.
|
||||
12. A company document shall include `status_notes` (NOT NULL).
|
||||
12. A company document may include `status_notes`.
|
||||
13. A company document record shall include `created_at` and `updated_at` timestamps.
|
||||
14. A company shall not repeat document names (`(company_id, name)` unique).
|
||||
15. Deleting a company shall delete related company documents.
|
||||
|
||||
## 12. API Key and Permission Model
|
||||
## 12. API Key and User Permission Model
|
||||
|
||||
1. An API key record shall include `name` and `key_hash`.
|
||||
2. API key hashes shall be globally unique.
|
||||
3. An API key shall belong to an existing application.
|
||||
3. An API key shall belong to an existing application and an existing user owner.
|
||||
4. An API key record shall include `created_at` and `updated_at` timestamps.
|
||||
5. Deleting an application shall delete related API keys.
|
||||
6. An API key permission record shall belong to an existing application, permission, and API key.
|
||||
7. API key permission assignments shall include `created_at`.
|
||||
8. An API key shall not repeat the same permission assignment (`(apikey_id, permission_id)` unique).
|
||||
9. Deleting an application, permission, or API key shall delete related API key permission assignments.
|
||||
5. API key `active` status shall default to `1` (true).
|
||||
6. Deleting an application or user shall delete related API keys.
|
||||
7. A user-permission assignment shall belong to an existing application, permission, and user.
|
||||
8. A user-permission assignment shall include `created_at` and `updated_at`, and may include `expires_at`.
|
||||
9. A user shall not repeat the same permission assignment (`(user_id, permission_id)` unique).
|
||||
10. Deleting an application, permission, or user shall delete related user-permission assignments.
|
||||
|
||||
## 13. Vehicle Documents
|
||||
|
||||
@@ -198,7 +213,36 @@ This document translates SQL constraints from the schema into software requireme
|
||||
2. A vehicle document shall include `document_id` and `name`.
|
||||
3. Vehicle document status shall be one of: `New`, `InReview`, `Approved`, `Rejected`.
|
||||
4. Vehicle document status shall default to `New`.
|
||||
5. A vehicle document shall include `status_notes` (NOT NULL).
|
||||
5. A vehicle document may include `status_notes`.
|
||||
6. A vehicle document record shall include `created_at` and `updated_at` timestamps.
|
||||
7. A company shall not repeat vehicle document names (`(company_id, name)` unique).
|
||||
8. Deleting a company or vehicle shall delete related vehicle documents.
|
||||
|
||||
## 14. Subscription and Billing Constraints
|
||||
|
||||
1. A subscription plan shall belong to an existing application.
|
||||
2. A subscription plan shall include `provider`, `provider_plan_id`, and internal `name` unique within its application (`(application_id, name)` unique).
|
||||
3. The pair `(provider, provider_plan_id)` shall be unique.
|
||||
4. A subscription plan shall include `amount` with 4 decimal precision and default `0.0000`.
|
||||
5. Subscription plan `currency` shall default to `MXN` when not provided.
|
||||
6. Subscription plan limits shall default to: `limit_users=2`, `limit_loads=4`, `limit_shipments=4`, `limit_privacy_allowed=0`.
|
||||
7. A subscription plan shall include `created_at` and `updated_at` timestamps.
|
||||
8. A company subscription shall reference an existing company and subscription plan.
|
||||
9. A company shall have at most one company subscription (`company_id` unique in `company_subscriptions`).
|
||||
10. Company subscription status shall be one of: `Pending`, `Active`, `PastDue`, `Unpaid`, `Cancelled`, `Paused`.
|
||||
11. Company subscription status shall default to `Unpaid`.
|
||||
12. A company subscription shall include `provider_subscription_id`.
|
||||
13. A company subscription may include `start_date`, `current_period_start`, `current_period_end`, `cancelled_at`, and `cancelled_at_period_end`.
|
||||
14. A company subscription shall include `created_at` and `updated_at` timestamps.
|
||||
15. Company and plan rows referenced by company subscriptions shall not be deletable while dependent subscriptions exist (`ON DELETE NO ACTION`).
|
||||
16. A payment method shall belong to an existing company.
|
||||
17. A payment method shall include `provider`, `provider_payment_id`, `last4`, `brand`, and `name`.
|
||||
18. The pair `(provider, provider_payment_id)` shall be unique among payment methods.
|
||||
19. Payment method `is_primary` shall default to `0`.
|
||||
20. A payment method shall include `created_at` and `updated_at` timestamps.
|
||||
21. A company row referenced by payment methods shall not be deletable while dependent payment methods exist (`ON DELETE NO ACTION`).
|
||||
22. A company limits record shall belong to an existing company.
|
||||
23. A company shall have at most one limits record (`company_id` unique).
|
||||
24. Company limits shall default to: `available_users=2`, `available_shipments=4`, `available_loads=4`, `privacy_allowed=0`.
|
||||
25. A company limits record shall include `created_at` and `updated_at` timestamps.
|
||||
26. Deleting a company shall delete related company limits records.
|
||||
|
||||
@@ -34,14 +34,14 @@ INSERT INTO `permissions` (`application_id`,`name`, `description`) VALUES (3,'cl
|
||||
INSERT INTO `permissions` (`application_id`,`name`, `description`) VALUES (4,'warehouse', '(ETAObserverWarehouse): Compatibility with Legacy while refactor in progress');
|
||||
|
||||
-- Role-Permissions link for ETAConsole application (1)
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (1,1,1);
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (1,2,2);
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (1,3,3);
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (1,4,4);
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (1,5,5);
|
||||
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);
|
||||
-- Role-Permissions link for ETADriver application (2)
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (2,6,6);
|
||||
INSERT INTO `role_permissions` (`role_id`, `permission_id`) VALUES (6,6);
|
||||
-- Role-Permissions link for ETAObserverClient application (3)
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (3,7,7);
|
||||
INSERT INTO `role_permissions` (`role_id`, `permission_id`) VALUES (7,7);
|
||||
-- Role-Permissions link for ETAObserverWarehouse application (4)
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (4,8,8);
|
||||
INSERT INTO `role_permissions` (`role_id`, `permission_id`) VALUES (8,8);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-- MySQL Script generated by MySQL Workbench
|
||||
-- Wed 01 Apr 2026 05:30:16 PM CST
|
||||
-- Thu 02 Apr 2026 01:32:42 AM CST
|
||||
-- Model: New Model Version: 1.0
|
||||
-- MySQL Workbench Forward Engineering
|
||||
|
||||
@@ -119,12 +119,12 @@ 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,
|
||||
`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_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`)
|
||||
@@ -134,11 +134,6 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`role_permissions` (
|
||||
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;
|
||||
|
||||
@@ -150,14 +145,13 @@ 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,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 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`)
|
||||
@@ -167,11 +161,6 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`user_roles` (
|
||||
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;
|
||||
|
||||
@@ -185,6 +174,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`verification_tokens` (
|
||||
`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,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`expires_at` DATETIME NOT NULL,
|
||||
`used_at` DATETIME NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
@@ -227,11 +217,13 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`companies` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(512) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`type` ENUM('NotSet', 'Shipper', 'Carrier') NOT NULL DEFAULT 'NotSet',
|
||||
`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,
|
||||
`disabled_reason` VARCHAR(255) NULL COMMENT 'Log of the reason to disable this company and it s resources',
|
||||
PRIMARY KEY (`id`))
|
||||
ENGINE = InnoDB;
|
||||
|
||||
@@ -249,12 +241,12 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`locations` (
|
||||
`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,
|
||||
`lat` DECIMAL(11,8) NULL,
|
||||
`lng` DECIMAL(11,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,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `fk_locations_companies1_idx` (`company_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_locations_companies1`
|
||||
@@ -277,7 +269,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`loads` (
|
||||
`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,
|
||||
`vehicle_type` VARCHAR(100) NOT NULL,
|
||||
`privacy_enabled` TINYINT NOT NULL DEFAULT 0,
|
||||
`est_loading_date` DATE NULL,
|
||||
`est_unloading_date` DATE NULL,
|
||||
@@ -326,7 +318,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicles` (
|
||||
`load_id` INT UNSIGNED NULL,
|
||||
`status` ENUM('Available', 'Busy') NOT NULL DEFAULT 'Available',
|
||||
`VIN` VARCHAR(45) NOT NULL,
|
||||
`truck_plate` VARCHAR(45) NOT NULL,
|
||||
`vehicle_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,
|
||||
@@ -336,7 +328,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicles` (
|
||||
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,
|
||||
UNIQUE INDEX `vehicle_plate_UNIQUE` (`company_id` ASC, `vehicle_plate` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_vehicles_companies1`
|
||||
FOREIGN KEY (`company_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
|
||||
@@ -364,8 +356,8 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`load_shipments` (
|
||||
`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,
|
||||
`last_lat` DECIMAL(11,8) NULL,
|
||||
`last_lng` DECIMAL(11,8) NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `fk_load_shipment_loads1_idx` (`load_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `load_id_UNIQUE` (`load_id` ASC) VISIBLE,
|
||||
@@ -485,7 +477,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`meta_vehicle_types` (
|
||||
`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)
|
||||
UNIQUE INDEX `meta_vehicle_typescol_UNIQUE` (`type` ASC) VISIBLE)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
@@ -524,6 +516,8 @@ 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,
|
||||
`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` (`company_id` ASC, `sector` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_company_sectors_companies1`
|
||||
@@ -540,10 +534,12 @@ ENGINE = InnoDB;
|
||||
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,
|
||||
`vehicle_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 `company_id_UNIQUE` (`company_id` ASC, `truck_type` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_company_truck_types_companies1`
|
||||
UNIQUE INDEX `company_id_UNIQUE` (`company_id` ASC, `vehicle_type` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_company_vehicle_types_companies1`
|
||||
FOREIGN KEY (`company_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
|
||||
ON DELETE CASCADE
|
||||
@@ -552,22 +548,24 @@ ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`location_categories`
|
||||
-- Table `u947463964_etaviaporte`.`company_location_sectors`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`location_categories` (
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_location_sectors` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`location_id` INT UNSIGNED NOT NULL,
|
||||
`category_id` INT UNSIGNED NOT NULL,
|
||||
`sector_id` 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`),
|
||||
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`
|
||||
UNIQUE INDEX `location_id_UNIQUE` (`location_id` ASC, `sector_id` ASC) VISIBLE,
|
||||
INDEX `fk_location_sectors_company_sectors1_idx` (`sector_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_location_sectors_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`)
|
||||
CONSTRAINT `fk_location_sectors_company_sectors1`
|
||||
FOREIGN KEY (`sector_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`company_sectors` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION)
|
||||
@@ -581,15 +579,17 @@ 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,
|
||||
`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 `vehicle_id_UNIQUE` (`vehicle_id` ASC, `type_id` ASC) VISIBLE,
|
||||
INDEX `fk_vehicle_types_company_truck_types1_idx` (`type_id` ASC) VISIBLE,
|
||||
INDEX `fk_vehicle_types_company_vehicle_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`
|
||||
CONSTRAINT `fk_vehicle_types_company_vehicle_types1`
|
||||
FOREIGN KEY (`type_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`company_vehicle_types` (`id`)
|
||||
ON DELETE CASCADE
|
||||
@@ -604,6 +604,8 @@ 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,
|
||||
`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 `user_id_UNIQUE` (`user_id` ASC, `location_id` ASC) VISIBLE,
|
||||
INDEX `fk_user_locations_locations1_idx` (`location_id` ASC) VISIBLE,
|
||||
@@ -630,7 +632,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`load_templates` (
|
||||
`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,
|
||||
`vehicle_type` VARCHAR(100) NULL,
|
||||
`weight` INT UNSIGNED NULL,
|
||||
`notes` TEXT NULL,
|
||||
`estimated_cost` INT UNSIGNED NULL,
|
||||
@@ -674,6 +676,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`user_applications` (
|
||||
`user_id` INT UNSIGNED NOT NULL,
|
||||
`application_id` 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`),
|
||||
UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC, `application_id` ASC) VISIBLE,
|
||||
INDEX `fk_user_applications_applications1_idx` (`application_id` ASC) VISIBLE,
|
||||
@@ -698,6 +701,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_users` (
|
||||
`user_id` INT UNSIGNED NOT NULL,
|
||||
`company_id` 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`),
|
||||
UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC) VISIBLE,
|
||||
INDEX `fk_company_users_companies1_idx` (`company_id` ASC) VISIBLE,
|
||||
@@ -742,6 +746,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`privacy_group_companies` (
|
||||
`group_id` INT UNSIGNED NOT NULL,
|
||||
`allowed_company_id` 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`),
|
||||
UNIQUE INDEX `group_id_UNIQUE` (`group_id` ASC, `allowed_company_id` ASC) VISIBLE,
|
||||
INDEX `fk_privacy_companies_companies1_idx` (`company_id` ASC) VISIBLE,
|
||||
@@ -771,6 +776,8 @@ 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,
|
||||
`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_loads_alert_emails_loads1_idx` (`load_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `load_id_UNIQUE` (`load_id` ASC, `email` ASC) VISIBLE,
|
||||
@@ -789,6 +796,8 @@ 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,
|
||||
`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 `warehouse_id_UNIQUE` (`warehouse_id` ASC, `email` ASC) VISIBLE,
|
||||
INDEX `fk_warehouse_alert_emails_locations1_idx` (`warehouse_id` ASC) VISIBLE,
|
||||
@@ -807,7 +816,7 @@ 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,
|
||||
`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`),
|
||||
@@ -830,7 +839,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_documents` (
|
||||
`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',
|
||||
`status_notes` TEXT 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`),
|
||||
@@ -850,48 +859,57 @@ ENGINE = InnoDB;
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`apikeys` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`application_id` INT UNSIGNED NOT NULL,
|
||||
`user_id` INT UNSIGNED NOT NULL,
|
||||
`name` VARCHAR(512) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`key_hash` VARCHAR(255) NOT NULL,
|
||||
`active` TINYINT NOT NULL DEFAULT 1,
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`expires_at` DATETIME NULL,
|
||||
`expires_at` DATETIME NULL COMMENT 'When detected that already expired then set this to false',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `key_hash_UNIQUE` (`key_hash` ASC) VISIBLE,
|
||||
INDEX `fk_apikeys_users1_idx` (`user_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_apikeys_applications1`
|
||||
FOREIGN KEY (`application_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_apikeys_users1`
|
||||
FOREIGN KEY (`user_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`apikey_permissions`
|
||||
-- Table `u947463964_etaviaporte`.`user_permissions`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`apikey_permissions` (
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`user_permissions` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`application_id` INT UNSIGNED NOT NULL,
|
||||
`user_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,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`expires_at` DATETIME NULL,
|
||||
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`
|
||||
INDEX `fk_user_permissions_permissions1_idx` (`permission_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC, `permission_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_user_permissions_applications1`
|
||||
FOREIGN KEY (`application_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_apikey_permissions_permissions1`
|
||||
CONSTRAINT `fk_user_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`)
|
||||
CONSTRAINT `fk_user_permissions_users1`
|
||||
FOREIGN KEY (`user_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
@@ -907,7 +925,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicle_documents` (
|
||||
`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,
|
||||
`status_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`),
|
||||
@@ -927,6 +945,119 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicle_documents` (
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`subscription_plans`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`subscription_plans` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`application_id` INT UNSIGNED NOT NULL,
|
||||
`provider` VARCHAR(45) NOT NULL,
|
||||
`provider_plan_id` VARCHAR(255) NOT NULL,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`amount` DECIMAL(19,4) NOT NULL DEFAULT 0.0000,
|
||||
`currency` VARCHAR(45) NULL DEFAULT 'MXN',
|
||||
`limit_users` INT NOT NULL DEFAULT 2,
|
||||
`limit_loads` INT NOT NULL DEFAULT 4,
|
||||
`limit_shipments` INT NOT NULL DEFAULT 4,
|
||||
`limit_privacy_allowed` TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`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 `internal_name_UNIQUE` (`application_id` ASC, `name` ASC) VISIBLE,
|
||||
INDEX `fk_subscription_plans_applications1_idx` (`application_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `provider_UNIQUE` (`provider` ASC, `provider_plan_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_subscription_plans_applications1`
|
||||
FOREIGN KEY (`application_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`company_subscriptions`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_subscriptions` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`company_id` INT UNSIGNED NOT NULL,
|
||||
`plan_id` INT UNSIGNED NOT NULL,
|
||||
`provider_subscription_id` VARCHAR(255) NOT NULL,
|
||||
`status` ENUM('Pending', 'Active', 'PastDue', 'Unpaid', 'Cancelled', 'Paused') NOT NULL DEFAULT 'Unpaid' COMMENT 'PastDue means retry in X days, Unpaid means all retries failed',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`start_date` DATE NULL,
|
||||
`current_period_start` DATE NULL,
|
||||
`current_period_end` DATE NULL COMMENT 'The date the next charge will happen',
|
||||
`cancelled_at` DATE NULL,
|
||||
`cancelled_at_period_end` TINYINT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `fk_company_limits_companies1_idx` (`company_id` ASC) VISIBLE,
|
||||
INDEX `fk_company_subscriptions_subscription_plans1_idx` (`plan_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `company_id_UNIQUE` (`company_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_company_limits_companies1`
|
||||
FOREIGN KEY (`company_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_company_subscriptions_subscription_plans1`
|
||||
FOREIGN KEY (`plan_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`subscription_plans` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`payment_methods`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`payment_methods` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`company_id` INT UNSIGNED NOT NULL COMMENT 'When company deleted, the credit cards must be deleted first!',
|
||||
`provider` VARCHAR(45) NOT NULL,
|
||||
`provider_payment_id` VARCHAR(255) NOT NULL,
|
||||
`last4` VARCHAR(4) NOT NULL COMMENT 'Last 4 digits of credit card',
|
||||
`brand` VARCHAR(45) NOT NULL COMMENT 'MasterCard, Visa, etc',
|
||||
`name` VARCHAR(100) NOT NULL COMMENT 'Human readable name for the credit card. If not given by user can be set to brand + last4 as naming convention.',
|
||||
`is_primary` 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,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `fk_payment_methods_companies1_idx` (`company_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `provider_UNIQUE` (`provider` ASC, `provider_payment_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_payment_methods_companies1`
|
||||
FOREIGN KEY (`company_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`company_limits`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_limits` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`company_id` INT UNSIGNED NOT NULL,
|
||||
`available_users` INT UNSIGNED NOT NULL DEFAULT 2,
|
||||
`available_shipments` INT UNSIGNED NOT NULL DEFAULT 4,
|
||||
`available_loads` INT UNSIGNED NOT NULL DEFAULT 4,
|
||||
`used_users` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`used_shipments` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`used_loads` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`privacy_allowed` 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,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `company_id_UNIQUE` (`company_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_company_limits_companies2`
|
||||
FOREIGN KEY (`company_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`companies` (`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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-- MySQL Script generated by MySQL Workbench
|
||||
-- Wed 01 Apr 2026 05:30:16 PM CST
|
||||
-- Thu 02 Apr 2026 01:32:42 AM CST
|
||||
-- Model: New Model Version: 1.0
|
||||
-- MySQL Workbench Forward Engineering
|
||||
|
||||
@@ -119,12 +119,12 @@ 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,
|
||||
`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_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`)
|
||||
@@ -134,11 +134,6 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`role_permissions` (
|
||||
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;
|
||||
|
||||
@@ -150,14 +145,13 @@ 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,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 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`)
|
||||
@@ -167,11 +161,6 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`user_roles` (
|
||||
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;
|
||||
|
||||
@@ -185,6 +174,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`verification_tokens` (
|
||||
`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,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`expires_at` DATETIME NOT NULL,
|
||||
`used_at` DATETIME NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
@@ -227,11 +217,13 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`companies` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(512) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`type` ENUM('NotSet', 'Shipper', 'Carrier') NOT NULL DEFAULT 'NotSet',
|
||||
`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,
|
||||
`disabled_reason` VARCHAR(255) NULL COMMENT 'Log of the reason to disable this company and it s resources',
|
||||
PRIMARY KEY (`id`))
|
||||
ENGINE = InnoDB;
|
||||
|
||||
@@ -249,12 +241,12 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`locations` (
|
||||
`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,
|
||||
`lat` DECIMAL(11,8) NULL,
|
||||
`lng` DECIMAL(11,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,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `fk_locations_companies1_idx` (`company_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_locations_companies1`
|
||||
@@ -277,7 +269,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`loads` (
|
||||
`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,
|
||||
`vehicle_type` VARCHAR(100) NOT NULL,
|
||||
`privacy_enabled` TINYINT NOT NULL DEFAULT 0,
|
||||
`est_loading_date` DATE NULL,
|
||||
`est_unloading_date` DATE NULL,
|
||||
@@ -326,7 +318,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicles` (
|
||||
`load_id` INT UNSIGNED NULL,
|
||||
`status` ENUM('Available', 'Busy') NOT NULL DEFAULT 'Available',
|
||||
`VIN` VARCHAR(45) NOT NULL,
|
||||
`truck_plate` VARCHAR(45) NOT NULL,
|
||||
`vehicle_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,
|
||||
@@ -336,7 +328,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicles` (
|
||||
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,
|
||||
UNIQUE INDEX `vehicle_plate_UNIQUE` (`company_id` ASC, `vehicle_plate` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_vehicles_companies1`
|
||||
FOREIGN KEY (`company_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
|
||||
@@ -364,8 +356,8 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`load_shipments` (
|
||||
`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,
|
||||
`last_lat` DECIMAL(11,8) NULL,
|
||||
`last_lng` DECIMAL(11,8) NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `fk_load_shipment_loads1_idx` (`load_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `load_id_UNIQUE` (`load_id` ASC) VISIBLE,
|
||||
@@ -485,7 +477,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`meta_vehicle_types` (
|
||||
`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)
|
||||
UNIQUE INDEX `meta_vehicle_typescol_UNIQUE` (`type` ASC) VISIBLE)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
@@ -524,6 +516,8 @@ 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,
|
||||
`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` (`company_id` ASC, `sector` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_company_sectors_companies1`
|
||||
@@ -540,10 +534,12 @@ ENGINE = InnoDB;
|
||||
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,
|
||||
`vehicle_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 `company_id_UNIQUE` (`company_id` ASC, `truck_type` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_company_truck_types_companies1`
|
||||
UNIQUE INDEX `company_id_UNIQUE` (`company_id` ASC, `vehicle_type` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_company_vehicle_types_companies1`
|
||||
FOREIGN KEY (`company_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
|
||||
ON DELETE CASCADE
|
||||
@@ -552,22 +548,24 @@ ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`location_categories`
|
||||
-- Table `u947463964_etaviaporte`.`company_location_sectors`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`location_categories` (
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_location_sectors` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`location_id` INT UNSIGNED NOT NULL,
|
||||
`category_id` INT UNSIGNED NOT NULL,
|
||||
`sector_id` 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`),
|
||||
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`
|
||||
UNIQUE INDEX `location_id_UNIQUE` (`location_id` ASC, `sector_id` ASC) VISIBLE,
|
||||
INDEX `fk_location_sectors_company_sectors1_idx` (`sector_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_location_sectors_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`)
|
||||
CONSTRAINT `fk_location_sectors_company_sectors1`
|
||||
FOREIGN KEY (`sector_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`company_sectors` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION)
|
||||
@@ -581,15 +579,17 @@ 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,
|
||||
`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 `vehicle_id_UNIQUE` (`vehicle_id` ASC, `type_id` ASC) VISIBLE,
|
||||
INDEX `fk_vehicle_types_company_truck_types1_idx` (`type_id` ASC) VISIBLE,
|
||||
INDEX `fk_vehicle_types_company_vehicle_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`
|
||||
CONSTRAINT `fk_vehicle_types_company_vehicle_types1`
|
||||
FOREIGN KEY (`type_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`company_vehicle_types` (`id`)
|
||||
ON DELETE CASCADE
|
||||
@@ -604,6 +604,8 @@ 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,
|
||||
`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 `user_id_UNIQUE` (`user_id` ASC, `location_id` ASC) VISIBLE,
|
||||
INDEX `fk_user_locations_locations1_idx` (`location_id` ASC) VISIBLE,
|
||||
@@ -630,7 +632,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`load_templates` (
|
||||
`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,
|
||||
`vehicle_type` VARCHAR(100) NULL,
|
||||
`weight` INT UNSIGNED NULL,
|
||||
`notes` TEXT NULL,
|
||||
`estimated_cost` INT UNSIGNED NULL,
|
||||
@@ -674,6 +676,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`user_applications` (
|
||||
`user_id` INT UNSIGNED NOT NULL,
|
||||
`application_id` 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`),
|
||||
UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC, `application_id` ASC) VISIBLE,
|
||||
INDEX `fk_user_applications_applications1_idx` (`application_id` ASC) VISIBLE,
|
||||
@@ -698,6 +701,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_users` (
|
||||
`user_id` INT UNSIGNED NOT NULL,
|
||||
`company_id` 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`),
|
||||
UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC) VISIBLE,
|
||||
INDEX `fk_company_users_companies1_idx` (`company_id` ASC) VISIBLE,
|
||||
@@ -742,6 +746,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`privacy_group_companies` (
|
||||
`group_id` INT UNSIGNED NOT NULL,
|
||||
`allowed_company_id` 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`),
|
||||
UNIQUE INDEX `group_id_UNIQUE` (`group_id` ASC, `allowed_company_id` ASC) VISIBLE,
|
||||
INDEX `fk_privacy_companies_companies1_idx` (`company_id` ASC) VISIBLE,
|
||||
@@ -771,6 +776,8 @@ 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,
|
||||
`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_loads_alert_emails_loads1_idx` (`load_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `load_id_UNIQUE` (`load_id` ASC, `email` ASC) VISIBLE,
|
||||
@@ -789,6 +796,8 @@ 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,
|
||||
`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 `warehouse_id_UNIQUE` (`warehouse_id` ASC, `email` ASC) VISIBLE,
|
||||
INDEX `fk_warehouse_alert_emails_locations1_idx` (`warehouse_id` ASC) VISIBLE,
|
||||
@@ -807,7 +816,7 @@ 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,
|
||||
`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`),
|
||||
@@ -830,7 +839,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_documents` (
|
||||
`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',
|
||||
`status_notes` TEXT 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`),
|
||||
@@ -850,48 +859,57 @@ ENGINE = InnoDB;
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`apikeys` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`application_id` INT UNSIGNED NOT NULL,
|
||||
`user_id` INT UNSIGNED NOT NULL,
|
||||
`name` VARCHAR(512) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`key_hash` VARCHAR(255) NOT NULL,
|
||||
`active` TINYINT NOT NULL DEFAULT 1,
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`expires_at` DATETIME NULL,
|
||||
`expires_at` DATETIME NULL COMMENT 'When detected that already expired then set this to false',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `key_hash_UNIQUE` (`key_hash` ASC) VISIBLE,
|
||||
INDEX `fk_apikeys_users1_idx` (`user_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_apikeys_applications1`
|
||||
FOREIGN KEY (`application_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_apikeys_users1`
|
||||
FOREIGN KEY (`user_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`apikey_permissions`
|
||||
-- Table `u947463964_etaviaporte`.`user_permissions`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`apikey_permissions` (
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`user_permissions` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`application_id` INT UNSIGNED NOT NULL,
|
||||
`user_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,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`expires_at` DATETIME NULL,
|
||||
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`
|
||||
INDEX `fk_user_permissions_permissions1_idx` (`permission_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC, `permission_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_user_permissions_applications1`
|
||||
FOREIGN KEY (`application_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_apikey_permissions_permissions1`
|
||||
CONSTRAINT `fk_user_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`)
|
||||
CONSTRAINT `fk_user_permissions_users1`
|
||||
FOREIGN KEY (`user_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`users` (`id`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
@@ -907,7 +925,7 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicle_documents` (
|
||||
`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,
|
||||
`status_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`),
|
||||
@@ -927,6 +945,119 @@ CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`vehicle_documents` (
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`subscription_plans`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`subscription_plans` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`application_id` INT UNSIGNED NOT NULL,
|
||||
`provider` VARCHAR(45) NOT NULL,
|
||||
`provider_plan_id` VARCHAR(255) NOT NULL,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`amount` DECIMAL(19,4) NOT NULL DEFAULT 0.0000,
|
||||
`currency` VARCHAR(45) NULL DEFAULT 'MXN',
|
||||
`limit_users` INT NOT NULL DEFAULT 2,
|
||||
`limit_loads` INT NOT NULL DEFAULT 4,
|
||||
`limit_shipments` INT NOT NULL DEFAULT 4,
|
||||
`limit_privacy_allowed` TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`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 `internal_name_UNIQUE` (`application_id` ASC, `name` ASC) VISIBLE,
|
||||
INDEX `fk_subscription_plans_applications1_idx` (`application_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `provider_UNIQUE` (`provider` ASC, `provider_plan_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_subscription_plans_applications1`
|
||||
FOREIGN KEY (`application_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`applications` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`company_subscriptions`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_subscriptions` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`company_id` INT UNSIGNED NOT NULL,
|
||||
`plan_id` INT UNSIGNED NOT NULL,
|
||||
`provider_subscription_id` VARCHAR(255) NOT NULL,
|
||||
`status` ENUM('Pending', 'Active', 'PastDue', 'Unpaid', 'Cancelled', 'Paused') NOT NULL DEFAULT 'Unpaid' COMMENT 'PastDue means retry in X days, Unpaid means all retries failed',
|
||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`start_date` DATE NULL,
|
||||
`current_period_start` DATE NULL,
|
||||
`current_period_end` DATE NULL COMMENT 'The date the next charge will happen',
|
||||
`cancelled_at` DATE NULL,
|
||||
`cancelled_at_period_end` TINYINT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `fk_company_limits_companies1_idx` (`company_id` ASC) VISIBLE,
|
||||
INDEX `fk_company_subscriptions_subscription_plans1_idx` (`plan_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `company_id_UNIQUE` (`company_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_company_limits_companies1`
|
||||
FOREIGN KEY (`company_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_company_subscriptions_subscription_plans1`
|
||||
FOREIGN KEY (`plan_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`subscription_plans` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`payment_methods`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`payment_methods` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`company_id` INT UNSIGNED NOT NULL COMMENT 'When company deleted, the credit cards must be deleted first!',
|
||||
`provider` VARCHAR(45) NOT NULL,
|
||||
`provider_payment_id` VARCHAR(255) NOT NULL,
|
||||
`last4` VARCHAR(4) NOT NULL COMMENT 'Last 4 digits of credit card',
|
||||
`brand` VARCHAR(45) NOT NULL COMMENT 'MasterCard, Visa, etc',
|
||||
`name` VARCHAR(100) NOT NULL COMMENT 'Human readable name for the credit card. If not given by user can be set to brand + last4 as naming convention.',
|
||||
`is_primary` 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,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `fk_payment_methods_companies1_idx` (`company_id` ASC) VISIBLE,
|
||||
UNIQUE INDEX `provider_UNIQUE` (`provider` ASC, `provider_payment_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_payment_methods_companies1`
|
||||
FOREIGN KEY (`company_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`companies` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `u947463964_etaviaporte`.`company_limits`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `u947463964_etaviaporte`.`company_limits` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`company_id` INT UNSIGNED NOT NULL,
|
||||
`available_users` INT UNSIGNED NOT NULL DEFAULT 2,
|
||||
`available_shipments` INT UNSIGNED NOT NULL DEFAULT 4,
|
||||
`available_loads` INT UNSIGNED NOT NULL DEFAULT 4,
|
||||
`used_users` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`used_shipments` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`used_loads` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`privacy_allowed` 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,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `company_id_UNIQUE` (`company_id` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_company_limits_companies2`
|
||||
FOREIGN KEY (`company_id`)
|
||||
REFERENCES `u947463964_etaviaporte`.`companies` (`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;
|
||||
|
||||
@@ -34,14 +34,14 @@ INSERT INTO `permissions` (`application_id`,`name`, `description`) VALUES (3,'cl
|
||||
INSERT INTO `permissions` (`application_id`,`name`, `description`) VALUES (4,'warehouse', '(ETAObserverWarehouse): Compatibility with Legacy while refactor in progress');
|
||||
|
||||
-- Role-Permissions link for ETAConsole application (1)
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (1,1,1);
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (1,2,2);
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (1,3,3);
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (1,4,4);
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (1,5,5);
|
||||
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);
|
||||
-- Role-Permissions link for ETADriver application (2)
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (2,6,6);
|
||||
INSERT INTO `role_permissions` (`role_id`, `permission_id`) VALUES (6,6);
|
||||
-- Role-Permissions link for ETAObserverClient application (3)
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (3,7,7);
|
||||
INSERT INTO `role_permissions` (`role_id`, `permission_id`) VALUES (7,7);
|
||||
-- Role-Permissions link for ETAObserverWarehouse application (4)
|
||||
INSERT INTO `role_permissions` (`application_id`,`role_id`, `permission_id`) VALUES (4,8,8);
|
||||
INSERT INTO `role_permissions` (`role_id`, `permission_id`) VALUES (8,8);
|
||||
|
||||
Reference in New Issue
Block a user