138 lines
3.7 KiB
Markdown
138 lines
3.7 KiB
Markdown
# Squad History Feature
|
|
|
|
## Overview
|
|
|
|
The squad history feature preserves historical match squad data when resetting for a new match. Previously, when the squad was reset, all player data was lost. Now it's automatically archived to a dedicated history table.
|
|
|
|
## What Changed
|
|
|
|
### Before
|
|
- Squad reset would delete or overwrite previous squad data
|
|
- No way to view who played in previous matches
|
|
- Historical squad information was lost forever
|
|
|
|
### After
|
|
- Squad data is **automatically archived** before being cleared
|
|
- Complete historical record preserved with match date and fixture number
|
|
- New admin interface to view all historical squads
|
|
- Easy lookup of who played in any previous match
|
|
|
|
## How It Works
|
|
|
|
### When You Reset the Squad
|
|
|
|
1. **Automatic Archival**: Before clearing the current squad, the system:
|
|
- Copies all players to the `squad_history` table
|
|
- Stores the match date and fixture number
|
|
- Records when the archive was created
|
|
|
|
2. **Clean Reset**: The current squad table is cleared for the new match
|
|
|
|
3. **Confirmation**: Shows how many players were archived
|
|
|
|
### Database Structure
|
|
|
|
**New Table: `squad_history`**
|
|
```sql
|
|
- id (primary key)
|
|
- player_number
|
|
- player_forenames
|
|
- player_surname
|
|
- player_nickname
|
|
- match_date
|
|
- fixture_number
|
|
- archived_at (timestamp)
|
|
```
|
|
|
|
## Using the Feature
|
|
|
|
### Resetting the Squad (with History)
|
|
|
|
1. Go to **Admin Dashboard** → **Match Squad Management**
|
|
2. Click **"Reset Squad"**
|
|
3. System automatically:
|
|
- Archives current squad with match details
|
|
- Clears squad for new match
|
|
- Shows confirmation message
|
|
|
|
### Viewing Squad History
|
|
|
|
1. Go to **Admin Dashboard** → **Squad History**
|
|
2. See summary of all historical squads
|
|
3. Click **"View Details"** on any fixture to see the full squad
|
|
4. Scroll to see detailed player lists for each match
|
|
|
|
## Migration
|
|
|
|
The migration has been **automatically completed**! ✅
|
|
|
|
The `squad_history` table was created successfully.
|
|
|
|
For future databases or if needed again:
|
|
```bash
|
|
python add_squad_history.py
|
|
```
|
|
|
|
## Features
|
|
|
|
✅ **Automatic Archival**: No manual steps needed
|
|
✅ **Complete Records**: All player details preserved
|
|
✅ **Easy Navigation**: Summary view with drill-down details
|
|
✅ **Match Context**: Linked to match date and fixture number
|
|
✅ **Safe Reset**: Squad clearing only happens after successful archive
|
|
|
|
## Admin Interface
|
|
|
|
### Squad History Page Shows:
|
|
|
|
**Summary Table:**
|
|
- Fixture Number
|
|
- Match Date
|
|
- Player Count
|
|
- Quick view button
|
|
|
|
**Detailed View:**
|
|
- Full squad rosters grouped by match
|
|
- Player numbers, nicknames, and full names
|
|
- Archive timestamp for audit trail
|
|
|
|
## Benefits
|
|
|
|
1. **Historical Reference**: See who played in any match
|
|
2. **Team Analysis**: Track player participation over time
|
|
3. **Data Integrity**: No more lost squad data
|
|
4. **Audit Trail**: Know when squads were archived
|
|
5. **Reporting**: Export or analyze squad patterns
|
|
|
|
## Technical Details
|
|
|
|
### Files Modified
|
|
|
|
1. **`database.py`** - Added `SquadHistory` model
|
|
2. **`main.py`** - Updated reset function and added history route
|
|
3. **`templates/squad_history.html`** - New history viewing interface
|
|
4. **`add_squad_history.py`** - Migration script
|
|
|
|
### Safety Features
|
|
|
|
- Transaction-based: Archive completes before deletion
|
|
- Error handling: If archive fails, squad is not cleared
|
|
- Flash messages: Clear feedback on what happened
|
|
- Rollback capable: Can restore from history if needed
|
|
|
|
## Future Enhancements
|
|
|
|
Potential additions for future versions:
|
|
- Export squad history to CSV/Excel
|
|
- Compare squads between matches
|
|
- Player participation statistics
|
|
- Squad restoration from history
|
|
- Search/filter historical squads
|
|
- Visual squad timeline
|
|
|
|
---
|
|
|
|
**Implementation Date**: October 2025
|
|
**Status**: ✅ Active and Working
|
|
|