1 |
07a6c869
|
David Friesecký
|
/* Drop Tables */
|
2 |
|
|
DROP TABLE IF EXISTS 'CertificateTypes'
|
3 |
|
|
;
|
4 |
|
|
|
5 |
|
|
DROP TABLE IF EXISTS 'CertificateUsages'
|
6 |
|
|
;
|
7 |
|
|
|
8 |
|
|
/* Create Tables with Primary and Foreign Keys, Check and Unique Constraints */
|
9 |
|
|
|
10 |
|
|
CREATE TABLE IF NOT EXISTS 'Certificates'
|
11 |
|
|
(
|
12 |
|
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
13 |
|
|
'valid_from' TEXT NOT NULL,
|
14 |
|
|
'valid_to' TEXT NOT NULL,
|
15 |
|
|
'pem_data' TEXT NOT NULL,
|
16 |
|
|
'common_name' TEXT NOT NULL,
|
17 |
|
|
'country_code' TEXT NULL,
|
18 |
|
|
'locality' TEXT NULL,
|
19 |
|
|
'province' TEXT NULL,
|
20 |
|
|
'organization' TEXT NULL,
|
21 |
|
|
'organizational_unit' TEXT NULL,
|
22 |
|
|
'email_address' TEXT NULL,
|
23 |
|
|
'revocation_date' TEXT NULL,
|
24 |
|
|
'revocation_reason' TEXT NULL,
|
25 |
|
|
'deletion_date' TEXT NULL,
|
26 |
|
|
'certificate_type_id' INTEGER NOT NULL,
|
27 |
|
|
'parent_certificate_id' INTEGER NOT NULL,
|
28 |
|
|
'private_key_id' INTEGER NOT NULL,
|
29 |
|
|
CONSTRAINT 'FK_Certificates' FOREIGN KEY ('parent_certificate_id') REFERENCES 'Certificates' ('id') ON DELETE No Action ON UPDATE No Action,
|
30 |
|
|
CONSTRAINT 'FK_CertificateTypes' FOREIGN KEY ('certificate_type_id') REFERENCES 'CertificateTypes' ('id') ON DELETE No Action ON UPDATE No Action,
|
31 |
|
|
CONSTRAINT 'FK_PrivateKeys' FOREIGN KEY ('private_key_id') REFERENCES 'PrivateKeys' ('id') ON DELETE No Action ON UPDATE No Action
|
32 |
|
|
)
|
33 |
|
|
;
|
34 |
|
|
|
35 |
|
|
CREATE TABLE IF NOT EXISTS 'CertificateTypes'
|
36 |
|
|
(
|
37 |
|
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
38 |
|
|
'certificate_type' TEXT NOT NULL
|
39 |
|
|
)
|
40 |
|
|
;
|
41 |
|
|
|
42 |
|
|
CREATE TABLE IF NOT EXISTS 'CertificateUsages'
|
43 |
|
|
(
|
44 |
|
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
45 |
|
|
'certificate_id' INTEGER NOT NULL,
|
46 |
|
|
'usage_type_id' INTEGER NOT NULL,
|
47 |
|
|
CONSTRAINT 'FK_Certificates' FOREIGN KEY ('certificate_id') REFERENCES 'Certificates' ('id') ON DELETE Cascade ON UPDATE No Action,
|
48 |
|
|
CONSTRAINT 'FK_UsageTypes' FOREIGN KEY ('usage_type_id') REFERENCES 'UsageTypes' ('id') ON DELETE No Action ON UPDATE No Action
|
49 |
|
|
)
|
50 |
|
|
;
|
51 |
|
|
|
52 |
|
|
CREATE TABLE IF NOT EXISTS 'PrivateKeys'
|
53 |
|
|
(
|
54 |
|
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
55 |
|
|
'private_key' TEXT NOT NULL,
|
56 |
|
|
'password' TEXT NULL
|
57 |
|
|
)
|
58 |
|
|
;
|
59 |
|
|
|
60 |
|
|
CREATE TABLE IF NOT EXISTS 'UsageTypes'
|
61 |
|
|
(
|
62 |
|
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
63 |
|
|
'usage_type' TEXT NOT NULL
|
64 |
|
|
)
|
65 |
|
|
;
|