AdventureWorks Models
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The AdventureWorks Models represent the core data entities within the SeaORM Pro project, specifically derived from the AdventureWorks Light (LT) dataset. These models define the structure, relationships, and constraints of the database schema used for the admin panel demonstration. They are implemented using the SeaORM framework, leveraging procedural macros for entity definitions and relation mapping.
These entities facilitate a wide range of features, including GraphQL schema generation via Seaography and automated data seeding for development environments. The models cover critical business domains such as customer management, product inventories, and sales order processing.
Sources: README.md, src/tasks/seed.rs:69-80, src/graphql/query_root.rs:41-43
Domain Entities
Sales and Customer Management
The system tracks customers and their related transactions through highly interconnected entities. The Customer entity stores personal and authentication data, while SalesOrderHeader and SalesOrderDetail manage transaction records.
The following ER diagram illustrates the relationships between customers, addresses, and sales orders:
Diagram shows the flow from customer identity to specific order line items.
Sources: src/models/customer.rs:37-41, src/models/sales_order_header.rs:59-81, src/models/sales_order_detail.rs:33-47
Product Catalog and Specifications
Products are categorized and linked to specific models and descriptions. The schema uses a junction table, ProductModelProductDescription, to handle many-to-many relationships between product models and localized descriptions (culture).
| Field | Type | Description |
|---|---|---|
product_id | i32 | Primary key for products. |
name | String | Unique product name. |
standard_cost | f64 | Unit cost of the product. |
weight | Decimal | Physical weight (optional). |
product_model_id | i32 | FK to the Product Model. |
Sources: src/models/product.rs:10-31, src/models/product_model_product_description.rs:10-21
Implementation Details
SeaORM Entity Definitions
Entities are defined as Rust structs with the DeriveEntityModel macro. They include serde attributes for handling data ingestion, particularly for custom date-time formats during seeding.
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize)]
#[sea_orm(table_name = "product")]
pub struct Model {
#[sea_orm(primary_key)]
pub product_id: i32,
#[sea_orm(unique)]
pub name: String,
#[serde(deserialize_with = "super::utils::date_time_from_str")]
pub created_date: DateTime,
}
Sources: src/models/product.rs:8-32, src/models/customer.rs:8-33
Data Seeding Architecture
The SeedData task handles the initialization of the AdventureWorks dataset from TSV files. It utilizes different encodings (Windows-1252, UTF-16LE) and delimiters depending on the source file requirements.
Diagram illustrates the sequential seeding process for the AdventureWorks dataset.
Sources: src/tasks/seed.rs:43-85
Conclusion
The AdventureWorks Models serve as the foundational schema for the SeaORM Pro demonstration. By utilizing SeaORM's active model patterns and complex relationship mappings, the project demonstrates a robust implementation of a standard retail database. These models are essential for both the GraphQL API layer and the administrative dashboard, providing a realistic data structure for testing and development.
Sources: README.md, src/tasks/seed.rs:107-133