|
@@ -286,72 +286,87 @@
|
286
|
286
|
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 (time, item, quantity) VALUES(NEW.time, NEW.unroasted_id[i], NEW.unroasted_quantity[i]); i := i + 1; END LOOP; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
|
287
|
287
|
query.exec("UPDATE TypicaFeatures SET version = 4 WHERE feature = 'base-features'");
|
288
|
288
|
};
|
289
|
|
- var DBUpdateReminders = function() {
|
290
|
|
- var query = new QSqlQuery;
|
291
|
|
- query.exec("CREATE TABLE IF NOT EXISTS reminders (id bigserial PRIMARY KEY NOT NULL, reminder text NOT NULL)");
|
292
|
|
- query.exec("UPDATE TypicaFeatures SET version = 5 WHERE feature = 'base-features'");
|
293
|
|
- query = query.invalidate();
|
294
|
|
- };
|
|
289
|
+ var DBUpdateReminders = function() {
|
|
290
|
+ var query = new QSqlQuery;
|
|
291
|
+ query.exec("CREATE TABLE IF NOT EXISTS reminders (id bigserial PRIMARY KEY NOT NULL, reminder text NOT NULL)");
|
|
292
|
+ query.exec("UPDATE TypicaFeatures SET version = 5 WHERE feature = 'base-features'");
|
|
293
|
+ query = query.invalidate();
|
|
294
|
+ };
|
295
|
295
|
var DBUpdateSpecification = function() {
|
296
|
|
- var query = new QSqlQuery;
|
297
|
|
- query.exec("CREATE TABLE IF NOT EXISTS roasting_specification (\"time\" timestamp without time zone NOT NULL, item bigint NOT NULL, loss numeric, tolerance numeric, notes text)");
|
298
|
|
- query.exec("UPDATE TypicaFeatures SET version = 6 WHERE feature = 'base-features'");
|
299
|
|
- query = query.invalidate();
|
300
|
|
- };
|
301
|
|
-
|
302
|
|
- query = new QSqlQuery();
|
303
|
|
- /* A table keeps track of database versioning information. This table is created
|
304
|
|
- if required. */
|
305
|
|
- query.exec("CREATE TABLE IF NOT EXISTS TypicaFeatures (feature TEXT PRIMARY KEY, enabled boolean, version bigint)");
|
306
|
|
- /* At the moment everything we're interested in is covered in the base-features
|
307
|
|
- row, but this can be extended later if needed. Each row encodes if certain
|
308
|
|
- database structures exist and what version of those structures exist. */
|
309
|
|
- query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'base-features'");
|
310
|
|
- if(query.next())
|
311
|
|
- {
|
312
|
|
- if(query.value(2) < 1)
|
313
|
|
- {
|
314
|
|
- DBCreateBase();
|
315
|
|
- }
|
316
|
|
- if(query.value(2) < 2)
|
317
|
|
- {
|
318
|
|
- DBUpdateMultiUser();
|
319
|
|
- DBUpdateHistory();
|
320
|
|
- }
|
321
|
|
- if(query.value(2) < 3)
|
322
|
|
- {
|
323
|
|
- DBUpdateNotifications();
|
324
|
|
- }
|
325
|
|
- if(query.value(2) < 4)
|
326
|
|
- {
|
327
|
|
- DBUpdateTriggers();
|
328
|
|
- }
|
329
|
|
- if(query.value(2) < 5)
|
330
|
|
- {
|
331
|
|
- DBUpdateReminders();
|
332
|
|
- }
|
333
|
|
- if(query.value(2) < 6)
|
334
|
|
- {
|
335
|
|
- DBUpdateSpecification();
|
336
|
|
- }
|
337
|
|
- }
|
338
|
|
- else
|
339
|
|
- {
|
340
|
|
- DBCreateBase();
|
341
|
|
- }
|
342
|
|
- query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'sample-roasting'");
|
343
|
|
- if(query.next())
|
344
|
|
- {
|
345
|
|
- if(query.value(2) < 1)
|
|
296
|
+ var query = new QSqlQuery;
|
|
297
|
+ query.exec("CREATE TABLE IF NOT EXISTS roasting_specification (\"time\" timestamp without time zone NOT NULL, item bigint NOT NULL, loss numeric, tolerance numeric, notes text)");
|
|
298
|
+ query.exec("UPDATE TypicaFeatures SET version = 6 WHERE feature = 'base-features'");
|
|
299
|
+ query = query.invalidate();
|
|
300
|
+ };
|
|
301
|
+
|
|
302
|
+ /* Updates for Typica version 1.8 */
|
|
303
|
+ var DBUpdate18 = function() {
|
|
304
|
+ var query = new QSqlQuery;
|
|
305
|
+ /* Create a table for Typica users login data */
|
|
306
|
+ query.exec("CREATE TABLE IF NOT EXISTS typica_users(name TEXT PRIMARY KEY NOT NULL, password TEXT, active boolean NOT NULL, auto_login boolean NOT NULL)");
|
|
307
|
+ /* Update session user logging to only use the database user when a Typica user is not explicitly provided. This maintains compatibility for mixed version use. */
|
|
308
|
+ query.exec("CREATE OR REPLACE FUNCTION log_session_user() RETURNS trigger AS $$ BEGIN IF NEW.person IS NULL THEN NEW.person := session_user; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
|
|
309
|
+
|
|
310
|
+ /* Uncomment before release */
|
|
311
|
+ // query.exec("UPDATE TypicaFeatures SET version = 7 WHERE feature = 'base-features'");
|
|
312
|
+ query = query.invalidate();
|
|
313
|
+ };
|
|
314
|
+ if(Application.databaseConnected()) {
|
|
315
|
+ query = new QSqlQuery();
|
|
316
|
+ /* A table keeps track of database versioning information. This
|
|
317
|
+ table is created
|
|
318
|
+ if required. */
|
|
319
|
+ query.exec("CREATE TABLE IF NOT EXISTS TypicaFeatures (feature TEXT PRIMARY KEY, enabled boolean, version bigint)");
|
|
320
|
+ query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'sample-roasting'");
|
|
321
|
+ if(query.next())
|
|
322
|
+ {
|
|
323
|
+ if(query.value(2) < 1)
|
|
324
|
+ {
|
|
325
|
+ DBCreateSampleRoasting();
|
|
326
|
+ }
|
|
327
|
+ }
|
|
328
|
+ else
|
346
|
329
|
{
|
347
|
330
|
DBCreateSampleRoasting();
|
348
|
331
|
}
|
|
332
|
+ query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'base-features'");
|
|
333
|
+ if(query.next())
|
|
334
|
+ {
|
|
335
|
+ if(query.value(2) < 1)
|
|
336
|
+ {
|
|
337
|
+ DBCreateBase();
|
|
338
|
+ }
|
|
339
|
+ if(query.value(2) < 2)
|
|
340
|
+ {
|
|
341
|
+ DBUpdateMultiUser();
|
|
342
|
+ DBUpdateHistory();
|
|
343
|
+ }
|
|
344
|
+ if(query.value(2) < 3)
|
|
345
|
+ {
|
|
346
|
+ DBUpdateNotifications();
|
|
347
|
+ }
|
|
348
|
+ if(query.value(2) < 4)
|
|
349
|
+ {
|
|
350
|
+ DBUpdateTriggers();
|
|
351
|
+ }
|
|
352
|
+ if(query.value(2) < 5)
|
|
353
|
+ {
|
|
354
|
+ DBUpdateReminders();
|
|
355
|
+ }
|
|
356
|
+ if(query.value(2) < 6)
|
|
357
|
+ {
|
|
358
|
+ DBUpdateSpecification();
|
|
359
|
+ }
|
|
360
|
+ if(query.value(2) < 7) {
|
|
361
|
+ DBUpdate18();
|
|
362
|
+ }
|
|
363
|
+ }
|
|
364
|
+ else
|
|
365
|
+ {
|
|
366
|
+ DBCreateBase();
|
|
367
|
+ }
|
|
368
|
+ query = query.invalidate();
|
349
|
369
|
}
|
350
|
|
- else
|
351
|
|
- {
|
352
|
|
- DBCreateSampleRoasting();
|
353
|
|
- }
|
354
|
|
- query = query.invalidate();
|
355
|
370
|
]]>
|
356
|
371
|
</program>
|
357
|
372
|
</window>
|