Browse Source

Session user logging in transaction and roasting_log tables

Neal Wilson 11 years ago
parent
commit
328c61022a
1 changed files with 23 additions and 1 deletions
  1. 23
    1
      config/Windows/navigation.xml

+ 23
- 1
config/Windows/navigation.xml View File

252
 			query.exec("INSERT INTO TypicaFeatures VALUES('sample-roasting', TRUE, 1)");
252
 			query.exec("INSERT INTO TypicaFeatures VALUES('sample-roasting', TRUE, 1)");
253
 			query = query.invalidate();
253
 			query = query.invalidate();
254
 		};
254
 		};
255
-
255
+		
256
+		/* Some changes to the database are required to log who performed what tasks.
257
+		   This adds logging for all transaction types and also for the roasting log.*/
258
+		var DBUpdateMultiUser = function() {
259
+			var query = new QSqlQuery;
260
+			query.exec("ALTER TABLE transactions ADD COLUMN person text DEFAULT NULL");
261
+			query.exec("ALTER TABLE roasting_log ADD COLUMN person text DEFAULT NULL");
262
+			query.exec("CREATE FUNCTION log_session_user() RETURNS trigger AS $$ BEGIN NEW.person := session_name; RETURN NEW; END; $$ LANGUAGE plpgsql");
263
+			query.exec("CREATE TRIGGER log_person BEFORE INSERT ON inventory FOR EACH ROW EXECUTE PROCEDURE log_session_user()");
264
+			query.exec("CREATE TRIGGER log_person BEFORE INSERT ON loss FOR EACH ROW EXECUTE PROCEDURE log_session_user()");
265
+			query.exec("CREATE TRIGGER log_person BEFORE INSERT ON make FOR EACH ROW EXECUTE PROCEDURE log_session_user()");
266
+			query.exec("CREATE TRIGGER log_person BEFORE INSERT ON purchase FOR EACH ROW EXECUTE PROCEDURE log_session_user()");
267
+			query.exec("CREATE TRIGGER log_person BEFORE INSERT ON sale FOR EACH ROW EXECUTE PROCEDURE log_session_user()");
268
+			query.exec("CREATE TRIGGER log_person BEFORE INSERT ON use FOR EACH ROW EXECUTE PROCEDURE log_session_user()");
269
+			query.exec("CREATE TRIGGER log_person BEFORE INSERT ON roasting_log FOR EACH ROW EXECUTE PROCEDURE log_session_user()");
270
+			query.exec("INSERT INTO TypicaFeatures VALUES('base-features', TRUE, 2)");
271
+			query = query.invalidate();
272
+		};
273
+		
256
 		query = new QSqlQuery();
274
 		query = new QSqlQuery();
257
 		/* A table keeps track of database versioning information. This table is created
275
 		/* A table keeps track of database versioning information. This table is created
258
 		   if required. */
276
 		   if required. */
267
 			{
285
 			{
268
 				DBCreateBase();
286
 				DBCreateBase();
269
 			}
287
 			}
288
+			if(query.value(2) < 2)
289
+			{
290
+				DBUpdateMultiUser();
291
+			}
270
 		}
292
 		}
271
 		else
293
 		else
272
 		{
294
 		{

Loading…
Cancel
Save