Mercurial > hg > orthanc
annotate OrthancServer/PrepareDatabase.sql @ 1036:bd17030db6d4
fix mainline version
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Jul 2014 16:22:59 +0200 |
parents | 72dc919a028c |
children | badc14fee61f |
rev | line source |
---|---|
181 | 1 CREATE TABLE GlobalProperties( |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
2 property INTEGER PRIMARY KEY, |
181 | 3 value TEXT |
4 ); | |
5 | |
6 CREATE TABLE Resources( | |
7 internalId INTEGER PRIMARY KEY AUTOINCREMENT, | |
8 resourceType INTEGER, | |
9 publicId TEXT, | |
10 parentId INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE | |
11 ); | |
12 | |
13 CREATE TABLE MainDicomTags( | |
14 id INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE, | |
15 tagGroup INTEGER, | |
16 tagElement INTEGER, | |
17 value TEXT, | |
18 PRIMARY KEY(id, tagGroup, tagElement) | |
19 ); | |
20 | |
21 CREATE TABLE Metadata( | |
22 id INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE, | |
23 type INTEGER, | |
24 value TEXT, | |
25 PRIMARY KEY(id, type) | |
26 ); | |
27 | |
28 CREATE TABLE AttachedFiles( | |
29 id INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE, | |
197
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
30 fileType INTEGER, |
181 | 31 uuid TEXT, |
183 | 32 compressedSize INTEGER, |
181 | 33 uncompressedSize INTEGER, |
34 compressionType INTEGER, | |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
616
diff
changeset
|
35 uncompressedMD5 TEXT, -- New in Orthanc 0.7.3 (database v4) |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
616
diff
changeset
|
36 compressedMD5 TEXT, -- New in Orthanc 0.7.3 (database v4) |
197
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
37 PRIMARY KEY(id, fileType) |
181 | 38 ); |
39 | |
183 | 40 CREATE TABLE Changes( |
41 seq INTEGER PRIMARY KEY AUTOINCREMENT, | |
42 changeType INTEGER, | |
189
ccbc2cf64a0d
record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
43 internalId INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE, |
183 | 44 resourceType INTEGER, |
45 date TEXT | |
46 ); | |
47 | |
231 | 48 CREATE TABLE ExportedResources( |
183 | 49 seq INTEGER PRIMARY KEY AUTOINCREMENT, |
231 | 50 resourceType INTEGER, |
51 publicId TEXT, | |
183 | 52 remoteModality TEXT, |
53 patientId TEXT, | |
54 studyInstanceUid TEXT, | |
55 seriesInstanceUid TEXT, | |
56 sopInstanceUid TEXT, | |
57 date TEXT | |
58 ); | |
59 | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
60 CREATE TABLE PatientRecyclingOrder( |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
61 seq INTEGER PRIMARY KEY AUTOINCREMENT, |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
62 patientId INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
63 ); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
64 |
181 | 65 CREATE INDEX ChildrenIndex ON Resources(parentId); |
66 CREATE INDEX PublicIndex ON Resources(publicId); | |
190 | 67 CREATE INDEX ResourceTypeIndex ON Resources(resourceType); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
68 CREATE INDEX PatientRecyclingIndex ON PatientRecyclingOrder(patientId); |
181 | 69 |
183 | 70 CREATE INDEX MainDicomTagsIndex1 ON MainDicomTags(id); |
71 CREATE INDEX MainDicomTagsIndex2 ON MainDicomTags(tagGroup, tagElement); | |
616
dbecea588ef5
revert to database v3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
567
diff
changeset
|
72 CREATE INDEX MainDicomTagsIndexValues ON MainDicomTags(value COLLATE BINARY); |
183 | 73 |
189
ccbc2cf64a0d
record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
74 CREATE INDEX ChangesIndex ON Changes(internalId); |
181 | 75 |
76 CREATE TRIGGER AttachedFileDeleted | |
77 AFTER DELETE ON AttachedFiles | |
78 BEGIN | |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
79 SELECT SignalFileDeleted(old.uuid, old.fileType, old.uncompressedSize, |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
616
diff
changeset
|
80 old.compressionType, old.compressedSize, |
694
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
81 -- These 2 arguments are new in Orthanc 0.7.3 (database v4) |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
616
diff
changeset
|
82 old.uncompressedMD5, old.compressedMD5); |
181 | 83 END; |
84 | |
85 CREATE TRIGGER ResourceDeleted | |
86 AFTER DELETE ON Resources | |
87 BEGIN | |
183 | 88 SELECT SignalRemainingAncestor(parent.publicId, parent.resourceType) |
89 FROM Resources AS parent WHERE internalId = old.parentId; | |
181 | 90 END; |
91 | |
183 | 92 -- Delete a parent resource when its unique child is deleted |
93 CREATE TRIGGER ResourceDeletedParentCleaning | |
94 AFTER DELETE ON Resources | |
95 FOR EACH ROW WHEN (SELECT COUNT(*) FROM Resources WHERE parentId = old.parentId) = 0 | |
96 BEGIN | |
97 DELETE FROM Resources WHERE internalId = old.parentId; | |
98 END; | |
252 | 99 |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
100 CREATE TRIGGER PatientAdded |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
101 AFTER INSERT ON Resources |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
102 FOR EACH ROW WHEN new.resourceType = 1 -- "1" corresponds to "ResourceType_Patient" in C++ |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
103 BEGIN |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
104 INSERT INTO PatientRecyclingOrder VALUES (NULL, new.internalId); |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
105 END; |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
106 |
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
252
diff
changeset
|
107 |
252 | 108 -- Set the version of the database schema |
109 -- The "1" corresponds to the "GlobalProperty_DatabaseSchemaVersion" enumeration | |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
616
diff
changeset
|
110 INSERT INTO GlobalProperties VALUES (1, "4"); |