-
-
Notifications
You must be signed in to change notification settings - Fork 165
/
schema.go
635 lines (633 loc) · 22.8 KB
/
schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
package cluster
// DO NOT EDIT BY HAND
//
// This code was generated by the schema.DotGo function. If you need to
// modify the database schema, please add a new schema update to update.go
// and the run 'make update-schema'.
const freshSchema = `
CREATE TABLE certificates (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
fingerprint TEXT NOT NULL,
type INTEGER NOT NULL,
name TEXT NOT NULL,
certificate TEXT NOT NULL,
restricted INTEGER NOT NULL DEFAULT 0,
description TEXT NOT NULL DEFAULT "",
UNIQUE (fingerprint)
);
CREATE TABLE "certificates_projects" (
certificate_id INTEGER NOT NULL,
project_id INTEGER NOT NULL,
FOREIGN KEY (certificate_id) REFERENCES certificates (id) ON DELETE CASCADE,
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE,
UNIQUE (certificate_id, project_id)
);
CREATE TABLE "cluster_groups" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
UNIQUE (name)
);
CREATE TABLE config (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
key TEXT NOT NULL,
value TEXT,
UNIQUE (key)
);
CREATE TABLE "images" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
fingerprint TEXT NOT NULL,
filename TEXT NOT NULL,
size INTEGER NOT NULL,
public INTEGER NOT NULL DEFAULT 0,
architecture INTEGER NOT NULL,
creation_date DATETIME,
expiry_date DATETIME,
upload_date DATETIME NOT NULL,
cached INTEGER NOT NULL DEFAULT 0,
last_use_date DATETIME,
auto_update INTEGER NOT NULL DEFAULT 0,
project_id INTEGER NOT NULL,
type INTEGER NOT NULL DEFAULT 0,
UNIQUE (project_id, fingerprint),
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE TABLE "images_aliases" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL,
image_id INTEGER NOT NULL,
description TEXT NOT NULL,
project_id INTEGER NOT NULL,
UNIQUE (project_id, name),
FOREIGN KEY (image_id) REFERENCES "images" (id) ON DELETE CASCADE,
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE INDEX images_aliases_project_id_idx ON images_aliases (project_id);
CREATE TABLE "images_nodes" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
image_id INTEGER NOT NULL,
node_id INTEGER NOT NULL,
UNIQUE (image_id, node_id),
FOREIGN KEY (image_id) REFERENCES "images" (id) ON DELETE CASCADE,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE
);
CREATE TABLE "images_profiles" (
image_id INTEGER NOT NULL,
profile_id INTEGER NOT NULL,
FOREIGN KEY (image_id) REFERENCES "images" (id) ON DELETE CASCADE,
FOREIGN KEY (profile_id) REFERENCES "profiles" (id) ON DELETE CASCADE,
UNIQUE (image_id, profile_id)
);
CREATE INDEX images_project_id_idx ON images (project_id);
CREATE TABLE "images_properties" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
image_id INTEGER NOT NULL,
type INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT,
FOREIGN KEY (image_id) REFERENCES "images" (id) ON DELETE CASCADE
);
CREATE TABLE "images_source" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
image_id INTEGER NOT NULL,
server TEXT NOT NULL,
protocol INTEGER NOT NULL,
certificate TEXT NOT NULL,
alias TEXT NOT NULL,
FOREIGN KEY (image_id) REFERENCES "images" (id) ON DELETE CASCADE
);
CREATE TABLE "instances" (
id INTEGER primary key AUTOINCREMENT NOT NULL,
node_id INTEGER NOT NULL,
name TEXT NOT NULL,
architecture INTEGER NOT NULL,
type INTEGER NOT NULL,
ephemeral INTEGER NOT NULL DEFAULT 0,
creation_date DATETIME NOT NULL DEFAULT 0,
stateful INTEGER NOT NULL DEFAULT 0,
last_use_date DATETIME,
description TEXT NOT NULL,
project_id INTEGER NOT NULL,
expiry_date DATETIME,
UNIQUE (project_id, name),
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE,
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE TABLE "instances_backups" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
instance_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
creation_date DATETIME,
expiry_date DATETIME,
container_only INTEGER NOT NULL default 0,
optimized_storage INTEGER NOT NULL default 0,
FOREIGN KEY (instance_id) REFERENCES "instances" (id) ON DELETE CASCADE,
UNIQUE (instance_id, name)
);
CREATE TABLE "instances_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
instance_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
FOREIGN KEY (instance_id) REFERENCES "instances" (id) ON DELETE CASCADE,
UNIQUE (instance_id, key)
);
CREATE TABLE "instances_devices" (
id INTEGER primary key AUTOINCREMENT NOT NULL,
instance_id INTEGER NOT NULL,
name TEXT NOT NULL,
type INTEGER NOT NULL default 0,
FOREIGN KEY (instance_id) REFERENCES "instances" (id) ON DELETE CASCADE,
UNIQUE (instance_id, name)
);
CREATE TABLE "instances_devices_config" (
id INTEGER primary key AUTOINCREMENT NOT NULL,
instance_device_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
FOREIGN KEY (instance_device_id) REFERENCES "instances_devices" (id) ON DELETE CASCADE,
UNIQUE (instance_device_id, key)
);
CREATE INDEX instances_node_id_idx ON instances (node_id);
CREATE TABLE "instances_profiles" (
id INTEGER primary key AUTOINCREMENT NOT NULL,
instance_id INTEGER NOT NULL,
profile_id INTEGER NOT NULL,
apply_order INTEGER NOT NULL default 0,
UNIQUE (instance_id, profile_id),
FOREIGN KEY (instance_id) REFERENCES "instances" (id) ON DELETE CASCADE,
FOREIGN KEY (profile_id) REFERENCES "profiles"(id) ON DELETE CASCADE
);
CREATE INDEX instances_project_id_and_name_idx ON instances (project_id,
name);
CREATE INDEX instances_project_id_and_node_id_and_name_idx ON instances (project_id,
node_id,
name);
CREATE INDEX instances_project_id_and_node_id_idx ON instances (project_id,
node_id);
CREATE INDEX instances_project_id_idx ON instances (project_id);
CREATE TABLE "instances_snapshots" (
id INTEGER primary key AUTOINCREMENT NOT NULL,
instance_id INTEGER NOT NULL,
name TEXT NOT NULL,
creation_date DATETIME NOT NULL DEFAULT 0,
stateful INTEGER NOT NULL DEFAULT 0,
description TEXT NOT NULL,
expiry_date DATETIME,
UNIQUE (instance_id, name),
FOREIGN KEY (instance_id) REFERENCES "instances" (id) ON DELETE CASCADE
);
CREATE TABLE "instances_snapshots_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
instance_snapshot_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
FOREIGN KEY (instance_snapshot_id) REFERENCES "instances_snapshots" (id) ON DELETE CASCADE,
UNIQUE (instance_snapshot_id, key)
);
CREATE TABLE "instances_snapshots_devices" (
id INTEGER primary key AUTOINCREMENT NOT NULL,
instance_snapshot_id INTEGER NOT NULL,
name TEXT NOT NULL,
type INTEGER NOT NULL default 0,
FOREIGN KEY (instance_snapshot_id) REFERENCES "instances_snapshots" (id) ON DELETE CASCADE,
UNIQUE (instance_snapshot_id, name)
);
CREATE TABLE "instances_snapshots_devices_config" (
id INTEGER primary key AUTOINCREMENT NOT NULL,
instance_snapshot_device_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
FOREIGN KEY (instance_snapshot_device_id) REFERENCES "instances_snapshots_devices" (id) ON DELETE CASCADE,
UNIQUE (instance_snapshot_device_id, key)
);
CREATE TABLE "networks" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
project_id INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
state INTEGER NOT NULL DEFAULT 0,
type INTEGER NOT NULL DEFAULT 0,
UNIQUE (project_id, name),
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_acls" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
project_id INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
ingress TEXT NOT NULL,
egress TEXT NOT NULL,
UNIQUE (project_id, name),
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_acls_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_acl_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (network_acl_id, key),
FOREIGN KEY (network_acl_id) REFERENCES "networks_acls" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_id INTEGER NOT NULL,
node_id INTEGER,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (network_id, node_id, key),
FOREIGN KEY (network_id) REFERENCES "networks" (id) ON DELETE CASCADE,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_forwards" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_id INTEGER NOT NULL,
node_id INTEGER,
listen_address TEXT NOT NULL,
description TEXT NOT NULL,
ports TEXT NOT NULL,
UNIQUE (network_id, node_id, listen_address),
FOREIGN KEY (network_id) REFERENCES "networks" (id) ON DELETE CASCADE,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_forwards_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_forward_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (network_forward_id, key),
FOREIGN KEY (network_forward_id) REFERENCES "networks_forwards" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_load_balancers" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_id INTEGER NOT NULL,
node_id INTEGER,
listen_address TEXT NOT NULL,
description TEXT NOT NULL,
backends TEXT NOT NULL,
ports TEXT NOT NULL,
UNIQUE (network_id, node_id, listen_address),
FOREIGN KEY (network_id) REFERENCES "networks" (id) ON DELETE CASCADE,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_load_balancers_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_load_balancer_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (network_load_balancer_id, key),
FOREIGN KEY (network_load_balancer_id) REFERENCES "networks_load_balancers" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_nodes" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_id INTEGER NOT NULL,
node_id INTEGER NOT NULL,
state INTEGER NOT NULL DEFAULT 0,
UNIQUE (network_id, node_id),
FOREIGN KEY (network_id) REFERENCES "networks" (id) ON DELETE CASCADE,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_peers" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_id INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
target_network_project TEXT NULL,
target_network_name TEXT NULL,
target_network_id INTEGER NULL,
UNIQUE (network_id, name),
UNIQUE (network_id, target_network_project, target_network_name),
UNIQUE (network_id, target_network_id),
FOREIGN KEY (network_id) REFERENCES "networks" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_peers_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_peer_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (network_peer_id, key),
FOREIGN KEY (network_peer_id) REFERENCES "networks_peers" (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX networks_unique_network_id_node_id_key ON "networks_config" (network_id, IFNULL(node_id, -1), key);
CREATE TABLE "networks_zones" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
project_id INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
UNIQUE (name),
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_zones_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_zone_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (network_zone_id, key),
FOREIGN KEY (network_zone_id) REFERENCES "networks_zones" (id) ON DELETE CASCADE
);
CREATE TABLE "networks_zones_records" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_zone_id INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
entries TEXT NOT NULL,
UNIQUE (network_zone_id, name),
FOREIGN KEY (network_zone_id) REFERENCES networks_zones (id) ON DELETE CASCADE
);
CREATE TABLE "networks_zones_records_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_zone_record_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (network_zone_record_id, key),
FOREIGN KEY (network_zone_record_id) REFERENCES "networks_zones_records" (id) ON DELETE CASCADE
);
CREATE TABLE "nodes" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
address TEXT NOT NULL,
schema INTEGER NOT NULL,
api_extensions INTEGER NOT NULL,
heartbeat DATETIME DEFAULT CURRENT_TIMESTAMP,
state INTEGER NOT NULL DEFAULT 0,
arch INTEGER NOT NULL DEFAULT 0 CHECK (arch > 0),
failure_domain_id INTEGER DEFAULT NULL REFERENCES nodes_failure_domains (id) ON DELETE SET NULL,
UNIQUE (name),
UNIQUE (address)
);
CREATE TABLE "nodes_cluster_groups" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
node_id INTEGER NOT NULL,
group_id INTEGER NOT NULL,
FOREIGN KEY (node_id) REFERENCES nodes (id) ON DELETE CASCADE,
FOREIGN KEY (group_id) REFERENCES cluster_groups (id) ON DELETE CASCADE,
UNIQUE (node_id, group_id)
);
CREATE TABLE "nodes_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
node_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE,
UNIQUE (node_id, key)
);
CREATE TABLE nodes_failure_domains (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL,
UNIQUE (name)
);
CREATE TABLE "nodes_roles" (
node_id INTEGER NOT NULL,
role INTEGER NOT NULL,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE,
UNIQUE (node_id, role)
);
CREATE TABLE "operations" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
uuid TEXT NOT NULL,
node_id TEXT NOT NULL,
type INTEGER NOT NULL DEFAULT 0,
project_id INTEGER,
UNIQUE (uuid),
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE,
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE TABLE "profiles" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
project_id INTEGER NOT NULL,
UNIQUE (project_id, name),
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE TABLE "profiles_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
profile_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (profile_id, key),
FOREIGN KEY (profile_id) REFERENCES "profiles"(id) ON DELETE CASCADE
);
CREATE TABLE "profiles_devices" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
profile_id INTEGER NOT NULL,
name TEXT NOT NULL,
type INTEGER NOT NULL default 0,
UNIQUE (profile_id, name),
FOREIGN KEY (profile_id) REFERENCES "profiles" (id) ON DELETE CASCADE
);
CREATE TABLE "profiles_devices_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
profile_device_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (profile_device_id, key),
FOREIGN KEY (profile_device_id) REFERENCES "profiles_devices" (id) ON DELETE CASCADE
);
CREATE INDEX profiles_project_id_idx ON profiles (project_id);
CREATE TABLE "projects" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
UNIQUE (name)
);
CREATE TABLE "projects_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
project_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE,
UNIQUE (project_id, key)
);
CREATE TABLE "storage_buckets" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL,
storage_pool_id INTEGER NOT NULL,
node_id INTEGER,
description TEXT NOT NULL,
project_id INTEGER NOT NULL,
UNIQUE (node_id, name),
FOREIGN KEY (storage_pool_id) REFERENCES "storage_pools" (id) ON DELETE CASCADE,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE,
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE TABLE "storage_buckets_backups" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
storage_bucket_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
creation_date DATETIME,
expiry_date DATETIME,
FOREIGN KEY (storage_bucket_id) REFERENCES "storage_buckets" (id) ON DELETE CASCADE,
UNIQUE (storage_bucket_id, name)
);
CREATE TABLE "storage_buckets_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
storage_bucket_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (storage_bucket_id, key),
FOREIGN KEY (storage_bucket_id) REFERENCES "storage_buckets" (id) ON DELETE CASCADE
);
CREATE TABLE "storage_buckets_keys" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
storage_bucket_id INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
access_key TEXT NOT NULL,
secret_key TEXT NOT NULL,
role TEXT NOT NULL,
UNIQUE (storage_bucket_id, name),
FOREIGN KEY (storage_bucket_id) REFERENCES "storage_buckets" (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX storage_buckets_unique_storage_pool_id_node_id_name ON "storage_buckets" (storage_pool_id, IFNULL(node_id, -1), name);
CREATE TABLE "storage_pools" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL,
driver TEXT NOT NULL,
description TEXT NOT NULL,
state INTEGER NOT NULL DEFAULT 0,
UNIQUE (name)
);
CREATE TABLE "storage_pools_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
storage_pool_id INTEGER NOT NULL,
node_id INTEGER,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (storage_pool_id, node_id, key),
FOREIGN KEY (storage_pool_id) REFERENCES "storage_pools" (id) ON DELETE CASCADE,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE
);
CREATE TABLE "storage_pools_nodes" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
storage_pool_id INTEGER NOT NULL,
node_id INTEGER NOT NULL,
state INTEGER NOT NULL DEFAULT 0,
UNIQUE (storage_pool_id, node_id),
FOREIGN KEY (storage_pool_id) REFERENCES "storage_pools" (id) ON DELETE CASCADE,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX storage_pools_unique_storage_pool_id_node_id_key ON storage_pools_config (storage_pool_id, IFNULL(node_id, -1), key);
CREATE TABLE "storage_volumes" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL,
storage_pool_id INTEGER NOT NULL,
node_id INTEGER,
type INTEGER NOT NULL,
description TEXT NOT NULL,
project_id INTEGER NOT NULL,
content_type INTEGER NOT NULL DEFAULT 0,
creation_date DATETIME NOT NULL DEFAULT "0001-01-01T00:00:00Z",
UNIQUE (storage_pool_id, node_id, project_id, name, type),
FOREIGN KEY (storage_pool_id) REFERENCES "storage_pools" (id) ON DELETE CASCADE,
FOREIGN KEY (node_id) REFERENCES "nodes" (id) ON DELETE CASCADE,
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE VIEW storage_volumes_all (
id,
name,
storage_pool_id,
node_id,
type,
description,
project_id,
content_type,
creation_date) AS
SELECT id,
name,
storage_pool_id,
node_id,
type,
description,
project_id,
content_type,
creation_date
FROM storage_volumes UNION
SELECT storage_volumes_snapshots.id,
printf('%s/%s',
storage_volumes.name,
storage_volumes_snapshots.name),
storage_volumes.storage_pool_id,
storage_volumes.node_id,
storage_volumes.type,
storage_volumes_snapshots.description,
storage_volumes.project_id,
storage_volumes.content_type,
storage_volumes_snapshots.creation_date
FROM storage_volumes
JOIN storage_volumes_snapshots ON storage_volumes.id = storage_volumes_snapshots.storage_volume_id;
CREATE TABLE "storage_volumes_backups" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
storage_volume_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
creation_date DATETIME,
expiry_date DATETIME,
volume_only INTEGER NOT NULL default 0,
optimized_storage INTEGER NOT NULL default 0,
FOREIGN KEY (storage_volume_id) REFERENCES "storage_volumes" (id) ON DELETE CASCADE,
UNIQUE (storage_volume_id, name)
);
CREATE TRIGGER storage_volumes_check_id
BEFORE INSERT ON storage_volumes
WHEN NEW.id IN (SELECT id FROM storage_volumes_snapshots)
BEGIN
SELECT RAISE(FAIL,
"invalid ID");
END;
CREATE TABLE "storage_volumes_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
storage_volume_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
UNIQUE (storage_volume_id, key),
FOREIGN KEY (storage_volume_id) REFERENCES "storage_volumes" (id) ON DELETE CASCADE
);
CREATE TABLE "storage_volumes_snapshots" (
id INTEGER NOT NULL,
storage_volume_id INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
expiry_date DATETIME,
creation_date DATETIME NOT NULL DEFAULT "0001-01-01T00:00:00Z",
UNIQUE (id),
UNIQUE (storage_volume_id, name),
FOREIGN KEY (storage_volume_id) REFERENCES "storage_volumes" (id) ON DELETE CASCADE
);
CREATE TRIGGER storage_volumes_snapshots_check_id
BEFORE INSERT ON storage_volumes_snapshots
WHEN NEW.id IN (SELECT id FROM storage_volumes)
BEGIN
SELECT RAISE(FAIL,
"invalid ID");
END;
CREATE TABLE "storage_volumes_snapshots_config" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
storage_volume_snapshot_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
FOREIGN KEY (storage_volume_snapshot_id) REFERENCES "storage_volumes_snapshots" (id) ON DELETE CASCADE,
UNIQUE (storage_volume_snapshot_id, key)
);
CREATE UNIQUE INDEX storage_volumes_unique_storage_pool_id_node_id_project_id_name_type ON "storage_volumes" (storage_pool_id, IFNULL(node_id, -1), project_id, name, type);
CREATE TABLE "warnings" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
node_id INTEGER,
project_id INTEGER,
entity_type_code INTEGER,
entity_id INTEGER,
uuid TEXT NOT NULL,
type_code INTEGER NOT NULL,
status INTEGER NOT NULL,
first_seen_date DATETIME NOT NULL,
last_seen_date DATETIME NOT NULL,
updated_date DATETIME,
last_message TEXT NOT NULL,
count INTEGER NOT NULL,
UNIQUE (uuid),
FOREIGN KEY (node_id) REFERENCES "nodes"(id) ON DELETE CASCADE,
FOREIGN KEY (project_id) REFERENCES "projects" (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX warnings_unique_node_id_project_id_entity_type_code_entity_id_type_code ON warnings(IFNULL(node_id, -1), IFNULL(project_id, -1), entity_type_code, entity_id, type_code);
INSERT INTO schema (version, updated_at) VALUES (71, strftime("%s"))
`