From d9d404ead4027ca551ae615aaa7fb092abef4802 Mon Sep 17 00:00:00 2001 From: checkroom Date: Thu, 19 Dec 2024 12:56:11 +0000 Subject: [PATCH] Added table for bookmarks --- commons/migrations/0001_silent_lester.sql | 19 + commons/migrations/meta/0001_snapshot.json | 550 +++++++++++++++++++++ commons/migrations/meta/_journal.json | 7 + schemas/db/bookmarks.ts | 18 + schemas/db/logs.ts | 21 +- schemas/db/secrets-shared.ts | 4 +- schemas/db/storage_kv.ts | 4 +- schemas/db/storage_res.ts | 4 +- 8 files changed, 612 insertions(+), 15 deletions(-) create mode 100644 commons/migrations/0001_silent_lester.sql create mode 100644 commons/migrations/meta/0001_snapshot.json create mode 100644 schemas/db/bookmarks.ts diff --git a/commons/migrations/0001_silent_lester.sql b/commons/migrations/0001_silent_lester.sql new file mode 100644 index 00000000..b754da6e --- /dev/null +++ b/commons/migrations/0001_silent_lester.sql @@ -0,0 +1,19 @@ +CREATE TABLE `bookmarks` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `curated` integer NOT NULL, + `notes` text, + `tags` text, + `timestamp_added` integer NOT NULL, + `timestamp_visited` integer NOT NULL +); +--> statement-breakpoint +CREATE TABLE `logs` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `session` integer NOT NULL, + `level` integer NOT NULL, + `type` integer NOT NULL, + `what` text, + `root` text, + `path` text, + `timestamp` integer NOT NULL +); diff --git a/commons/migrations/meta/0001_snapshot.json b/commons/migrations/meta/0001_snapshot.json new file mode 100644 index 00000000..5c8a1979 --- /dev/null +++ b/commons/migrations/meta/0001_snapshot.json @@ -0,0 +1,550 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "bda02015-4f80-4a89-b27f-dc86050cdb0d", + "prevId": "c5fc20c2-6e89-4ec1-9ab5-9b049cdc19a5", + "tables": { + "apps": { + "name": "apps", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "app_id": { + "name": "app_id", + "type": "blob", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "base": { + "name": "base", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "apps_app_id_unique": { + "name": "apps_app_id_unique", + "columns": [ + "app_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "bookmarks": { + "name": "bookmarks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "curated": { + "name": "curated", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tags": { + "name": "tags", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "timestamp_added": { + "name": "timestamp_added", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timestamp_visited": { + "name": "timestamp_visited", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "logs": { + "name": "logs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "session": { + "name": "session", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "level": { + "name": "level", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "what": { + "name": "what", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "root": { + "name": "root", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "timestamp": { + "name": "timestamp", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "policies": { + "name": "policies", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "app_id": { + "name": "app_id", + "type": "blob", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "policies_app_id_unique": { + "name": "policies_app_id_unique", + "columns": [ + "app_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "secrets_shared": { + "name": "secrets_shared", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "from_app": { + "name": "from_app", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "with_app": { + "name": "with_app", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "timestamp_creation": { + "name": "timestamp_creation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timestamp_expiring": { + "name": "timestamp_expiring", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "secretsUnique": { + "name": "secretsUnique", + "columns": [ + "from_app", + "with_app", + "tag" + ], + "isUnique": true + } + }, + "foreignKeys": { + "secrets_shared_from_app_apps_id_fk": { + "name": "secrets_shared_from_app_apps_id_fk", + "tableFrom": "secrets_shared", + "tableTo": "apps", + "columnsFrom": [ + "from_app" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "secrets_shared_with_app_apps_id_fk": { + "name": "secrets_shared_with_app_apps_id_fk", + "tableFrom": "secrets_shared", + "tableTo": "apps", + "columnsFrom": [ + "with_app" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "secrets": { + "name": "secrets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "app": { + "name": "app", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "blob", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "secretsUniqueIdx": { + "name": "secretsUniqueIdx", + "columns": [ + "app", + "tag", + "path" + ], + "isUnique": true + } + }, + "foreignKeys": { + "secrets_app_apps_id_fk": { + "name": "secrets_app_apps_id_fk", + "tableFrom": "secrets", + "tableTo": "apps", + "columnsFrom": [ + "app" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "storage_kv": { + "name": "storage_kv", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "app": { + "name": "app", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "blob", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timestamp_creation": { + "name": "timestamp_creation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timestamp_expiring": { + "name": "timestamp_expiring", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "kvUniqueIdx": { + "name": "kvUniqueIdx", + "columns": [ + "app", + "key" + ], + "isUnique": true + } + }, + "foreignKeys": { + "storage_kv_app_apps_id_fk": { + "name": "storage_kv_app_apps_id_fk", + "tableFrom": "storage_kv", + "tableTo": "apps", + "columnsFrom": [ + "app" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "storage_res": { + "name": "storage_res", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "app": { + "name": "app", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "src": { + "name": "src", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "blob", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "hash": { + "name": "hash", + "type": "blob", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timestamp_creation": { + "name": "timestamp_creation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timestamp_expiring": { + "name": "timestamp_expiring", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "resUniqueIdx": { + "name": "resUniqueIdx", + "columns": [ + "app", + "src" + ], + "isUnique": true + } + }, + "foreignKeys": { + "storage_res_app_apps_id_fk": { + "name": "storage_res_app_apps_id_fk", + "tableFrom": "storage_res", + "tableTo": "apps", + "columnsFrom": [ + "app" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/commons/migrations/meta/_journal.json b/commons/migrations/meta/_journal.json index a2f67c22..52fc1246 100644 --- a/commons/migrations/meta/_journal.json +++ b/commons/migrations/meta/_journal.json @@ -8,6 +8,13 @@ "when": 1731863264392, "tag": "0000_flawless_meltdown", "breakpoints": true + }, + { + "idx": 1, + "version": "6", + "when": 1734612906535, + "tag": "0001_silent_lester", + "breakpoints": true } ] } \ No newline at end of file diff --git a/schemas/db/bookmarks.ts b/schemas/db/bookmarks.ts new file mode 100644 index 00000000..67483a9d --- /dev/null +++ b/schemas/db/bookmarks.ts @@ -0,0 +1,18 @@ +import { sqliteTable, integer, text } from "drizzle-orm/sqlite-core" + +/** + * Application logs. In place/addition of them being shown on the terminal, logs gets recorded. + */ +export const bookmarks = sqliteTable('bookmarks', { + id: integer().primaryKey({ autoIncrement: true }), + //If true it was defined by the user, else inferred by history + curated: integer({mode:'boolean'}).notNull(), + //User notes + notes: text(), + //List of tags as JSON array + tags: text({ mode: 'json' }).$type(), + //Recording time + timestamp_added: integer({ mode: 'timestamp_ms' }).notNull(), + //Last visit + timestamp_visited: integer({ mode: 'timestamp_ms' }).notNull(), +}); \ No newline at end of file diff --git a/schemas/db/logs.ts b/schemas/db/logs.ts index f7d39c74..dc628c42 100644 --- a/schemas/db/logs.ts +++ b/schemas/db/logs.ts @@ -1,12 +1,15 @@ -import { sqliteTable, integer, blob, text } from "drizzle-orm/sqlite-core" +import { sqliteTable, integer, text } from "drizzle-orm/sqlite-core" +/** + * Application logs. In place/addition of them being shown on the terminal, logs gets recorded. + */ export const apps = sqliteTable('logs', { - id: integer().primaryKey({ autoIncrement: true }), //Unique id for the message - session: integer().notNull(), //Session id, each instance of vs is a new session - level: integer().notNull(), //Message level - type: integer().notNull(), //Message type - what: text(), //Message explanation - root: text(), //Current app root - path: text(), //Current path in the app where the message was triggered - timestamp: integer().notNull(), //When the message was recorded + id: integer().primaryKey({ autoIncrement: true }), //Unique id for the message + session: integer().notNull(), //Session id, each instance of vs is a new session + level: integer().notNull(), //Message level + type: integer().notNull(), //Message type + what: text(), //Message explanation + root: text(), //Current app root + path: text(), //Current path in the app where the message was triggered + timestamp: integer({ mode: 'timestamp_ms' }).notNull(), //When the message was recorded }); \ No newline at end of file diff --git a/schemas/db/secrets-shared.ts b/schemas/db/secrets-shared.ts index d657ebfe..c7cc4725 100644 --- a/schemas/db/secrets-shared.ts +++ b/schemas/db/secrets-shared.ts @@ -9,6 +9,6 @@ export const secrets_shared = sqliteTable('secrets_shared', { with_app: integer().references(()=> apps.id, {onDelete:'cascade',onUpdate:'cascade'}).notNull(), tag: text(), notes: text(), - timestamp_creation: integer().notNull(), - timestamp_expiring: integer().notNull(), + timestamp_creation: integer({ mode: 'timestamp_ms' }).notNull(), + timestamp_expiring: integer({ mode: 'timestamp_ms' }).notNull(), },(table)=>({idx:uniqueIndex('secretsUnique').on(table.from_app,table.with_app,table.tag)})); \ No newline at end of file diff --git a/schemas/db/storage_kv.ts b/schemas/db/storage_kv.ts index 11339d1a..0ad3dd7c 100644 --- a/schemas/db/storage_kv.ts +++ b/schemas/db/storage_kv.ts @@ -7,6 +7,6 @@ export const storage_kv = sqliteTable('storage_kv', { app: integer().references(()=> apps.id, {onDelete:'cascade',onUpdate:'cascade'}).notNull(), key: text().notNull(), value: blob().notNull(), - timestamp_creation: integer().notNull(), - timestamp_expiring: integer().notNull(), //If null no expiration + timestamp_creation: integer({ mode: 'timestamp_ms' }).notNull(), + timestamp_expiring: integer({ mode: 'timestamp_ms' }).notNull(), //If null no expiration },(table)=>({idx:uniqueIndex('kvUniqueIdx').on(table.app,table.key)})); \ No newline at end of file diff --git a/schemas/db/storage_res.ts b/schemas/db/storage_res.ts index 3448a227..b70ff8d9 100644 --- a/schemas/db/storage_res.ts +++ b/schemas/db/storage_res.ts @@ -8,6 +8,6 @@ export const storage_res = sqliteTable('storage_res', { src: text().notNull(), //URL of the resource content: blob().notNull(), hash: blob().notNull(), //Hash to verify the fresheness of this resource. - timestamp_creation: integer().notNull(), - timestamp_expiring: integer(), //If null no expiration + timestamp_creation: integer({ mode: 'timestamp_ms' }).notNull(), + timestamp_expiring: integer({ mode: 'timestamp_ms' }), //If null no expiration },(table)=>({idx:uniqueIndex('resUniqueIdx').on(table.app,table.src)})); \ No newline at end of file