Add tracking start date
This commit is contained in:
parent
c49cd7184f
commit
1459ed8814
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "fwdekker/death-notifier",
|
||||
"description": "Get notified when a famous person dies.",
|
||||
"version": "0.17.4", "_comment_version": "Also update version in `package.json`!",
|
||||
"version": "0.18.0", "_comment_version": "Also update version in `package.json`!",
|
||||
"type": "project",
|
||||
"license": "MIT",
|
||||
"homepage": "https://git.fwdekker.com/tools/death-notifier",
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "death-notifier",
|
||||
"version": "0.17.4", "_comment_version": "Also update version in `composer.json`!",
|
||||
"version": "0.18.0", "_comment_version": "Also update version in `composer.json`!",
|
||||
"description": "Get notified when a famous person dies.",
|
||||
"author": "Florine W. Dekker",
|
||||
"browser": "dist/bundle.js",
|
||||
|
|
|
@ -233,6 +233,7 @@
|
|||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Status</th>
|
||||
<th>Added</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -65,6 +65,10 @@ function refreshTrackings(): void {
|
|||
statusCell.innerText = statusText;
|
||||
row.append(statusCell);
|
||||
|
||||
const sinceCell = document.createElement("td");
|
||||
sinceCell.innerText = (new Date(tracking.since * 1000)).toLocaleDateString();
|
||||
row.append(sinceCell);
|
||||
|
||||
const deleteCell = document.createElement("td");
|
||||
const deleteForm = document.createElement("form");
|
||||
deleteForm.addEventListener("submit", (event: SubmitEvent) => {
|
||||
|
|
|
@ -108,6 +108,7 @@ class Database
|
|||
if (Comparator::lessThan($db_version, "0.8.0")) self::migrate_0_8_0();
|
||||
if (Comparator::lessThan($db_version, "0.10.0")) self::migrate_0_10_0();
|
||||
if (Comparator::lessThan($db_version, "0.16.0")) self::migrate_0_16_0();
|
||||
if (Comparator::lessThan($db_version, "0.18.0")) self::migrate_0_18_0();
|
||||
|
||||
// Update version
|
||||
$stmt = $this->conn->prepare("UPDATE meta SET v=:version WHERE k='version';");
|
||||
|
@ -148,7 +149,8 @@ class Database
|
|||
PRIMARY KEY (type, recipient, arg1));");
|
||||
$this->conn->exec("INSERT INTO new_email_tasks (type, recipient, arg1)
|
||||
SELECT type, arg1, arg2
|
||||
FROM email_tasks WHERE arg1 NOT NULL;");
|
||||
FROM email_tasks
|
||||
WHERE arg1 NOT NULL;");
|
||||
$this->conn->exec("DROP TABLE email_tasks;");
|
||||
$this->conn->exec("ALTER TABLE new_email_tasks RENAME TO email_tasks;");
|
||||
}
|
||||
|
@ -196,6 +198,41 @@ class Database
|
|||
PRIMARY KEY (type_key, recipient));");
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates the database from a previous version to one compatible with v0.18.0.
|
||||
*
|
||||
* @return void
|
||||
* @noinspection SqlResolve Function necessarily refers to old schema which is not detected by tools
|
||||
*/
|
||||
private function migrate_0_18_0(): void
|
||||
{
|
||||
$this->logger->notice("Migrating to v0.18.0.");
|
||||
|
||||
$this->conn->exec("CREATE TABLE new_trackings(user_uuid TEXT NOT NULL,
|
||||
person_name TEXT NOT NULL,
|
||||
since INT NOT NULL DEFAULT(unixepoch()),
|
||||
PRIMARY KEY (user_uuid, person_name),
|
||||
FOREIGN KEY (user_uuid) REFERENCES users (uuid)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
FOREIGN KEY (person_name) REFERENCES people (name)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE);");
|
||||
$this->conn->exec("INSERT INTO new_trackings (user_uuid, person_name)
|
||||
SELECT user_uuid, person_name
|
||||
FROM trackings;");
|
||||
$this->conn->exec("DROP TRIGGER people_cull_orphans;");
|
||||
$this->conn->exec("DROP TABLE trackings;");
|
||||
$this->conn->exec("ALTER TABLE new_trackings RENAME TO trackings;");
|
||||
$this->conn->exec("CREATE TRIGGER people_cull_orphans
|
||||
AFTER DELETE ON trackings
|
||||
FOR EACH ROW
|
||||
WHEN (SELECT COUNT(*) FROM trackings WHERE person_name=OLD.person_name)=0
|
||||
BEGIN
|
||||
DELETE FROM people WHERE name=OLD.person_name;
|
||||
END;");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes {@see $lambda} within a transaction, allowing nesting.
|
||||
|
|
|
@ -51,6 +51,7 @@ class TrackingList
|
|||
$conn = $this->database->conn;
|
||||
$conn->exec("CREATE TABLE trackings(user_uuid TEXT NOT NULL,
|
||||
person_name TEXT NOT NULL,
|
||||
since INT NOT NULL DEFAULT(unixepoch()),
|
||||
PRIMARY KEY (user_uuid, person_name),
|
||||
FOREIGN KEY (user_uuid) REFERENCES users (uuid)
|
||||
ON DELETE CASCADE
|
||||
|
@ -58,7 +59,6 @@ class TrackingList
|
|||
FOREIGN KEY (person_name) REFERENCES people (name)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE);");
|
||||
// TODO: Add column for date since tracking
|
||||
$conn->exec("CREATE TABLE people(name TEXT NOT NULL UNIQUE PRIMARY KEY,
|
||||
status TEXT NOT NULL DEFAULT(''),
|
||||
is_deleted INT NOT NULL DEFAULT(0));");
|
||||
|
@ -156,7 +156,7 @@ class TrackingList
|
|||
*/
|
||||
public function list_trackings(string $user_uuid): array
|
||||
{
|
||||
$stmt = $this->database->conn->prepare("SELECT people.name, people.status, people.is_deleted
|
||||
$stmt = $this->database->conn->prepare("SELECT people.name, people.status, people.is_deleted, since
|
||||
FROM trackings
|
||||
INNER JOIN people
|
||||
ON trackings.user_uuid=:user_uuid
|
||||
|
|
Loading…
Reference in New Issue