Browse Source

Finalize database changes

Neal Wilson 7 years ago
parent
commit
a495482ef8
1 changed files with 22 additions and 16 deletions
  1. 22
    16
      config/Windows/navigation.xml

+ 22
- 16
config/Windows/navigation.xml View File

239
 		   Typica 1.6 and later. */
239
 		   Typica 1.6 and later. */
240
 		var DBCreateSampleRoasting = function() {
240
 		var DBCreateSampleRoasting = function() {
241
 			var query = new QSqlQuery;
241
 			var query = new QSqlQuery;
242
-			query.exec("CREATE TABLE IF NOT EXISTS item_attributes (id bigint PRIMARY KEY NOT NULL, name text NOT NULL)");
242
+			query.exec("CREATE TABLE IF NOT EXISTS item_attributes (id bigserial PRIMARY KEY NOT NULL, name text NOT NULL)");
243
 			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)");
243
 			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)");
244
 			query.exec("INSERT INTO TypicaFeatures (feature, enabled, version) VALUES('sample-roasting', TRUE, 1)");
244
 			query.exec("INSERT INTO TypicaFeatures (feature, enabled, version) VALUES('sample-roasting', TRUE, 1)");
245
 			query = query.invalidate();
245
 			query = query.invalidate();
310
 			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");
310
 			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");
311
 			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, person) VALUES(NEW.time, NEW.unroasted_id[i], NEW.unroasted_quantity[i], NEW.person); i := i + 1; END LOOP; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
311
 			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, person) VALUES(NEW.time, NEW.unroasted_id[i], NEW.unroasted_quantity[i], NEW.person); i := i + 1; END LOOP; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
312
 			query.exec("CREATE OR REPLACE FUNCTION log_make() RETURNS trigger AS $$ BEGIN IF NEW.roasted_quantity IS NOT NULL THEN INSERT INTO make (time, item, quantity, person) VALUES(NEW.time, NEW.roasted_id, NEW.roasted_quantity, NEW.person); END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
312
 			query.exec("CREATE OR REPLACE FUNCTION log_make() RETURNS trigger AS $$ BEGIN IF NEW.roasted_quantity IS NOT NULL THEN INSERT INTO make (time, item, quantity, person) VALUES(NEW.time, NEW.roasted_id, NEW.roasted_quantity, NEW.person); END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
313
-			
314
-			/* Uncomment before release */
315
-			// query.exec("UPDATE TypicaFeatures SET version = 7 WHERE feature = 'base-features'");
313
+			query.exec("CREATE TABLE IF NOT EXISTS sample_roast_profiles(\"time\" timestamp without time zone NOT NULL, profile_name TEXT NOT NULL, file bigint NOT NULL)");
314
+			query.exec("UPDATE TypicaFeatures SET version = 7 WHERE feature = 'base-features'");
316
 			query = query.invalidate();
315
 			query = query.invalidate();
317
 		};
316
 		};
318
 		if(Application.databaseConnected()) {
317
 		if(Application.databaseConnected()) {
321
 			   table is created
320
 			   table is created
322
 			   if required. */
321
 			   if required. */
323
 			query.exec("CREATE TABLE IF NOT EXISTS TypicaFeatures (feature TEXT PRIMARY KEY, enabled boolean, version bigint)");
322
 			query.exec("CREATE TABLE IF NOT EXISTS TypicaFeatures (feature TEXT PRIMARY KEY, enabled boolean, version bigint)");
324
-			query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'sample-roasting'");
325
-			if(query.next())
326
-			{
327
-				if(query.value(2) < 1)
328
-				{
329
-					DBCreateSampleRoasting();
330
-				}
331
-			}
332
-			else
333
-			{
334
-				DBCreateSampleRoasting();
335
-			}
336
 			query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'base-features'");
323
 			query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'base-features'");
337
 			if(query.next())
324
 			if(query.next())
338
 			{
325
 			{
368
 			else
355
 			else
369
 			{
356
 			{
370
 				DBCreateBase();
357
 				DBCreateBase();
358
+				DBUpdateMultiUser();
359
+		        DBUpdateHistory();
360
+				DBUpdateNotifications();
361
+				DBUpdateTriggers();
362
+				DBUpdateReminders();
363
+				DBUpdateSpecification();
364
+				DBUpdate18();
365
+			}
366
+			query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'sample-roasting'");
367
+			if(query.next())
368
+			{
369
+				if(query.value(2) < 1)
370
+				{
371
+					DBCreateSampleRoasting();
372
+				}
373
+			}
374
+			else
375
+			{
376
+				DBCreateSampleRoasting();
371
 			}
377
 			}
372
 			var promptNewUsers = true;
378
 			var promptNewUsers = true;
373
 			query.exec("SELECT count(1) FROM typica_users");
379
 			query.exec("SELECT count(1) FROM typica_users");

Loading…
Cancel
Save