annotate OrthancServer/PrepareDatabase.sql @ 267:2ccf556dc1ce Orthanc-0.3.1

close
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 29 Apr 2013 12:55:01 +0200
parents bd009f0b1931
children 2354560daf2f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 value TEXT
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 );
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 CREATE TABLE Resources(
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 internalId INTEGER PRIMARY KEY AUTOINCREMENT,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 resourceType INTEGER,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 publicId TEXT,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 parentId INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 );
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 CREATE TABLE MainDicomTags(
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 id INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 tagGroup INTEGER,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 tagElement INTEGER,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 value TEXT,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 PRIMARY KEY(id, tagGroup, tagElement)
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 );
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 CREATE TABLE Metadata(
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 id INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 type INTEGER,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 value TEXT,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 PRIMARY KEY(id, type)
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 );
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 CREATE TABLE AttachedFiles(
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 uuid TEXT,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
32 compressedSize INTEGER,
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 uncompressedSize INTEGER,
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 compressionType INTEGER,
197
530a25320461 removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
35 PRIMARY KEY(id, fileType)
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 );
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
38 CREATE TABLE Changes(
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
39 seq INTEGER PRIMARY KEY AUTOINCREMENT,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
40 changeType INTEGER,
189
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 183
diff changeset
41 internalId INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
42 resourceType INTEGER,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
43 date TEXT
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
44 );
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
45
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
46 CREATE TABLE ExportedResources(
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
47 seq INTEGER PRIMARY KEY AUTOINCREMENT,
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
48 resourceType INTEGER,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
49 publicId TEXT,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
50 remoteModality TEXT,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
51 patientId TEXT,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
52 studyInstanceUid TEXT,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
53 seriesInstanceUid TEXT,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
54 sopInstanceUid TEXT,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
55 date TEXT
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
56 );
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
57
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 CREATE INDEX ChildrenIndex ON Resources(parentId);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 CREATE INDEX PublicIndex ON Resources(publicId);
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
60 CREATE INDEX ResourceTypeIndex ON Resources(resourceType);
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
62 CREATE INDEX MainDicomTagsIndex1 ON MainDicomTags(id);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
63 CREATE INDEX MainDicomTagsIndex2 ON MainDicomTags(tagGroup, tagElement);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
64 CREATE INDEX MainDicomTagsIndexValues ON MainDicomTags(value COLLATE BINARY);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
65
189
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 183
diff changeset
66 CREATE INDEX ChangesIndex ON Changes(internalId);
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 CREATE TRIGGER AttachedFileDeleted
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 AFTER DELETE ON AttachedFiles
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 BEGIN
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 SELECT SignalFileDeleted(old.uuid);
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 END;
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 CREATE TRIGGER ResourceDeleted
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 AFTER DELETE ON Resources
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 BEGIN
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
77 SELECT SignalRemainingAncestor(parent.publicId, parent.resourceType)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
78 FROM Resources AS parent WHERE internalId = old.parentId;
181
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 END;
2dece1526c06 simplifying db schema
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
81 -- Delete a parent resource when its unique child is deleted
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
82 CREATE TRIGGER ResourceDeletedParentCleaning
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
83 AFTER DELETE ON Resources
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
84 FOR EACH ROW WHEN (SELECT COUNT(*) FROM Resources WHERE parentId = old.parentId) = 0
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
85 BEGIN
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
86 DELETE FROM Resources WHERE internalId = old.parentId;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 181
diff changeset
87 END;
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
88
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
89 -- Set the version of the database schema
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
90 -- The "1" corresponds to the "GlobalProperty_DatabaseSchemaVersion" enumeration
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
91 INSERT INTO GlobalProperties VALUES (1, "2");