Pārlūkot izejas kodu

Database updates for sample roasting feature.

Neal Wilson 11 gadus atpakaļ
vecāks
revīzija
9ff08dc4f0
1 mainītis faili ar 25 papildinājumiem un 0 dzēšanām
  1. 25
    0
      config/Windows/navigation.xml

+ 25
- 0
config/Windows/navigation.xml Parādīt failu

@@ -241,6 +241,18 @@ type="push" />
241 241
 			query.exec("INSERT INTO TypicaFeatures VALUES('base-features', TRUE, 1)");
242 242
 			query = query.invalidate();
243 243
 		};
244
+		
245
+		/* Some changes to the database are required for sample roasting features in
246
+		   Typica 1.6 and later. */
247
+		var DBCreateSampleRoasting = function() {
248
+			var query = new QSqlQuery;
249
+			query.exec("CREATE OR REPLACE FUNCTION log_use() RETURNS trigger AS $$ DECLARE i integer := array_lower(NEW.unroasted_id, 1); u integer := array_upper(NEW.unroasted_id, 1); BEGIN IF NEW.transaction_type = 'ROAST' THEN WHILE i <= u LOOP INSERT INTO use VALUES(NEW.time, NEW.unroasted_id[i], NEW.unroasted_quantity[i]); i := i + 1; END LOOP; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
250
+			query.exec("CREATE TABLE IF NOT EXISTS item_attributes (id bigint PRIMARY KEY NOT NULL, name text NOT NULL)");
251
+			query.exec("CREATE TABLE IF NOT EXISTS coffee_sample_items(arrival timestamp without time zone, vendor text, attribute_ids bigint[], attribute_values text[]. item_id bigint) INHERITS (items)");
252
+			query.exec("INSERT INTO TypicaFeatures VALUES('sample-roasting', TRUE, 1)");
253
+			query = query.invalidate();
254
+		};
255
+
244 256
 		query = new QSqlQuery();
245 257
 		/* A table keeps track of database versioning information. This table is created
246 258
 		   if required. */
@@ -260,6 +272,19 @@ type="push" />
260 272
 		{
261 273
 			DBCreateBase();
262 274
 		}
275
+		query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'sample-roasting'");
276
+		if(query.next())
277
+		{
278
+			if(query.value(2) < 1)
279
+			{
280
+				DBCreateSampleRoasting();
281
+			}
282
+		}
283
+		else
284
+		{
285
+			DBCreateSampleRoasting();
286
+		}
287
+		query = query.invalidate();
263 288
         ]]>
264 289
     </program>
265 290
 </window>

Notiek ielāde…
Atcelt
Saglabāt