comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 221:73cc85f3d9c1

implementation of the "serverIdentifier" information for global properties
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Mar 2021 10:40:34 +0200
parents fbb52129158a
children 94c9908e6aca
comparison
equal deleted inserted replaced
220:492aa3edf572 221:73cc85f3d9c1
89 89
90 Orthanc::EmbeddedResources::GetFileResource 90 Orthanc::EmbeddedResources::GetFileResource
91 (query, Orthanc::EmbeddedResources::POSTGRESQL_PREPARE_INDEX); 91 (query, Orthanc::EmbeddedResources::POSTGRESQL_PREPARE_INDEX);
92 db->Execute(query); 92 db->Execute(query);
93 93
94 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); 94 SetGlobalIntegerProperty(*db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion);
95 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, 1); 95 SetGlobalIntegerProperty(*db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, 1);
96 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasTrigramIndex, 0); 96 SetGlobalIntegerProperty(*db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasTrigramIndex, 0);
97 } 97 }
98 98
99 if (!db->DoesTableExist("Resources")) 99 if (!db->DoesTableExist("Resources"))
100 { 100 {
101 LOG(ERROR) << "Corrupted PostgreSQL database"; 101 LOG(ERROR) << "Corrupted PostgreSQL database";
102 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); 102 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
103 } 103 }
104 104
105 int version = 0; 105 int version = 0;
106 if (!LookupGlobalIntegerProperty(version, *db, t, Orthanc::GlobalProperty_DatabaseSchemaVersion) || 106 if (!LookupGlobalIntegerProperty(version, *db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion) ||
107 version != 6) 107 version != 6)
108 { 108 {
109 LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema version: " << version; 109 LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema version: " << version;
110 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); 110 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
111 } 111 }
112 112
113 int revision; 113 int revision;
114 if (!LookupGlobalIntegerProperty(revision, *db, t, Orthanc::GlobalProperty_DatabasePatchLevel)) 114 if (!LookupGlobalIntegerProperty(revision, *db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel))
115 { 115 {
116 revision = 1; 116 revision = 1;
117 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, revision); 117 SetGlobalIntegerProperty(*db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
118 } 118 }
119 119
120 if (revision != 1) 120 if (revision != 1)
121 { 121 {
122 LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema revision: " << revision; 122 LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema revision: " << revision;
128 128
129 { 129 {
130 PostgreSQLTransaction t(*db, TransactionType_ReadWrite); 130 PostgreSQLTransaction t(*db, TransactionType_ReadWrite);
131 131
132 int hasTrigram = 0; 132 int hasTrigram = 0;
133 if (!LookupGlobalIntegerProperty(hasTrigram, *db, t, 133 if (!LookupGlobalIntegerProperty(hasTrigram, *db, t, MISSING_SERVER_IDENTIFIER,
134 Orthanc::GlobalProperty_HasTrigramIndex) || 134 Orthanc::GlobalProperty_HasTrigramIndex) ||
135 hasTrigram != 1) 135 hasTrigram != 1)
136 { 136 {
137 /** 137 /**
138 * Apply fix for performance issue (speed up wildcard search 138 * Apply fix for performance issue (speed up wildcard search
152 152
153 db->Execute( 153 db->Execute(
154 "CREATE EXTENSION IF NOT EXISTS pg_trgm; " 154 "CREATE EXTENSION IF NOT EXISTS pg_trgm; "
155 "CREATE INDEX DicomIdentifiersIndexValues2 ON DicomIdentifiers USING gin(value gin_trgm_ops);"); 155 "CREATE INDEX DicomIdentifiersIndexValues2 ON DicomIdentifiers USING gin(value gin_trgm_ops);");
156 156
157 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasTrigramIndex, 1); 157 SetGlobalIntegerProperty(*db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasTrigramIndex, 1);
158 LOG(WARNING) << "Trigram index has been created"; 158 LOG(WARNING) << "Trigram index has been created";
159 159
160 t.Commit(); 160 t.Commit();
161 } 161 }
162 catch (Orthanc::OrthancException&) 162 catch (Orthanc::OrthancException&)
175 175
176 { 176 {
177 PostgreSQLTransaction t(*db, TransactionType_ReadWrite); 177 PostgreSQLTransaction t(*db, TransactionType_ReadWrite);
178 178
179 int property = 0; 179 int property = 0;
180 if (!LookupGlobalIntegerProperty(property, *db, t, 180 if (!LookupGlobalIntegerProperty(property, *db, t, MISSING_SERVER_IDENTIFIER,
181 Orthanc::GlobalProperty_HasCreateInstance) || 181 Orthanc::GlobalProperty_HasCreateInstance) ||
182 property != 2) 182 property != 2)
183 { 183 {
184 LOG(INFO) << "Installing the CreateInstance extension"; 184 LOG(INFO) << "Installing the CreateInstance extension";
185 185
193 std::string query; 193 std::string query;
194 Orthanc::EmbeddedResources::GetFileResource 194 Orthanc::EmbeddedResources::GetFileResource
195 (query, Orthanc::EmbeddedResources::POSTGRESQL_CREATE_INSTANCE); 195 (query, Orthanc::EmbeddedResources::POSTGRESQL_CREATE_INSTANCE);
196 db->Execute(query); 196 db->Execute(query);
197 197
198 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasCreateInstance, 2); 198 SetGlobalIntegerProperty(*db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasCreateInstance, 2);
199 } 199 }
200 200
201 201
202 if (!LookupGlobalIntegerProperty(property, *db, t, 202 if (!LookupGlobalIntegerProperty(property, *db, t, MISSING_SERVER_IDENTIFIER,
203 Orthanc::GlobalProperty_GetTotalSizeIsFast) || 203 Orthanc::GlobalProperty_GetTotalSizeIsFast) ||
204 property != 1) 204 property != 1)
205 { 205 {
206 LOG(INFO) << "Installing the FastTotalSize extension"; 206 LOG(INFO) << "Installing the FastTotalSize extension";
207 207
208 std::string query; 208 std::string query;
209 Orthanc::EmbeddedResources::GetFileResource 209 Orthanc::EmbeddedResources::GetFileResource
210 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_TOTAL_SIZE); 210 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_TOTAL_SIZE);
211 db->Execute(query); 211 db->Execute(query);
212 212
213 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_GetTotalSizeIsFast, 1); 213 SetGlobalIntegerProperty(*db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_GetTotalSizeIsFast, 1);
214 } 214 }
215 215
216 216
217 // Installing this extension requires the "GlobalIntegers" table 217 // Installing this extension requires the "GlobalIntegers" table
218 // created by the "FastTotalSize" extension 218 // created by the "FastTotalSize" extension
219 property = 0; 219 property = 0;
220 if (!LookupGlobalIntegerProperty(property, *db, t, 220 if (!LookupGlobalIntegerProperty(property, *db, t, MISSING_SERVER_IDENTIFIER,
221 Orthanc::GlobalProperty_HasFastCountResources) || 221 Orthanc::GlobalProperty_HasFastCountResources) ||
222 property != 1) 222 property != 1)
223 { 223 {
224 LOG(INFO) << "Installing the FastCountResources extension"; 224 LOG(INFO) << "Installing the FastCountResources extension";
225 225
226 std::string query; 226 std::string query;
227 Orthanc::EmbeddedResources::GetFileResource 227 Orthanc::EmbeddedResources::GetFileResource
228 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_COUNT_RESOURCES); 228 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_COUNT_RESOURCES);
229 db->Execute(query); 229 db->Execute(query);
230 230
231 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasFastCountResources, 1); 231 SetGlobalIntegerProperty(*db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasFastCountResources, 1);
232 } 232 }
233 233
234 234
235 // Installing this extension requires the "GlobalIntegers" table 235 // Installing this extension requires the "GlobalIntegers" table
236 // created by the "GetLastChangeIndex" extension 236 // created by the "GetLastChangeIndex" extension
237 property = 0; 237 property = 0;
238 if (!LookupGlobalIntegerProperty(property, *db, t, 238 if (!LookupGlobalIntegerProperty(property, *db, t, MISSING_SERVER_IDENTIFIER,
239 Orthanc::GlobalProperty_GetLastChangeIndex) || 239 Orthanc::GlobalProperty_GetLastChangeIndex) ||
240 property != 1) 240 property != 1)
241 { 241 {
242 LOG(INFO) << "Installing the GetLastChangeIndex extension"; 242 LOG(INFO) << "Installing the GetLastChangeIndex extension";
243 243
244 std::string query; 244 std::string query;
245 Orthanc::EmbeddedResources::GetFileResource 245 Orthanc::EmbeddedResources::GetFileResource
246 (query, Orthanc::EmbeddedResources::POSTGRESQL_GET_LAST_CHANGE_INDEX); 246 (query, Orthanc::EmbeddedResources::POSTGRESQL_GET_LAST_CHANGE_INDEX);
247 db->Execute(query); 247 db->Execute(query);
248 248
249 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_GetLastChangeIndex, 1); 249 SetGlobalIntegerProperty(*db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_GetLastChangeIndex, 1);
250 } 250 }
251 251
252 t.Commit(); 252 t.Commit();
253 } 253 }
254 } 254 }