12 KiB
12 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, permission, and application.
- The pair
(role_id, permission_id)shall be unique. - Deleting an application, role, or permission shall delete related role-permission assignments.
- A user-role assignment shall reference an existing user, role, and application.
- The pair
(user_id, role_id)shall be unique. - 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_atandexpires_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
privacy_enabledshall default to0. - Company
disabledshall default to0. - 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, andtruck_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
VINandtruck_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 truck plate (
(company_id, truck_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 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 its load shipment.
- 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 shipment evidences.
- 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.
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). - 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, truck_type)unique). - Deleting a company shall delete its company vehicle types.
- A location-category assignment shall reference an existing location and existing company sector.
- A location shall not repeat the same category (
(location_id, category_id)unique). - Deleting a location or company sector shall delete related location-category 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). - 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). - 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). - 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_at. - 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). - 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). - 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). - 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 shall include
notes(NOT NULL). - 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 shall include
status_notes(NOT NULL). - 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 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.
- An API key record shall include
created_atandupdated_attimestamps. - Deleting an application shall delete related API keys.
- An API key permission record shall belong to an existing application, permission, and API key.
- API key permission assignments shall include
created_at. - An API key shall not repeat the same permission assignment (
(apikey_id, permission_id)unique). - Deleting an application, permission, or API key shall delete related API key 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 shall include
status_notes(NOT NULL). - 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.