- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_creation.sql
More file actions
Latest commit
28 lines (25 loc) · 840 Bytes
/
Copy pathdatabase_creation.sql
File metadata and controls
28 lines (25 loc) · 840 Bytes
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
-- rim of database
CREATETABLEowner (
id INTEGERNOT NULLPRIMARY KEY AUTOINCREMENT,
name VARCHAR(255) NOT NULL
);
CREATETABLEdevice (
id INTEGERNOT NULLPRIMARY KEY AUTOINCREMENT,
name VARCHAR(255) NOT NULL,
owner_id INTEGERNOT NULL,
FOREIGN KEY (owner_id) REFERENCES owner (id)
ONUPDATE CASCADE
ON DELETE CASCADE
);
CREATETABLEkey (
id INTEGERNOT NULLPRIMARY KEY AUTOINCREMENT,
license_key VARCHAR(255) NOT NULL,
in_use BOOLEANNOT NULL DEFAULT 0,
device_id INTEGER DEFAULT NULL,
FOREIGN KEY (device_id) REFERENCES device (id)
ONUPDATE CASCADE
ON DELETESET DEFAULT
);
CREATEUNIQUE INDEXowner_nameON owner (name);
CREATEUNIQUE INDEXdevice_nameON device (name);
CREATEUNIQUE INDEXlicense_key_idON key (license_key);