|
@@ -252,7 +252,25 @@ type="push" />
|
252
|
252
|
query.exec("INSERT INTO TypicaFeatures VALUES('sample-roasting', TRUE, 1)");
|
253
|
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
|
274
|
query = new QSqlQuery();
|
257
|
275
|
/* A table keeps track of database versioning information. This table is created
|
258
|
276
|
if required. */
|
|
@@ -267,6 +285,10 @@ type="push" />
|
267
|
285
|
{
|
268
|
286
|
DBCreateBase();
|
269
|
287
|
}
|
|
288
|
+ if(query.value(2) < 2)
|
|
289
|
+ {
|
|
290
|
+ DBUpdateMultiUser();
|
|
291
|
+ }
|
270
|
292
|
}
|
271
|
293
|
else
|
272
|
294
|
{
|