feat: Enhance schema with new models and relationships for notifications, contracts, seasons, and related entities
- Added Notification and NotificationRecipient models for managing user notifications. - Introduced Contract model to handle agreements between farmers and buyers, including pricing and terms. - Created Season, PlotSeason, and SeasonHarvest models to manage agricultural seasons and their associated data. - Added Currency, Country, and Religion models to standardize related data. - Updated existing models to reference new entities and changed data types for monetary values to Decimal for precision. - Removed enums for EducationLevel and Religion, replacing them with corresponding models.
This commit is contained in:
parent
d3614a335d
commit
dacae9e70e
|
|
@ -7,21 +7,25 @@ This comprehensive database schema is designed for a modern agricultural technol
|
|||
## Table of Contents
|
||||
|
||||
1. [Core User Management](#core-user-management)
|
||||
2. [Farm Management](#farm-management)
|
||||
3. [Product & Variant System](#product--variant-system)
|
||||
4. [Procurement & Trading](#procurement--trading)
|
||||
5. [Weather & Climate Data](#weather--climate-data)
|
||||
6. [Input Management](#input-management)
|
||||
7. [Labor Management](#labor-management)
|
||||
8. [Equipment & Asset Management](#equipment--asset-management)
|
||||
9. [Pest & Disease Management](#pest--disease-management)
|
||||
10. [Financial Management](#financial-management)
|
||||
11. [Soil Analysis](#soil-analysis)
|
||||
12. [Communication System](#communication-system)
|
||||
13. [Market Intelligence](#market-intelligence)
|
||||
14. [Training & Certification](#training--certification)
|
||||
15. [Knowledge Base](#knowledge-base)
|
||||
16. [Attachment Systems](#attachment-systems)
|
||||
2. [Reference Data Management](#reference-data-management)
|
||||
3. [Farm Management](#farm-management)
|
||||
4. [Product & Variant System](#product--variant-system)
|
||||
5. [Procurement & Trading](#procurement--trading)
|
||||
6. [Contract Management](#contract-management)
|
||||
7. [Season & Cycle Management](#season--cycle-management)
|
||||
8. [Weather & Climate Data](#weather--climate-data)
|
||||
9. [Input Management](#input-management)
|
||||
10. [Labor Management](#labor-management)
|
||||
11. [Equipment & Asset Management](#equipment--asset-management)
|
||||
12. [Pest & Disease Management](#pest--disease-management)
|
||||
13. [Financial Management](#financial-management)
|
||||
14. [Soil Analysis](#soil-analysis)
|
||||
15. [Communication & Notifications](#communication--notifications)
|
||||
16. [Market Intelligence](#market-intelligence)
|
||||
17. [Training & Certification](#training--certification)
|
||||
18. [Knowledge Base](#knowledge-base)
|
||||
19. [Attachment Systems](#attachment-systems)
|
||||
20. [Data Types & Performance](#data-types--performance)
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -110,6 +114,78 @@ This comprehensive database schema is designed for a modern agricultural technol
|
|||
|
||||
---
|
||||
|
||||
## Reference Data Management
|
||||
|
||||
### Country
|
||||
**Purpose**: Standardized country and nationality management
|
||||
**Key Features**:
|
||||
- ISO standard country codes and names
|
||||
- Regional and continental classification
|
||||
- Support for nationality vs. residence country
|
||||
- Centralized country data management
|
||||
|
||||
**Fields**:
|
||||
- `id`: ISO country code (e.g., "indonesia", "malaysia")
|
||||
- `name`: Full country name
|
||||
- `code`: ISO 3166-1 alpha-2 code (e.g., "ID", "MY")
|
||||
- `region`: Geographic region
|
||||
- `continent`: Continental classification
|
||||
- `isActive`: Status flag
|
||||
|
||||
**Relations**: Connected to Farmer nationality and country fields
|
||||
|
||||
### Currency
|
||||
**Purpose**: Multi-currency support for financial transactions
|
||||
**Key Features**:
|
||||
- ISO 4217 currency standard compliance
|
||||
- Symbol and formatting support
|
||||
- Active currency management
|
||||
- Financial system integration
|
||||
|
||||
**Fields**:
|
||||
- `id`: ISO currency code (e.g., "idr", "usd")
|
||||
- `name`: Full currency name
|
||||
- `code`: ISO 4217 currency code (e.g., "IDR", "USD")
|
||||
- `symbol`: Currency symbol (₹, $, Rp, etc.)
|
||||
- `isActive`: Status flag
|
||||
|
||||
**Relations**: Connected to FinancialRecord for multi-currency transactions
|
||||
|
||||
### Religion
|
||||
**Purpose**: Religious affiliation reference data
|
||||
**Key Features**:
|
||||
- Standardized religious categories
|
||||
- Descriptive information
|
||||
- Cultural sensitivity support
|
||||
- Demographic analysis capability
|
||||
|
||||
**Fields**:
|
||||
- `id`: Unique identifier
|
||||
- `name`: Religion name (e.g., "Islam", "Christianity")
|
||||
- `description`: Additional information
|
||||
- `isActive`: Status flag
|
||||
|
||||
**Relations**: Connected to Farmer religious affiliation
|
||||
|
||||
### EducationLevel
|
||||
**Purpose**: Hierarchical education level classification
|
||||
**Key Features**:
|
||||
- Structured education levels
|
||||
- Numerical hierarchy for analysis
|
||||
- International education standards
|
||||
- Progress tracking support
|
||||
|
||||
**Fields**:
|
||||
- `id`: Unique identifier
|
||||
- `name`: Education level name
|
||||
- `level`: Numerical hierarchy (0=No formal, 1=Elementary, etc.)
|
||||
- `description`: Level details
|
||||
- `isActive`: Status flag
|
||||
|
||||
**Relations**: Connected to Farmer education tracking
|
||||
|
||||
---
|
||||
|
||||
## Farm Management
|
||||
|
||||
### Farm
|
||||
|
|
@ -300,6 +376,172 @@ This comprehensive database schema is designed for a modern agricultural technol
|
|||
|
||||
---
|
||||
|
||||
## Contract Management
|
||||
|
||||
### Contract
|
||||
**Purpose**: Formal farmer-buyer agreement management
|
||||
**Key Features**:
|
||||
- Comprehensive contract lifecycle management
|
||||
- Multi-type agreement support
|
||||
- Legal compliance and documentation
|
||||
- Performance tracking and analytics
|
||||
|
||||
**Agreement Details**:
|
||||
- Contract identification and numbering
|
||||
- Agreement type classification (purchase, supply, exclusive, etc.)
|
||||
- Title, description, and terms documentation
|
||||
- Legal framework and governing law
|
||||
|
||||
**Commercial Terms**:
|
||||
- Pricing structure and payment terms
|
||||
- Quantity specifications (minimum/maximum)
|
||||
- Quality requirements and grading
|
||||
- Delivery schedules and logistics
|
||||
|
||||
**Financial Management**:
|
||||
- Agreed pricing per unit
|
||||
- Total contract value calculation
|
||||
- Advance payment terms and percentages
|
||||
- Payment method specification
|
||||
|
||||
**Legal Framework**:
|
||||
- Terms and conditions documentation
|
||||
- Penalty clauses and enforcement
|
||||
- Force majeure provisions
|
||||
- Governing law specification
|
||||
|
||||
**Status Management**:
|
||||
- Contract lifecycle stages (draft → active → fulfilled)
|
||||
- Digital signature support
|
||||
- Witness documentation
|
||||
- Amendment and renewal tracking
|
||||
|
||||
**Performance Tracking**:
|
||||
- Delivery quantity monitoring
|
||||
- Payment completion tracking
|
||||
- Contract fulfillment analytics
|
||||
- Breach and dispute management
|
||||
|
||||
**Relations**: Connected to farmers, buyers, products, variants, and procurement deliveries
|
||||
|
||||
---
|
||||
|
||||
## Season & Cycle Management
|
||||
|
||||
### Season
|
||||
**Purpose**: Agricultural season and cycle planning
|
||||
**Key Features**:
|
||||
- Seasonal calendar management
|
||||
- Weather pattern integration
|
||||
- Crop recommendation system
|
||||
- Market outlook planning
|
||||
|
||||
**Season Definition**:
|
||||
- Season naming and type classification
|
||||
- Annual calendar integration
|
||||
- Geographic scope (region, province, country)
|
||||
- Start and end date management
|
||||
|
||||
**Agricultural Phases**:
|
||||
- Planting window definition
|
||||
- Growing period tracking
|
||||
- Harvest season planning
|
||||
- Activity scheduling support
|
||||
|
||||
**Weather Integration**:
|
||||
- Average rainfall and temperature
|
||||
- Humidity and climate conditions
|
||||
- Historical weather pattern analysis
|
||||
- Forecast integration
|
||||
|
||||
**Crop Management**:
|
||||
- Recommended crop varieties
|
||||
- Crops to avoid listing
|
||||
- Seasonal suitability analysis
|
||||
- Agricultural activity planning
|
||||
|
||||
**Market Intelligence**:
|
||||
- Expected demand forecasting
|
||||
- Price outlook analysis
|
||||
- Market trend integration
|
||||
- Supply chain planning
|
||||
|
||||
**Relations**: Connected to plot seasons, harvest summaries, and weather data
|
||||
|
||||
### PlotSeason
|
||||
**Purpose**: Individual plot seasonal planning and tracking
|
||||
**Key Features**:
|
||||
- Plot-specific seasonal management
|
||||
- Crop variety assignment
|
||||
- Yield planning and tracking
|
||||
- Performance comparison
|
||||
|
||||
**Planting Management**:
|
||||
- Planted area tracking
|
||||
- Seed variety specification
|
||||
- Planting date documentation
|
||||
- Growth stage monitoring
|
||||
|
||||
**Yield Planning**:
|
||||
- Expected yield per hectare
|
||||
- Total harvest projections
|
||||
- Harvest date estimation
|
||||
- Planning vs. actual comparison
|
||||
|
||||
**Performance Analytics**:
|
||||
- Actual yield measurement
|
||||
- Productivity analysis
|
||||
- Seasonal performance comparison
|
||||
- Optimization recommendations
|
||||
|
||||
**Relations**: Connected to plots, seasons, products, and variants
|
||||
|
||||
### SeasonHarvest
|
||||
**Purpose**: Aggregated seasonal harvest analytics
|
||||
**Key Features**:
|
||||
- Farmer-level seasonal summaries
|
||||
- Product performance analysis
|
||||
- Quality and value tracking
|
||||
- Multi-harvest aggregation
|
||||
|
||||
**Performance Metrics**:
|
||||
- Total quantity harvested
|
||||
- Average quality grades
|
||||
- Total financial value
|
||||
- Harvest frequency tracking
|
||||
|
||||
**Timeline Management**:
|
||||
- First and last harvest dates
|
||||
- Harvest window analysis
|
||||
- Seasonal duration tracking
|
||||
- Peak harvest identification
|
||||
|
||||
**Relations**: Connected to seasons, farmers, products, and variants
|
||||
|
||||
### SeasonWeather
|
||||
**Purpose**: Seasonal weather analysis and impact assessment
|
||||
**Key Features**:
|
||||
- Aggregated weather data
|
||||
- Extreme event tracking
|
||||
- Agricultural impact analysis
|
||||
- Climate pattern documentation
|
||||
|
||||
**Weather Analytics**:
|
||||
- Cumulative rainfall totals
|
||||
- Temperature range analysis
|
||||
- Humidity and climate summaries
|
||||
- Weather pattern identification
|
||||
|
||||
**Impact Assessment**:
|
||||
- Crop damage evaluation
|
||||
- Yield impact analysis
|
||||
- Weather correlation studies
|
||||
- Risk factor identification
|
||||
|
||||
**Relations**: Connected to seasons for regional weather analysis
|
||||
|
||||
---
|
||||
|
||||
## Weather & Climate Data
|
||||
|
||||
### WeatherData
|
||||
|
|
@ -609,21 +851,75 @@ This comprehensive database schema is designed for a modern agricultural technol
|
|||
|
||||
---
|
||||
|
||||
## Communication System
|
||||
## Communication & Notifications
|
||||
|
||||
### Notification
|
||||
**Purpose**: Comprehensive notification and alert system
|
||||
**Key Features**:
|
||||
- Multi-channel notification delivery
|
||||
- Targeted and personalized messaging
|
||||
- Scheduled notification support
|
||||
- Analytics and engagement tracking
|
||||
|
||||
**Notification Management**:
|
||||
- Rich content support (text, images, actions)
|
||||
- Deep linking and call-to-action buttons
|
||||
- Expiration date management
|
||||
- Priority-based delivery
|
||||
|
||||
**Targeting Options**:
|
||||
- Individual user targeting
|
||||
- Role-based broadcasting (farmers, buyers)
|
||||
- Geographic targeting (region, province)
|
||||
- Product-specific notifications
|
||||
- Custom audience segments
|
||||
|
||||
**Content Types**:
|
||||
- System alerts and warnings
|
||||
- Market price updates
|
||||
- Weather warnings and forecasts
|
||||
- Training and certification reminders
|
||||
- Payment and procurement notifications
|
||||
- Maintenance and equipment alerts
|
||||
|
||||
**Analytics and Tracking**:
|
||||
- Delivery confirmation
|
||||
- Read receipt tracking
|
||||
- Click-through analytics
|
||||
- Engagement measurement
|
||||
- Performance optimization
|
||||
|
||||
**Relations**: Connected to all user types through NotificationRecipient
|
||||
|
||||
### NotificationRecipient
|
||||
**Purpose**: Individual notification delivery and tracking
|
||||
**Key Features**:
|
||||
- Per-user delivery status
|
||||
- Read and interaction tracking
|
||||
- Delivery confirmation
|
||||
- User-specific analytics
|
||||
|
||||
**Tracking Metrics**:
|
||||
- Delivery status and timestamp
|
||||
- Read status and time
|
||||
- Click tracking and engagement
|
||||
- User response patterns
|
||||
|
||||
**Relations**: Connected to notifications and users
|
||||
|
||||
### Message
|
||||
**Purpose**: Platform-wide communication and notification system
|
||||
**Purpose**: Direct communication between platform users
|
||||
**Key Features**:
|
||||
- Multi-type messaging support
|
||||
- Priority-based delivery
|
||||
- Attachment support
|
||||
- Delivery status tracking
|
||||
- Personal messaging support
|
||||
- Group communication
|
||||
- Attachment handling
|
||||
- Message threading
|
||||
|
||||
**Message Types**:
|
||||
- Personal messages between users
|
||||
- Broadcast announcements
|
||||
- System notifications and alerts
|
||||
- Emergency communications
|
||||
- Group discussions
|
||||
- Administrative communications
|
||||
- Support conversations
|
||||
|
||||
**Delivery Management**:
|
||||
- Priority levels (low to critical)
|
||||
|
|
@ -787,7 +1083,51 @@ This comprehensive database schema is designed for a modern agricultural technol
|
|||
|
||||
---
|
||||
|
||||
## Enums and Data Types
|
||||
## Data Types & Performance
|
||||
|
||||
### Data Type Optimization
|
||||
|
||||
**Financial Precision**:
|
||||
All financial and monetary fields use `Decimal` type for precision:
|
||||
- Pricing fields (basePrice, totalPrice, finalAmount)
|
||||
- Cost tracking (transportCost, processingCost, wages)
|
||||
- Financial amounts (income, investment, credit limits)
|
||||
- Currency amounts and exchange rates
|
||||
|
||||
**Measurement Precision**:
|
||||
Scientific and agricultural measurements use `Decimal` for accuracy:
|
||||
- Quantities (harvest amounts, procurement volumes)
|
||||
- Percentages (water content, premiums, tax rates)
|
||||
- Chemical concentrations and soil nutrients
|
||||
- Area measurements and yield calculations
|
||||
- Quality ratings and scores
|
||||
|
||||
**Geographic Coordinates**:
|
||||
Location data uses `Float` for standard GPS compatibility:
|
||||
- Latitude and longitude coordinates
|
||||
- Elevation and distance measurements
|
||||
- Weather data (temperature, pressure, wind speed)
|
||||
|
||||
**Large Value Support**:
|
||||
High-volume counters use `BigInt`:
|
||||
- Article view counts
|
||||
- Large transaction volumes
|
||||
- System usage statistics
|
||||
|
||||
### Normalized Reference Data
|
||||
|
||||
**Benefits of Normalization**:
|
||||
- Improved data consistency and integrity
|
||||
- Enhanced maintainability and updates
|
||||
- Support for internationalization
|
||||
- Better analytics and reporting capabilities
|
||||
- Reduced storage redundancy
|
||||
|
||||
**Normalized Tables**:
|
||||
- `Country`: ISO-compliant country and nationality data
|
||||
- `Currency`: Multi-currency support with ISO 4217 standards
|
||||
- `Religion`: Standardized religious classification
|
||||
- `EducationLevel`: Hierarchical education tracking
|
||||
|
||||
### Key Enumerations
|
||||
|
||||
|
|
@ -796,9 +1136,21 @@ This comprehensive database schema is designed for a modern agricultural technol
|
|||
- `Gender`: MALE, FEMALE, OTHER
|
||||
- `MaritalStatus`: SINGLE, MARRIED, DIVORCED, WIDOWED, SEPARATED
|
||||
- `IdentityType`: KTP, PASSPORT, DRIVING_LICENSE, OTHER
|
||||
- `EducationLevel`: NO_FORMAL_EDUCATION to DOCTORATE
|
||||
- `FarmerStatus`: ACTIVE, INACTIVE, SUSPENDED, PENDING_VERIFICATION, BLACKLISTED
|
||||
|
||||
**Contract Management**:
|
||||
- `AgreementType`: PURCHASE_AGREEMENT, SUPPLY_CONTRACT, EXCLUSIVE_SUPPLY, etc.
|
||||
- `ContractStatus`: DRAFT, PENDING_REVIEW, ACTIVE, FULFILLED, EXPIRED, etc.
|
||||
|
||||
**Season Management**:
|
||||
- `SeasonType`: WET_SEASON, DRY_SEASON, TRANSITION, YEAR_ROUND, etc.
|
||||
- `PlantingStatus`: PLANNED, PLANTED, GROWING, HARVESTING, HARVESTED, etc.
|
||||
|
||||
**Notification System**:
|
||||
- `NotificationType`: SYSTEM, ANNOUNCEMENT, ALERT, REMINDER, etc.
|
||||
- `NotificationCategory`: GENERAL, PROCUREMENT, PAYMENT, WEATHER, etc.
|
||||
- `NotificationStatus`: PENDING, SCHEDULED, SENT, DELIVERED, FAILED, etc.
|
||||
|
||||
**Agricultural Operations**:
|
||||
- `QualityGrade`: A, B, C
|
||||
- `InputType`: SEED, FERTILIZER, PESTICIDE, HERBICIDE, FUNGICIDE, etc.
|
||||
|
|
@ -825,22 +1177,50 @@ This comprehensive database schema is designed for a modern agricultural technol
|
|||
|
||||
**User Hierarchy**:
|
||||
- User → Farmer/Buyer/Administrator (one-to-one)
|
||||
- User → NotificationRecipient (one-to-many)
|
||||
- Farmer → Farms (one-to-many)
|
||||
- Farm → Plots (one-to-many)
|
||||
|
||||
**Reference Data Integration**:
|
||||
- Farmer → Country (nationality and residence)
|
||||
- Farmer → Religion (religious affiliation)
|
||||
- Farmer → EducationLevel (education tracking)
|
||||
- FinancialRecord → Currency (multi-currency support)
|
||||
|
||||
**Agricultural Operations**:
|
||||
- Plot → Harvests (one-to-many)
|
||||
- Plot → PlotSeason (seasonal planning)
|
||||
- Harvest → Procurement (one-to-one)
|
||||
- Product → Variants → Harvests (hierarchical)
|
||||
- Season → PlotSeason → Plot (seasonal management)
|
||||
|
||||
**Contract Management**:
|
||||
- Farmer ↔ Buyer → Contract (bilateral agreements)
|
||||
- Contract → Procurement (contract fulfillment)
|
||||
- Product/Variant → Contract (product specifications)
|
||||
|
||||
**Seasonal Planning**:
|
||||
- Season → PlotSeason (plot-level planning)
|
||||
- Season → SeasonHarvest (aggregated outcomes)
|
||||
- Season → SeasonWeather (seasonal climate data)
|
||||
- Plot → PlotSeason → Season (cyclical relationships)
|
||||
|
||||
**Communication Systems**:
|
||||
- Notification → NotificationRecipient (delivery tracking)
|
||||
- User → NotificationRecipient (user-specific delivery)
|
||||
- Message → User (direct communication)
|
||||
|
||||
**Support Systems**:
|
||||
- Farm/Plot → Weather Data (location-based)
|
||||
- Farm/Plot → Input Applications (activity-based)
|
||||
- Farm/Plot → Labor Records (work-based)
|
||||
- Equipment → MaintenanceRecord (service history)
|
||||
- Equipment → EquipmentUsage (utilization tracking)
|
||||
|
||||
**Documentation**:
|
||||
- All major entities → Attachments (comprehensive documentation)
|
||||
- Financial Records → Multiple entities (cost allocation)
|
||||
- Contract → Attachments (legal documentation)
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -919,4 +1299,51 @@ This comprehensive database schema is designed for a modern agricultural technol
|
|||
|
||||
---
|
||||
|
||||
This comprehensive schema provides the foundation for a complete agricultural technology platform that supports farmers from production planning through market delivery, with integrated training, certification, and financial management capabilities.
|
||||
## Schema Evolution and Improvements
|
||||
|
||||
### Recent Enhancements
|
||||
|
||||
**Data Type Optimization (v2.0)**:
|
||||
- Migrated from `Float` to `Decimal` for all financial and precise measurement fields
|
||||
- Implemented `BigInt` for high-volume counters
|
||||
- Maintained `Float` for geographic coordinates and weather data
|
||||
|
||||
**Reference Data Normalization (v2.0)**:
|
||||
- Converted static enums to dynamic reference tables
|
||||
- Implemented Country, Currency, Religion, and EducationLevel tables
|
||||
- Enhanced internationalization and maintainability
|
||||
|
||||
**Contract Management System (v2.0)**:
|
||||
- Added comprehensive contract lifecycle management
|
||||
- Integrated legal compliance and performance tracking
|
||||
- Connected procurement deliveries to contract fulfillment
|
||||
|
||||
**Advanced Notification System (v2.0)**:
|
||||
- Implemented rich notification management with targeting
|
||||
- Added delivery tracking and engagement analytics
|
||||
- Integrated with all system workflows and alerts
|
||||
|
||||
**Seasonal Planning Framework (v2.0)**:
|
||||
- Added Season, PlotSeason, SeasonHarvest, and SeasonWeather models
|
||||
- Implemented agricultural cycle planning and tracking
|
||||
- Enhanced yield planning and performance analytics
|
||||
|
||||
### Benefits of Current Schema
|
||||
|
||||
**Financial Accuracy**: Decimal precision ensures accurate financial calculations and eliminates floating-point errors in monetary transactions.
|
||||
|
||||
**Scalability**: Normalized reference data and optimized data types support platform growth and international expansion.
|
||||
|
||||
**Compliance**: Formal contract management and audit trails meet legal and regulatory requirements.
|
||||
|
||||
**User Experience**: Advanced notification system provides targeted, relevant information to users.
|
||||
|
||||
**Agricultural Intelligence**: Seasonal planning framework enables data-driven farming decisions and optimization.
|
||||
|
||||
**Data Integrity**: Comprehensive relationships and constraints ensure data consistency across the platform.
|
||||
|
||||
**Performance**: Optimized data types and indexing strategies support high-volume operations and fast queries.
|
||||
|
||||
---
|
||||
|
||||
This comprehensive schema provides the foundation for a complete agricultural technology platform that supports farmers from production planning through market delivery, with integrated training, certification, and financial management capabilities. The recent enhancements ensure scalability, accuracy, and compliance while providing advanced features for contract management, seasonal planning, and user engagement.
|
||||
687
schema.prisma
687
schema.prisma
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue