TurnFix Database Schema Documentation¶
Version: 2.0 | Last Updated: 2025-10-31
This document provides a comprehensive overview of the TurnFix PostgreSQL database schema, including all tables, fields, data types, and relationships.
β Legacy Schema Compatibility¶
The TurnFix database maintains full compatibility with the original C++/Qt application database structure. All table and column names follow the original naming conventions:
- Table prefix:
tfx_(e.g.,tfx_disziplinen) - Column naming convention:
int_= Integer columnsvar_= String/Text columnsbol_= Boolean columnsflt_= Float columnsdat_= Date columns
π Core Tables¶
1. tfx_bereiche (Categories/Regions)¶
Stores geographic regions and administrative areas.
Table: tfx_bereiche
βββ int_bereicheid (PK, AutoIncrement) - Primary key
βββ var_name (String, NOT NULL) - Region name (e.g., "Bayern")
βββ Relationships: β tfx_disziplinen, tfx_veranstalter, tfx_verband, tfx_verein
Constraints:
- Primary Key: int_bereicheid
- Foreign Key Relations: Referenced by multiple tables for regional organization
2. tfx_verband (Associations/Federations)¶
Stores sports federations and associations (e.g., DTB - Deutscher Turner-Bund).
Table: tfx_verband
βββ int_verbandid (PK, AutoIncrement) - Primary key
βββ int_bereicheid (FK) - Region identifier
βββ var_name (String, NOT NULL) - Association name
βββ var_kurzname (String) - Short name
βββ Relationships: β tfx_verein, tfx_veranstalter
Constraints:
- Primary Key: int_verbandid
- Foreign Key: int_bereicheid β tfx_bereiche.int_bereicheid
- Cascade Delete Rule (from tfx_bereiche)
3. tfx_verein (Clubs/Associations)¶
Stores individual gymnastics clubs/organizations.
Table: tfx_verein
βββ int_vereinid (PK, AutoIncrement) - Primary key
βββ int_verbandid (FK) - Federation identifier
βββ int_bereicheid (FK) - Region identifier
βββ var_name (String, NOT NULL) - Club name
βββ var_kurzname (String) - Short name
βββ var_ort (String) - Location/City
βββ var_strasse (String) - Street address
βββ var_plz (String) - Postal code
βββ var_telefon (String) - Phone number
βββ var_kontaktperson (String) - Contact person
βββ var_email (String) - Email address
βββ Relationships: β tfx_person, tfx_veranstalter, tfx_mannschaft
Constraints:
- Primary Key: int_vereinid
- Foreign Keys:
- int_verbandid β tfx_verband.int_verbandid
- int_bereicheid β tfx_bereiche.int_bereicheid
- Cascade Delete Rules
4. tfx_person (Participants/Athletes)¶
Stores individual athletes/participants in competitions.
Table: tfx_person
βββ int_personid (PK, AutoIncrement) - Primary key
βββ int_vereinid (FK) - Club identifier
βββ var_vorname (String, NOT NULL) - First name
βββ var_nachname (String, NOT NULL) - Last name
βββ var_kurzname (String) - Short name
βββ dat_geburtsdatum (Date) - Date of birth
βββ var_geschlecht (String) - Gender ('mΓ€nnlich' | 'weiblich')
βββ var_startnum (String) - Start number
βββ var_passnummer (String) - Passport number
βββ var_behinderung (String) - Disability information
βββ bol_aktiv (Boolean) - Active status
βββ var_notizen (String) - Notes
βββ Relationships: β tfx_wettkampfperson, tfx_mannschaft_person, tfx_wertung
Constraints:
- Primary Key: int_personid
- Foreign Key: int_vereinid β tfx_verein.int_vereinid
- Cascade Delete Rule
5. tfx_sport (Sport Categories)¶
Stores sport types/categories (e.g., "Turnen DTB", "Turnen DTB LK", "P-GerΓ€te").
Table: tfx_sport
βββ int_sportid (PK, AutoIncrement) - Primary key
βββ var_name (String, NOT NULL) - Sport name
βββ Relationships: β tfx_disziplinen
Constraints:
- Primary Key: int_sportid
- Unique constraint on var_name (implicit through design)
6. tfx_disziplinen (Devices/Disciplines)¶
Stores gymnastics devices and discipline types (e.g., Floor, Vault, Bars).
Table: tfx_disziplinen
βββ int_disziplinenid (PK, AutoIncrement) - Primary key
βββ int_bereicheid (FK) - Region identifier
βββ int_sportid (FK) - Sport category identifier
βββ var_name (String, NOT NULL) - Device name (e.g., "Boden", "Reck")
βββ var_anzeigename (String) - Display name
βββ var_kurzname (String) - Short name
βββ bol_m (Boolean) - Male allowed
βββ bol_w (Boolean) - Female allowed
βββ int_gymnetid (Integer) - GymNet system ID
βββ Relationships: β tfx_disziplinen_felder, tfx_disziplinen_gruppen, tfx_wettkampf_disziplin
Constraints:
- Primary Key: int_disziplinenid
- Foreign Keys:
- int_bereicheid β tfx_bereiche.int_bereicheid
- int_sportid β tfx_sport.int_sportid
- Cascade Delete Rules
Data Example:
| int_disziplinenid | var_name | bol_m | bol_w | int_sportid |
|---|---|---|---|---|
| 31 | Pferd | true | false | 1 |
| 46 | Reck | true | false | 1 |
| 50 | Ringe | true | false | 1 |
| 68 | Stufenbarren | false | true | 1 |
| 71 | Sprung | true | true | 2 |
| 73 | Schwebebalken | false | true | 1 |
| 74 | Boden | true | true | 1 |
| 75 | GerΓ€tebahn A | true | true | 3 |
| 76 | GerΓ€tebahn B | true | true | 3 |
| 77 | Minitrampolin | true | true | 3 |
7. tfx_disziplinen_felder (Device Fields/Scoring Components)¶
Stores field definitions for each device (e.g., "Γbungswert", "AbzΓΌge AusfΓΌhrung", "Endwert").
Table: tfx_disziplinen_felder
βββ int_feldid (PK, AutoIncrement) - Primary key
βββ int_disziplinenid (FK) - Device identifier
βββ var_name (String, NOT NULL) - Field name
βββ var_kurzname (String) - Short name
βββ int_position (Integer) - Display order
βββ var_feldartenid (String) - Field type
βββ bol_sichtbar (Boolean) - Visibility flag
βββ bol_bearbeitbar (Boolean) - Editable flag
βββ int_nachkomma (Integer) - Decimal places
βββ Relationships: β tfx_wertung
Constraints:
- Primary Key: int_feldid
- Foreign Key: int_disziplinenid β tfx_disziplinen.int_disziplinenid
- Cascade Delete Rule
Special Note - P-Device Fields: For P-device types (Minitrampolin, GerΓ€tebahn A/B), exactly 3 fields are created:
8. tfx_formeln (Calculation Formulas)¶
Stores mathematical formulas for score calculations.
Table: tfx_formeln
βββ int_formelid (PK, AutoIncrement) - Primary key
βββ int_disziplinenid (FK) - Device identifier
βββ var_name (String, NOT NULL) - Formula name
βββ var_formel (String, NOT NULL) - Formula expression
βββ var_typ (String) - Formula type (e.g., "Endwert", "Wertung")
βββ Relationships: β tfx_wertung
Constraints:
- Primary Key: int_formelid
- Foreign Key: int_disziplinenid β tfx_disziplinen.int_disziplinenid
- Cascade Delete Rule
Formula Examples:
Device: Boden (Floor)
βββ Endwert = Uebungsstufe + AbzugAusf.
βββ Wertung = Endwert
Device: Pferd (Vault)
βββ Endwert = Uebungsstufe + AbzugAusf.
βββ Wertung = Endwert
Device: Minitrampolin (P-Device)
βββ Endwert = Stufe + AbzugAusf.
βββ Wertung = Endwert
9. tfx_disziplinen_gruppen (Device Groups)¶
Groups related devices together (e.g., all male apparatuses, all female apparatuses).
Table: tfx_disziplinen_gruppen
βββ int_disziplinen_gruppeid (PK, AutoIncrement) - Primary key
βββ int_disziplinenid (FK) - Device identifier
βββ int_gruppeid (FK) - Group identifier
βββ var_name (String) - Group name
βββ Relationships: β tfx_gruppe
Constraints:
- Primary Key: int_disziplinen_gruppeid
- Foreign Keys:
- int_disziplinenid β tfx_disziplinen.int_disziplinenid
- int_gruppeid β tfx_gruppe.int_gruppeid
10. tfx_veranstaltung (Events)¶
Stores competition events (e.g., "Landesmeisterschaften 2024").
Table: tfx_veranstaltung
βββ int_veranstaltungid (PK, AutoIncrement) - Primary key
βββ int_verbandid (FK) - Federation identifier
βββ int_vereinid (FK) - Organizing club identifier
βββ int_bereicheid (FK) - Region identifier
βββ var_name (String, NOT NULL) - Event name
βββ var_kurzname (String) - Short name
βββ var_ort (String) - Location
βββ dat_von (Date) - Start date
βββ dat_bis (Date) - End date
βββ var_notizen (String) - Notes
βββ Relationships: β tfx_wettkampf, tfx_wettkampf_disziplin
Constraints:
- Primary Key: int_veranstaltungid
- Foreign Keys:
- int_verbandid β tfx_verband.int_verbandid
- int_vereinid β tfx_verein.int_vereinid
- int_bereicheid β tfx_bereiche.int_bereicheid
- Cascade Delete Rules
11. tfx_wettkampf (Competitions)¶
Stores individual competitions within an event.
Table: tfx_wettkampf
βββ int_wettkampfid (PK, AutoIncrement) - Primary key
βββ int_veranstaltungid (FK) - Event identifier
βββ var_name (String, NOT NULL) - Competition name
βββ var_type (String) - Competition type
βββ dat_wettkampftag (Date) - Competition date
βββ tim_start (Time) - Start time
βββ var_geschlecht (String) - Gender ('mΓ€nnlich' | 'weiblich' | 'gemischt')
βββ int_altersgruppe (Integer) - Age group
βββ var_klasse (String) - Class/Level
βββ bol_aktiv (Boolean) - Active status
βββ Relationships: β tfx_wettkampfperson, tfx_wettkampf_disziplin, tfx_durchgang, tfx_wertung
Constraints:
- Primary Key: int_wettkampfid
- Foreign Key: int_veranstaltungid β tfx_veranstaltung.int_veranstaltungid
- Cascade Delete Rule
12. tfx_wettkampf_disziplin (Competition Disciplines)¶
Junction table linking competitions to their disciplines/devices.
Table: tfx_wettkampf_disziplin
βββ int_wettkampf_disziplinid (PK, AutoIncrement) - Primary key
βββ int_wettkampfid (FK) - Competition identifier
βββ int_disziplinenid (FK) - Device identifier
βββ int_position (Integer) - Display order
βββ bol_geraetegruppe (Boolean) - Device group flag
βββ Relationships: β tfx_durchgang, tfx_wertung
Constraints:
- Primary Key: int_wettkampf_disziplinid
- Foreign Keys:
- int_wettkampfid β tfx_wettkampf.int_wettkampfid
- int_disziplinenid β tfx_disziplinen.int_disziplinenid
- Cascade Delete Rules
13. tfx_wettkampfperson (Competition Participants)¶
Participants enrolled in specific competitions.
Table: tfx_wettkampfperson
βββ int_wettkampfpersonid (PK, AutoIncrement) - Primary key
βββ int_wettkampfid (FK) - Competition identifier
βββ int_personid (FK) - Participant identifier
βββ var_startnum (String) - Start number in competition
βββ var_geschlecht (String) - Gender
βββ int_altersgruppe (Integer) - Age group
βββ var_klasse (String) - Class/Level
βββ Relationships: β tfx_wertung
Constraints:
- Primary Key: int_wettkampfpersonid
- Foreign Keys:
- int_wettkampfid β tfx_wettkampf.int_wettkampfid
- int_personid β tfx_person.int_personid
- Cascade Delete Rules
14. tfx_durchgang (Rounds/Rotations)¶
Stores rounds or rotation groups in a competition.
Table: tfx_durchgang
βββ int_durchgangid (PK, AutoIncrement) - Primary key
βββ int_wettkampfid (FK) - Competition identifier
βββ int_wettkampf_disziplinid (FK) - Competition discipline identifier
βββ var_name (String) - Round name (e.g., "Rotation 1")
βββ int_position (Integer) - Display order
βββ tim_start (Time) - Start time
βββ bol_aktiv (Boolean) - Active status
βββ Relationships: β tfx_wertung
Constraints:
- Primary Key: int_durchgangid
- Foreign Keys:
- int_wettkampfid β tfx_wettkampf.int_wettkampfid
- int_wettkampf_disziplinid β tfx_wettkampf_disziplin.int_wettkampf_disziplinid
- Cascade Delete Rules
15. tfx_wertung (Scores/Ratings)¶
Stores individual scores for participants.
Table: tfx_wertung
βββ int_wertungid (PK, AutoIncrement) - Primary key
βββ int_wettkampfpersonid (FK) - Participant identifier
βββ int_durchgangid (FK) - Round identifier
βββ int_disziplinenid (FK) - Device identifier
βββ int_feldid (FK) - Field identifier
βββ int_formelid (FK) - Formula identifier
βββ var_wert (String) - Score value
βββ var_benutzer (String) - User who entered score
βββ dat_aenderung (Date) - Last modification date
βββ tim_aenderung (Time) - Last modification time
βββ Relationships: (leaf table)
Constraints:
- Primary Key: int_wertungid
- Foreign Keys:
- int_wettkampfpersonid β tfx_wettkampfperson.int_wettkampfpersonid
- int_durchgangid β tfx_durchgang.int_durchgangid
- int_disziplinenid β tfx_disziplinen.int_disziplinenid
- int_feldid β tfx_disziplinen_felder.int_feldid
- int_formelid β tfx_formeln.int_formelid
- Cascade Delete Rules
- No cascade delete from fields/formulas (Restrict rule) to preserve audit trail
π Key Relationships¶
Data Flow¶
tfx_bereiche (Region)
βββ tfx_verband (Federation)
β βββ tfx_verein (Club)
β βββ tfx_person (Participant)
β βββ tfx_wettkampfperson (Enrollment)
β βββ tfx_wertung (Score)
β βββ tfx_disziplinen (Device)
β β βββ tfx_disziplinen_felder (Field)
β β βββ tfx_formeln (Formula)
β βββ tfx_durchgang (Round)
β βββ tfx_wettkampf_disziplin (Comp. Discipline)
β βββ tfx_wettkampf (Competition)
β βββ tfx_veranstaltung (Event)
Cascade Delete Rules¶
- Cascade:
tfx_bereicheβ all regional entities (verband, verein, person, disziplinen) - Cascade:
tfx_veranstaltungβ competitions, participants - Cascade:
tfx_wettkampfβ participants, rounds, scores - Cascade:
tfx_personβ competition enrollments, scores - Restrict: Score integrity preserved when deleting formulas/fields
π Initialization Process¶
Step 1: Create Database¶
Step 2: Initialize Schema¶
Executed via prisma migrate deploy:
- Creates all 15+ tables
- Establishes foreign key relationships
- Sets up cascade rules
- Creates auto-increment sequences
Step 3: Populate GymNet Presets¶
Inserts canonical data: - 4 Sport categories (Turnen DTB, Turnen DTB LK, Turnen DTB Turn10, Turnen DTB P) - 60+ Devices with gender flags - 100+ Scoring formulas - Device field templates (3 fields for P-devices, 5+ for regular devices)
π Data Type Mapping¶
| Type | PostgreSQL | Description | Example |
|---|---|---|---|
int_* |
INTEGER | Auto-increment IDs | 1, 2, 3 |
var_* |
VARCHAR(255) | Text strings | "Boden", "Reck" |
bol_* |
BOOLEAN | True/False flags | true, false |
flt_* |
DECIMAL(5,2) | Decimal numbers | 8.50, 9.25 |
dat_* |
DATE | Dates | 2024-10-31 |
tim_* |
TIME | Times | 10:30:00 |
txt_* |
TEXT | Long text | Notes, descriptions |
π Usage in Application¶
Backend API (Node.js/Prisma)¶
// Example: Get all devices for a sport
const devices = await prisma.tfx_disziplinen.findMany({
where: { int_sportid: 1 },
include: { tfx_disziplinen_felder: true, tfx_formeln: true }
});
// Example: Insert competition scores
await prisma.tfx_wertung.create({
data: {
int_wettkampfpersonid: 123,
int_durchgangid: 456,
int_disziplinenid: 31,
int_feldid: 1,
var_wert: "8.50"
}
});
Frontend API Routes¶
GET /api/disciplines - List all devices
GET /api/competitions/:id - Get competition details
POST /api/scores - Record a score
GET /api/results/:eventId - Get competition results
π Notes¶
- All times are stored as local wall-clock time (no timezone information)
- Scores are stored as strings to preserve formatting precision
- Deleting a region cascades to all dependent data
- Sport categories are managed through configuration UI
- Device fields for P-devices are automatically generated during schema creation
- GymNet IDs (
int_gymnetid) enable integration with external systems
End of Database Schema Documentation