From 5c8365554129fb64761690b2d3a1b076a5270a61 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Tue, 8 Dec 2020 16:10:23 -0500 Subject: [PATCH] Add modification timestamp to user metadata --- lib/Database.php | 4 ++-- sql/MySQL/6.sql | 1 + sql/PostgreSQL/6.sql | 1 + sql/SQLite3/6.sql | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Database.php b/lib/Database.php index f961f7dd..b2a7aa38 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -322,8 +322,8 @@ class Database { } $tr = $this->begin(); $find = $this->db->prepare("SELECT count(*) from arsse_user_meta where owner = ? and \"key\" = ?", "str", "strict str"); - $update = $this->db->prepare("UPDATE arsse_user_meta set value = ? where owner = ? and \"key\" = ?", "str", "str", "str"); - $insert = $this->db->prepare("INSERT INTO arsse_user_meta values(?, ?, ?)", "str", "strict str", "str"); + $update = $this->db->prepare("UPDATE arsse_user_meta set value = ?, modified = CURRENT_TIMESTAMP where owner = ? and \"key\" = ?", "str", "str", "str"); + $insert = $this->db->prepare("INSERT INTO arsse_user_meta(owner, \"key\", value) values(?, ?, ?)", "str", "strict str", "str"); foreach ($data as $k => $v) { if ($k === "admin") { $this->db->prepare("UPDATE arsse_users SET admin = ? where id = ?", "bool", "str")->run($v, $user); diff --git a/sql/MySQL/6.sql b/sql/MySQL/6.sql index 23ba5edb..36b2d6e4 100644 --- a/sql/MySQL/6.sql +++ b/sql/MySQL/6.sql @@ -22,6 +22,7 @@ alter table arsse_users modify num bigint unsigned not null; create table arsse_user_meta( owner varchar(255) not null, "key" varchar(255) not null, + modified datetime(0) not null default CURRENT_TIMESTAMP, value longtext, foreign key(owner) references arsse_users(id) on delete cascade on update cascade, primary key(owner,"key") diff --git a/sql/PostgreSQL/6.sql b/sql/PostgreSQL/6.sql index 0b405a27..a32eb0c0 100644 --- a/sql/PostgreSQL/6.sql +++ b/sql/PostgreSQL/6.sql @@ -23,6 +23,7 @@ alter table arsse_users alter column num set not null; create table arsse_user_meta( owner text not null references arsse_users(id) on delete cascade on update cascade, key text not null, + modified timestamp(0) without time zone not null default CURRENT_TIMESTAMP, value text, primary key(owner,key) ); diff --git a/sql/SQLite3/6.sql b/sql/SQLite3/6.sql index 9e86182d..81e9e821 100644 --- a/sql/SQLite3/6.sql +++ b/sql/SQLite3/6.sql @@ -34,6 +34,7 @@ create table arsse_user_meta( -- It is up to individual applications (i.e. the client protocols) to cooperate with names and types owner text not null references arsse_users(id) on delete cascade on update cascade, -- the user to whom the metadata belongs key text not null, -- metadata key + modified text not null default CURRENT_TIMESTAMP, -- time at which the metadata was last changed value text, -- metadata value primary key(owner,key) ) without rowid;