|
Bogdan Timofte
authored
4 days ago
|
1
|
# SQLite Database
|
|
|
2
|
|
|
|
3
|
Madagascar Local Authority folosește SQLite ca sursă de adevăr runtime pentru hosturi, aliasuri, vhosturi, Work Orders, workeri de date și certificate.
|
|
|
4
|
|
|
|
5
|
Locația implicită în checkout:
|
|
|
6
|
|
|
|
7
|
```text
|
|
|
8
|
var/host-manager.sqlite
|
|
|
9
|
```
|
|
|
10
|
|
|
|
11
|
Locația runtime pe jumper:
|
|
|
12
|
|
|
|
13
|
```text
|
|
|
14
|
/usr/local/xdev-host-manager/var/host-manager.sqlite
|
|
|
15
|
```
|
|
|
16
|
|
|
|
17
|
Path-ul poate fi schimbat cu:
|
|
|
18
|
|
|
|
19
|
```text
|
|
|
20
|
HOST_MANAGER_DB=/path/to/host-manager.sqlite
|
|
|
21
|
```
|
|
|
22
|
|
|
|
23
|
## Principii
|
|
|
24
|
|
|
|
25
|
Hosturile sunt identificate prin FQDN complet, nu prin short name. Exemplu: `gw.local` și `gw.remote` sunt identități diferite. Coloana compatibilă `legacy_id` păstrează ID-ul scurt folosit de UI-ul curent, dar cheia reală este `hosts.fqdn`.
|
|
|
26
|
|
|
|
27
|
Schema evită să transforme `hosts` într-un tabel cu prea multe coloane. Datele specializate stau în tabele separate:
|
|
|
28
|
|
|
|
29
|
- aliasuri: [`host_aliases`](tables/host_aliases.md)
|
|
|
30
|
- roluri: [`host_roles`](tables/host_roles.md)
|
|
|
31
|
- surse: [`host_sources`](tables/host_sources.md)
|
|
|
32
|
- flaguri: [`host_flags`](tables/host_flags.md)
|
|
|
33
|
- SSH: [`host_ssh`](tables/host_ssh.md)
|
|
|
34
|
- vhosturi mutabile: [`vhosts`](tables/vhosts.md)
|
|
|
35
|
- certificate: [`certificates`](tables/certificates.md), [`certificate_dns_names`](tables/certificate_dns_names.md)
|
|
|
36
|
- workeri și observații: [`data_workers`](tables/data_workers.md), [`dhcp_leases`](tables/dhcp_leases.md), [`mdns_observations`](tables/mdns_observations.md)
|
|
|
37
|
|
|
|
38
|
[`documents`](tables/documents.md) rămâne doar tabel legacy pentru migrarea din modelul vechi document-store. Aplicația nu îl mai folosește ca sursă de adevăr.
|
|
|
39
|
|
|
|
40
|
## Schema Version
|
|
|
41
|
|
|
|
42
|
Schema curentă este versiunea `2`.
|
|
|
43
|
|
|
|
44
|
```sql
|
|
|
45
|
schema_meta('schema_version') = '2'
|
|
|
46
|
```
|
|
|
47
|
|
|
|
48
|
[`schema_meta`](tables/schema_meta.md) păstrează și metadate runtime precum `registry_updated_at`.
|
|
|
49
|
|
|
|
50
|
## Catalog
|
|
|
51
|
|
|
|
52
|
| Tabel | Rol |
|
|
|
53
|
|-------|-----|
|
|
|
54
|
| [`schema_meta`](tables/schema_meta.md) | metadate de schemă/runtime |
|
|
|
55
|
| [`documents`](tables/documents.md) | document-store legacy pentru migrare |
|
|
|
56
|
| [`hosts`](tables/hosts.md) | hosturi canonice, identificate prin FQDN |
|
|
|
57
|
| [`host_aliases`](tables/host_aliases.md) | aliasuri păstrate inclusiv după retragere |
|
|
|
58
|
| [`host_roles`](tables/host_roles.md) | roluri active/retrase per host |
|
|
|
59
|
| [`host_sources`](tables/host_sources.md) | surse active/retrase per host |
|
|
|
60
|
| [`host_flags`](tables/host_flags.md) | flaguri extensibile per host |
|
|
|
61
|
| [`host_ssh`](tables/host_ssh.md) | profile SSH per host |
|
|
|
62
|
| [`vhosts`](tables/vhosts.md) | vhosturi mutabile între hosturi |
|
|
|
63
|
| [`data_workers`](tables/data_workers.md) | workeri/surse care colectează date |
|
|
|
64
|
| [`dhcp_leases`](tables/dhcp_leases.md) | date observate din DHCP lease/reservation |
|
|
|
65
|
| [`mdns_observations`](tables/mdns_observations.md) | date observate din mDNS |
|
|
|
66
|
| [`certificates`](tables/certificates.md) | certificate emise de CA locală |
|
|
|
67
|
| [`certificate_dns_names`](tables/certificate_dns_names.md) | SAN DNS names pentru certificate |
|
|
|
68
|
| [`work_orders`](tables/work_orders.md) | Work Orders |
|
|
|
69
|
| [`work_order_checklist`](tables/work_order_checklist.md) | checklist items pentru Work Orders |
|
|
|
70
|
| [`work_order_actions`](tables/work_order_actions.md) | acțiuni confirmabile pentru Work Orders |
|
|
|
71
|
|
|
|
72
|
## Relații Principale
|
|
|
73
|
|
|
|
74
|
```mermaid
|
|
|
75
|
erDiagram
|
|
|
76
|
hosts ||--o{ host_aliases : has
|
|
|
77
|
hosts ||--o{ vhosts : serves
|
|
|
78
|
hosts ||--o{ host_roles : has
|
|
|
79
|
hosts ||--o{ host_sources : has
|
|
|
80
|
hosts ||--o{ host_flags : has
|
|
|
81
|
hosts ||--o{ host_ssh : has
|
|
|
82
|
hosts ||--o{ dhcp_leases : may_match
|
|
|
83
|
hosts ||--o{ mdns_observations : may_match
|
|
|
84
|
hosts ||--o{ certificates : may_own
|
|
|
85
|
certificates ||--o{ certificate_dns_names : has
|
|
|
86
|
data_workers ||--o{ dhcp_leases : collects
|
|
|
87
|
data_workers ||--o{ mdns_observations : collects
|
|
|
88
|
work_orders ||--o{ work_order_checklist : has
|
|
|
89
|
work_orders ||--o{ work_order_actions : has
|
|
|
90
|
hosts ||--o{ work_order_actions : targets
|
|
|
91
|
```
|
|
|
92
|
|
|
|
93
|
## Migrare și Seed
|
|
|
94
|
|
|
|
95
|
La prima inițializare a unei baze fără rânduri în `hosts`, aplicația seed-uiește din:
|
|
|
96
|
|
|
|
97
|
1. `documents.name = 'hosts_yaml'`, dacă există din vechiul model
|
|
|
98
|
2. `config/hosts.yaml`, dacă documentul legacy lipsește
|
|
|
99
|
3. document gol valid, dacă lipsește și seed-ul
|
|
|
100
|
|
|
|
101
|
Work Orders se seed-uiesc similar din `documents.name = 'work_orders_yaml'` sau `config/work-orders.yaml`.
|
|
|
102
|
|
|
|
103
|
Seed-ul curent produce:
|
|
|
104
|
|
|
|
105
|
- 11 hosturi cunoscute
|
|
|
106
|
- aliasuri scurte derivate pentru hosturi și vhosturi
|
|
|
107
|
- vhosturile `hosts.*`, `pmx.*` și `pbs.*`
|
|
|
108
|
- workerii `dhcp-router` și `mdns-listener`
|
|
|
109
|
- Work Order-ul existent pentru retragerea numelor legacy
|
|
|
110
|
|
|
Bogdan Timofte
authored
4 days ago
|
111
|
`config/local-hosts.tsv` rămâne manifest generat explicit din tabelele runtime, dar scriptul de sync citește manifestul direct din SQLite-ul runtime de pe jumper.
|
|
Bogdan Timofte
authored
4 days ago
|
112
|
|
|
|
113
|
## Inspecție
|
|
|
114
|
|
|
|
115
|
Pe jumper:
|
|
|
116
|
|
|
|
117
|
```bash
|
|
|
118
|
cd /usr/local/xdev-host-manager
|
|
|
119
|
sqlite3 var/host-manager.sqlite '.tables'
|
|
|
120
|
sqlite3 var/host-manager.sqlite '.schema hosts'
|
|
|
121
|
sqlite3 var/host-manager.sqlite '.schema host_aliases'
|
|
|
122
|
sqlite3 var/host-manager.sqlite '.schema vhosts'
|
|
|
123
|
sqlite3 var/host-manager.sqlite 'pragma foreign_key_list(vhosts);'
|
|
|
124
|
sqlite3 var/host-manager.sqlite 'pragma index_list(host_aliases);'
|
|
|
125
|
sqlite3 var/host-manager.sqlite 'select fqdn, legacy_id, status, dns_ip from hosts order by legacy_id;'
|
|
|
126
|
sqlite3 var/host-manager.sqlite 'select alias_name, host_fqdn, alias_kind, status from host_aliases order by alias_name;'
|
|
|
127
|
sqlite3 var/host-manager.sqlite 'select vhost_fqdn, host_fqdn, status from vhosts order by vhost_fqdn;'
|
|
|
128
|
```
|
|
|
129
|
|
|
|
130
|
## Backup
|
|
|
131
|
|
|
|
132
|
Backup recomandat:
|
|
|
133
|
|
|
|
134
|
```bash
|
|
|
135
|
cd /usr/local/xdev-host-manager
|
|
|
136
|
sqlite3 var/host-manager.sqlite ".backup 'backups/host-manager/host-manager.sqlite.$(date +%Y%m%d_%H%M%S).bak'"
|
|
|
137
|
```
|
|
|
138
|
|
|
|
139
|
Cu WAL activ, o copie brută trebuie să trateze fișierele ca set coerent:
|
|
|
140
|
|
|
|
141
|
```text
|
|
|
142
|
var/host-manager.sqlite
|
|
|
143
|
var/host-manager.sqlite-wal
|
|
|
144
|
var/host-manager.sqlite-shm
|
|
|
145
|
```
|
|
|
146
|
|
|
|
147
|
## Restore
|
|
|
148
|
|
|
|
149
|
Restore-ul înlocuiește sursa de adevăr runtime:
|
|
|
150
|
|
|
|
151
|
```bash
|
|
|
152
|
sudo systemctl stop host-manager
|
|
|
153
|
sudo cp backups/host-manager/host-manager.sqlite.YYYYMMDD_HHMMSS.bak var/host-manager.sqlite
|
|
|
154
|
sudo chown host-manager:host-manager var/host-manager.sqlite
|
|
|
155
|
sudo systemctl start host-manager
|
|
|
156
|
curl -fsS http://127.0.0.1:8088/healthz >/dev/null
|
|
|
157
|
```
|