16 KiB
16 KiB
ETA RBAC and Domain Data Requirements
This document translates SQL constraints from the schema into software requirements language.
1. Global Requirements
- The system shall store all data in the schema
u947463964_etaviaporte. - Each table shall use an auto-generated unsigned integer
idas primary key. - Every foreign-keyed record shall reference an existing parent record.
2. Users and Authentication
- A user shall provide
nameandlast_name. - A user record shall always include
created_atandupdated_attimestamps. - An auth identity shall always belong to an existing user.
- An auth identity shall include
providerandidentifier. - The combination of
providerandidentifiershall be unique. - Auth identity flags
is_primaryandis_verifiedshall default to0(false). - Deleting a user shall delete the user auth identities.
3. Applications, Roles, and Permissions
- An application shall include unique
nameand uniqueslug. - A role shall always belong to an existing application.
- A role name shall be unique within its application.
- A permission shall always belong to an existing application.
- A permission name shall be unique within its application.
- A permission record shall include
created_atandupdated_attimestamps. - A role-permission assignment shall reference an existing role and permission.
- The pair
(role_id, permission_id)shall be unique. - A role-permission assignment shall include
created_atandupdated_attimestamps. - Deleting an application, role, or permission shall delete related role-permission assignments.
- A user-role assignment shall reference an existing user and role.
- The pair
(user_id, role_id)shall be unique. - A user-role assignment shall include
created_atandupdated_at, and may includeexpires_at. - Deleting a user, role, or application shall delete related user-role assignments.
- A user shall be allowed to have multiple roles as long as each
(user_id, role_id)pair is unique.
4. Verification and Sessions
- A verification token shall belong to an existing auth identity.
- A verification token shall include unique
token_hash. - Verification token purpose shall be one of:
email_verification,phone_verification,password_reset. - A verification token shall include
created_at,updated_at, andexpires_at. - Deleting an auth identity shall delete related verification tokens.
- A session shall belong to an existing user.
- A session shall include unique
session_token_hash. - A session shall include
created_at,updated_at, andexpires_at. - Deleting a user shall delete related sessions.
5. Companies and Locations
- A company shall include
name. - Company type shall be one of:
NotSet,Shipper,Carrier. - Company type shall default to
NotSet. - Company
privacy_enabledshall default to0. - Company
disabledshall default to0. - Company
disabled_reason, when present, shall be stored as up to 255 characters. - A location shall belong to an existing company.
- A location shall include
state,city,country,zipcode, andaddress_line1. - Location type shall be one of:
loading,unloading,both. - Location type shall default to
both. - Location coordinates, when present, shall be stored as decimal latitude and longitude values.
- Deleting a company shall delete its locations.
6. Loads, Vehicles, and Shipment Lifecycle
- A load shall belong to an existing company and an existing creator user.
- Load status shall be one of:
Draft,Published,Completed,Closed,Cancelled. - Load status shall default to
Draft. - A load shall include
product,sector, andvehicle_type. - Load
privacy_enabledshall default to0. - Load
disabledshall default to0. - If an origin or destination location is deleted, the corresponding load reference shall be set to
NULL. - Deleting the load creator user shall delete the load.
- Deleting the load company shall delete the load.
- A vehicle shall belong to an existing company.
- A vehicle shall include
VINandvehicle_plate. - Vehicle status shall be one of:
Available,Busy. - Vehicle status shall default to
Available. - A company shall not repeat the same vehicle VIN (
(company_id, VIN)unique). - A company shall not repeat the same vehicle plate (
(company_id, vehicle_plate)unique). - A driver shall be assigned to at most one vehicle at a time (
driver_idunique). - A load shall be assigned to at most one vehicle at a time (
load_idunique). - If a driver user is deleted, the vehicle driver reference shall be set to
NULL. - If an assigned load is deleted, the vehicle load reference shall be set to
NULL. - Deleting a company shall delete its vehicles.
- A shipment proposal shall belong to an existing load and an existing user (
created_by). - If a proposed vehicle is deleted, the shipment proposal vehicle reference shall be set to
NULL. - Deleting a load shall delete shipment proposals.
- Deleting the creator user shall delete shipment proposals.
- A shipment agreement shall reference an existing load, shipment proposal, and accepting user.
- A load shall have at most one shipment agreement (
load_idunique). - Deleting a load, shipment proposal, or accepting user shall delete shipment agreements.
- A load shipment shall belong to an existing load.
- A load shipment status shall be one of:
Assigned,Loading,Transit,Unloading,Delivered. - A load shipment status shall default to
Assigned. - Shipment tracking coordinates, when present, shall be stored as decimal latitude and longitude values.
- Each load shall have at most one load shipment (
load_idunique). - Deleting a load shall delete related load shipments.
- A shipment evidence record shall belong to an existing load.
- Shipment evidence type shall be one of:
loading,unloading. - A load shall have at most one evidence per evidence type (
(load_id, type)unique). - Deleting a load shall delete related shipment evidences.
7. Master Data and Categorization
- Sector names in
meta_sectorsshall be unique. - A sector record shall include
created_atandupdated_attimestamps. - Vehicle type names in
meta_vehicle_typesshall be unique. - A vehicle type record shall include
created_atandupdated_attimestamps. - Product names in
meta_productsshall be unique. - A product record shall include
created_atandupdated_attimestamps. - A city record shall include
city,state, andcountry. - A city record shall include
created_atandupdated_attimestamps. - A company sector shall belong to an existing company.
- A company shall not repeat the same sector (
(company_id, sector)unique). - A company sector record shall include
created_atandupdated_attimestamps. - Deleting a company shall delete its company sectors.
- A company vehicle type shall belong to an existing company.
- A company shall not repeat the same vehicle type (
(company_id, vehicle_type)unique). - A company vehicle type record shall include
created_atandupdated_attimestamps. - Deleting a company shall delete its company vehicle types.
- A company-location-sector assignment shall reference an existing location and existing company sector.
- A location shall not repeat the same sector (
(location_id, sector_id)unique). - A company-location-sector record shall include
created_atandupdated_attimestamps. - Deleting a location or company sector shall delete related company-location-sector assignments.
- A vehicle-type assignment shall reference an existing vehicle and existing company vehicle type.
- A vehicle shall not repeat the same type (
(vehicle_id, type_id)unique). - A vehicle-type assignment shall include
created_atandupdated_attimestamps. - Deleting a vehicle or company vehicle type shall delete related vehicle-type assignments.
- A user-location assignment shall reference an existing user and existing location.
- A user shall not repeat the same location (
(user_id, location_id)unique). - A user-location assignment shall include
created_atandupdated_attimestamps. - Deleting a user or location shall delete related user-location assignments.
8. Templates, Memberships, and Privacy
- A load template shall belong to an existing company and creator user.
- A load template shall include
name. - A user shall not create duplicate load template names inside the same company (
(company_id, created_by, name)unique). - Deleting a company shall delete related load templates.
- Deleting a creator user shall delete related load templates.
- Deleting an origin or destination location referenced by a load template shall set that location reference to
NULL. - A user-application assignment shall reference an existing user and existing application.
- A user shall be allowed to be added to multiple applications.
- A user shall not be assigned to the same application more than once (
(user_id, application_id)unique). - A user-application assignment shall include
created_atandupdated_attimestamps. - Deleting a user or application shall delete related user-application assignments.
- A company-user assignment shall reference an existing user and existing company.
- A company-user assignment shall include
created_atandupdated_attimestamps. - A user shall be assigned to only one company (
user_idunique incompany_users). - Deleting a user or company shall delete related company-user assignments.
- A privacy group shall belong to an existing company.
- Privacy group names shall be unique per company (
(company_id, name)unique). - Deleting a company shall delete its privacy groups.
- A privacy group company rule shall reference an existing company, privacy group, and allowed company.
- An allowed company shall not be repeated within the same privacy group (
(group_id, allowed_company_id)unique). - A privacy group company rule shall include
created_atandupdated_attimestamps. - Deleting a company or privacy group shall delete related privacy group company rules.
9. Alert Email Constraints
- A load alert email record shall belong to an existing load.
- The same email shall not be repeated for the same load (
(load_id, email)unique). - A load alert email record shall include
created_atandupdated_attimestamps. - Deleting a load shall delete load alert emails.
- A warehouse alert email record shall belong to an existing warehouse location.
- The same email shall not be repeated for the same warehouse (
(warehouse_id, email)unique). - A warehouse alert email record shall include
created_atandupdated_attimestamps. - Deleting a warehouse location shall delete warehouse alert emails.
10. Identity and Access Interpretation
- A user shall be authorized using an identity provider and identifier pair, such as email address or phone number.
- A provider-specific identifier shall map to one and only one auth identity record.
- A role and permission model shall be scoped by application.
11. Company Compliance and Documents
- A company status record shall belong to an existing company.
- A company shall have at most one company status record (
company_idunique). - Company status shall be one of:
Registered,InReview,Enabled,Disabled. - Company status shall default to
Registered. - A company status record may include
notes. - A company status record shall include
created_atandupdated_attimestamps. - Deleting a company shall delete related company status records.
- A company document shall belong to an existing company.
- A company document shall include
document_idandname. - Company document status shall be one of:
New,InReview,Approved,Rejected. - Company document status shall default to
New. - A company document may include
status_notes. - A company document record shall include
created_atandupdated_attimestamps. - A company shall not repeat document names (
(company_id, name)unique). - Deleting a company shall delete related company documents.
12. API Key and User Permission Model
- An API key record shall include
nameandkey_hash. - API key hashes shall be globally unique.
- An API key shall belong to an existing application and an existing user owner.
- An API key record shall include
created_atandupdated_attimestamps. - API key
activestatus shall default to1(true). - Deleting an application or user shall delete related API keys.
- A user-permission assignment shall belong to an existing application, permission, and user.
- A user-permission assignment shall include
created_atandupdated_at, and may includeexpires_at. - A user shall not repeat the same permission assignment (
(user_id, permission_id)unique). - Deleting an application, permission, or user shall delete related user-permission assignments.
13. Vehicle Documents
- A vehicle document shall belong to an existing company and an existing vehicle.
- A vehicle document shall include
document_idandname. - Vehicle document status shall be one of:
New,InReview,Approved,Rejected. - Vehicle document status shall default to
New. - A vehicle document may include
status_notes. - A vehicle document record shall include
created_atandupdated_attimestamps. - A company shall not repeat vehicle document names (
(company_id, name)unique). - Deleting a company or vehicle shall delete related vehicle documents.
14. Subscription and Billing Constraints
- A subscription plan shall belong to an existing application.
- A subscription plan shall include
provider,provider_plan_id, and internalnameunique within its application ((application_id, name)unique). - The pair
(provider, provider_plan_id)shall be unique. - A subscription plan shall include
amountwith 4 decimal precision and default0.0000. - Subscription plan
currencyshall default toMXNwhen not provided. - Subscription plan limits shall default to:
limit_users=2,limit_loads=4,limit_shipments=4,limit_privacy_allowed=0. - A subscription plan shall include
created_atandupdated_attimestamps. - A company subscription shall reference an existing company and subscription plan.
- A company shall have at most one company subscription (
company_idunique incompany_subscriptions). - Company subscription status shall be one of:
Pending,Active,PastDue,Unpaid,Cancelled,Paused. - Company subscription status shall default to
Unpaid. - A company subscription shall include
provider_subscription_id. - A company subscription may include
start_date,current_period_start,current_period_end,cancelled_at, andcancelled_at_period_end. - A company subscription shall include
created_atandupdated_attimestamps. - Company and plan rows referenced by company subscriptions shall not be deletable while dependent subscriptions exist (
ON DELETE NO ACTION). - A payment method shall belong to an existing company.
- A payment method shall include
provider,provider_payment_id,last4,brand, andname. - The pair
(provider, provider_payment_id)shall be unique among payment methods. - Payment method
is_primaryshall default to0. - A payment method shall include
created_atandupdated_attimestamps. - A company row referenced by payment methods shall not be deletable while dependent payment methods exist (
ON DELETE NO ACTION). - A company limits record shall belong to an existing company.
- A company shall have at most one limits record (
company_idunique). - Company limits shall default to:
available_users=2,available_shipments=4,available_loads=4,privacy_allowed=0. - A company limits record shall include
created_atandupdated_attimestamps. - Deleting a company shall delete related company limits records.