forked from denoland/std
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use ULID for notifications functionality (denoland#483)
Changes: 1. Notifications use ULIDs for their IDs. 2. Removes the `notifications` index from KV, as it seems unnecessary. 3. Removed the `createdAt` property from notifications. 4. Removes `newNotificationProps()`, as it now seems unnecessary. Closes denoland#473 Towards denoland#470 CC @lino-levan (this might be a good reference to learn more about ULIDs)
- Loading branch information
Showing
9 changed files
with
111 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2023 the Deno authors. All rights reserved. MIT license. | ||
/** | ||
* This script is used to perform migration jobs on the database. These jobs | ||
* can be performed on remote KV instances using | ||
* {@link https://github.com/denoland/deno/tree/main/ext/kv#kv-connect|KV Connect}. | ||
* | ||
* This script will continually change over time for database migrations, as | ||
* required. | ||
* | ||
* @example | ||
* ```bash | ||
* deno task db:migrate | ||
* ``` | ||
*/ | ||
import { kv, type Notification } from "@/utils/db.ts"; | ||
|
||
interface OldNotification extends Notification { | ||
createdAt: Date; | ||
} | ||
|
||
if (!confirm("WARNING: The database will be migrated. Continue?")) Deno.exit(); | ||
|
||
const promises = []; | ||
|
||
const iter1 = kv.list<OldNotification>({ prefix: ["notifications"] }); | ||
for await (const { key } of iter1) promises.push(kv.delete(key)); | ||
|
||
const iter2 = kv.list<OldNotification>({ prefix: ["notifications_by_user"] }); | ||
for await (const { key } of iter2) promises.push(kv.delete(key)); | ||
|
||
const results = await Promise.allSettled(promises); | ||
results.forEach((result) => { | ||
if (result.status === "rejected") console.error(result); | ||
}); | ||
|
||
kv.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters