Newer Older
57 lines | 2.214kb
Bogdan Timofte authored 4 days ago
1
# Table: `host_aliases`
2

            
3
Stores aliases for canonical hosts. Aliases are retained after retirement for audit and collision prevention.
4

            
5
## Columns
6

            
7
| Column | Type | Null | Default | Notes |
8
|--------|------|------|---------|-------|
9
| `alias_name` | `TEXT` | no | none | Alias DNS name or short alias. |
10
| `host_fqdn` | `TEXT` | no | none | Target host. References `hosts(fqdn)`. |
11
| `alias_kind` | `TEXT` | no | `'declared'` | `declared`, `derived`, or `derived-vhost`. |
12
| `status` | `TEXT` | no | `'active'` | Alias lifecycle state. |
13
| `is_dns_published` | `INTEGER` | no | `1` | Whether this alias should appear in generated DNS exports. |
14
| `created_at` | `TEXT` | no | none | ISO UTC creation timestamp. |
15
| `retired_at` | `TEXT` | yes | `NULL` | ISO UTC retirement timestamp. |
16
| `notes` | `TEXT` | no | `''` | Operator notes. |
17

            
18
## Keys And Indexes
19

            
20
- Primary key: `(alias_name, host_fqdn)`
21
- Unique partial index: `idx_host_aliases_active_name` on `alias_name` where `status = 'active'`
22
- Lookup index: `idx_host_aliases_host_status` on `(host_fqdn, status)`
23

            
24
## Relationships
25

            
26
- `host_fqdn` references `hosts(fqdn)` with `ON UPDATE CASCADE ON DELETE RESTRICT`
27

            
28
## Rules
29

            
30
- A retired alias is not deleted; `status` changes to `retired` and `is_dns_published` is set to `0`.
31
- One active alias can point to only one host.
32
- Derived short names such as `baobab` are persisted with `alias_kind = 'derived'`.
33
- Derived vhost short names such as `pmx.baobab` are persisted with `alias_kind = 'derived-vhost'`.
34

            
35
## Definition
36

            
37
```sql
38
CREATE TABLE IF NOT EXISTS host_aliases (
39
    alias_name TEXT NOT NULL,
40
    host_fqdn TEXT NOT NULL,
41
    alias_kind TEXT NOT NULL DEFAULT 'declared',
42
    status TEXT NOT NULL DEFAULT 'active',
43
    is_dns_published INTEGER NOT NULL DEFAULT 1,
44
    created_at TEXT NOT NULL,
45
    retired_at TEXT,
46
    notes TEXT NOT NULL DEFAULT '',
47
    PRIMARY KEY (alias_name, host_fqdn),
48
    FOREIGN KEY (host_fqdn) REFERENCES hosts(fqdn) ON UPDATE CASCADE ON DELETE RESTRICT
49
);
50

            
51
CREATE UNIQUE INDEX IF NOT EXISTS idx_host_aliases_active_name
52
ON host_aliases(alias_name)
53
WHERE status = 'active';
54

            
55
CREATE INDEX IF NOT EXISTS idx_host_aliases_host_status
56
ON host_aliases(host_fqdn, status);
57
```