Newer Older
35 lines | 1.093kb
Bogdan Timofte authored 4 days ago
1
# Table: `host_roles`
2

            
3
Stores host roles separately from `hosts` so the host table does not grow a role-specific column set.
4

            
5
## Columns
6

            
7
| Column | Type | Null | Default | Notes |
8
|--------|------|------|---------|-------|
9
| `host_fqdn` | `TEXT` | no | none | Target host. References `hosts(fqdn)`. |
10
| `role` | `TEXT` | no | none | Role label, for example `proxmox`, `pbs`, `storage`. |
11
| `status` | `TEXT` | no | `'active'` | Role lifecycle state. |
12
| `created_at` | `TEXT` | no | none | ISO UTC creation timestamp. |
13
| `retired_at` | `TEXT` | yes | `NULL` | ISO UTC retirement timestamp. |
14

            
15
## Keys And Indexes
16

            
17
- Primary key: `(host_fqdn, role)`
18

            
19
## Relationships
20

            
21
- `host_fqdn` references `hosts(fqdn)` with `ON UPDATE CASCADE ON DELETE RESTRICT`
22

            
23
## Definition
24

            
25
```sql
26
CREATE TABLE IF NOT EXISTS host_roles (
27
    host_fqdn TEXT NOT NULL,
28
    role TEXT NOT NULL,
29
    status TEXT NOT NULL DEFAULT 'active',
30
    created_at TEXT NOT NULL,
31
    retired_at TEXT,
32
    PRIMARY KEY (host_fqdn, role),
33
    FOREIGN KEY (host_fqdn) REFERENCES hosts(fqdn) ON UPDATE CASCADE ON DELETE RESTRICT
34
);
35
```