From 400a5949ab763768e5c3b1052dc0662acb6348ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andri=20=C3=93skarsson?= Date: Tue, 7 Jan 2025 14:37:42 +0100 Subject: [PATCH] prepare for supporting other feed events --- .../db/drizzle/0027_faulty_madame_masque.sql | 2 + .../drizzle/0028_normal_valeria_richards.sql | 1 + .../db/drizzle/0029_wonderful_quasimodo.sql | 1 + .../db/drizzle/0030_last_texas_twister.sql | 1 + .../db/drizzle/meta/0027_snapshot.json | 602 +++++++++++++++++ .../db/drizzle/meta/0028_snapshot.json | 602 +++++++++++++++++ .../db/drizzle/meta/0029_snapshot.json | 596 +++++++++++++++++ .../db/drizzle/meta/0030_snapshot.json | 603 ++++++++++++++++++ .../atproto/db/drizzle/meta/_journal.json | 28 + .../atproto/domain/post/content-flags.test.ts | 44 -- .../atproto/domain/post/post-flags.test.ts | 10 + .../post/{content-flags.ts => post-flags.ts} | 2 +- packages/atproto/domain/post/post.table.ts | 2 +- .../domain/queue-for-classification.ts | 5 + packages/atproto/helpers/bitmask.ts | 56 -- 15 files changed, 2453 insertions(+), 102 deletions(-) create mode 100644 packages/atproto/db/drizzle/0027_faulty_madame_masque.sql create mode 100644 packages/atproto/db/drizzle/0028_normal_valeria_richards.sql create mode 100644 packages/atproto/db/drizzle/0029_wonderful_quasimodo.sql create mode 100644 packages/atproto/db/drizzle/0030_last_texas_twister.sql create mode 100644 packages/atproto/db/drizzle/meta/0027_snapshot.json create mode 100644 packages/atproto/db/drizzle/meta/0028_snapshot.json create mode 100644 packages/atproto/db/drizzle/meta/0029_snapshot.json create mode 100644 packages/atproto/db/drizzle/meta/0030_snapshot.json delete mode 100644 packages/atproto/domain/post/content-flags.test.ts create mode 100644 packages/atproto/domain/post/post-flags.test.ts rename packages/atproto/domain/post/{content-flags.ts => post-flags.ts} (85%) delete mode 100644 packages/atproto/helpers/bitmask.ts diff --git a/packages/atproto/db/drizzle/0027_faulty_madame_masque.sql b/packages/atproto/db/drizzle/0027_faulty_madame_masque.sql new file mode 100644 index 0000000..573ba11 --- /dev/null +++ b/packages/atproto/db/drizzle/0027_faulty_madame_masque.sql @@ -0,0 +1,2 @@ +ALTER TABLE "post" ADD COLUMN "collection" text DEFAULT 'app.bsky.feed.post' NOT NULL;--> statement-breakpoint +ALTER TABLE "post" ADD COLUMN "content_flags" integer; \ No newline at end of file diff --git a/packages/atproto/db/drizzle/0028_normal_valeria_richards.sql b/packages/atproto/db/drizzle/0028_normal_valeria_richards.sql new file mode 100644 index 0000000..f82b1be --- /dev/null +++ b/packages/atproto/db/drizzle/0028_normal_valeria_richards.sql @@ -0,0 +1 @@ +ALTER TABLE "post" RENAME COLUMN "content_flags" TO "flags"; \ No newline at end of file diff --git a/packages/atproto/db/drizzle/0029_wonderful_quasimodo.sql b/packages/atproto/db/drizzle/0029_wonderful_quasimodo.sql new file mode 100644 index 0000000..42812a0 --- /dev/null +++ b/packages/atproto/db/drizzle/0029_wonderful_quasimodo.sql @@ -0,0 +1 @@ +ALTER TABLE "post" DROP COLUMN "flags"; \ No newline at end of file diff --git a/packages/atproto/db/drizzle/0030_last_texas_twister.sql b/packages/atproto/db/drizzle/0030_last_texas_twister.sql new file mode 100644 index 0000000..de67a0f --- /dev/null +++ b/packages/atproto/db/drizzle/0030_last_texas_twister.sql @@ -0,0 +1 @@ +ALTER TABLE "post" ADD COLUMN "flags" integer DEFAULT 0 NOT NULL; \ No newline at end of file diff --git a/packages/atproto/db/drizzle/meta/0027_snapshot.json b/packages/atproto/db/drizzle/meta/0027_snapshot.json new file mode 100644 index 0000000..dc079e6 --- /dev/null +++ b/packages/atproto/db/drizzle/meta/0027_snapshot.json @@ -0,0 +1,602 @@ +{ + "id": "fe8426fc-970d-4f1a-815a-a1869137c552", + "prevId": "866da020-e85a-40a5-bc66-1fd95eee279c", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.app": { + "name": "app", + "schema": "", + "columns": { + "k": { + "name": "k", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "v": { + "name": "v", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tfjs_model": { + "name": "tfjs_model", + "schema": "", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "model_json": { + "name": "model_json", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "weights": { + "name": "weights", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "unique_words": { + "name": "unique_words", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "word_index": { + "name": "word_index", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "(CURRENT_TIMESTAMP)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_ranking": { + "name": "post_ranking", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "algo": { + "name": "algo", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "post_ranking_post_id_post_id_fk": { + "name": "post_ranking_post_id_post_id_fk", + "tableFrom": "post_ranking", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "post_ranking_tag_id_tag_id_fk": { + "name": "post_ranking_tag_id_tag_id_fk", + "tableFrom": "post_ranking", + "tableTo": "tag", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_record": { + "name": "post_record", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cid": { + "name": "cid", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "post_idx": { + "name": "post_idx", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_record_post_id_post_id_fk": { + "name": "post_record_post_id_post_id_fk", + "tableFrom": "post_record", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_tag": { + "name": "post_tag", + "schema": "", + "columns": { + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "algo": { + "name": "algo", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "tagpost_idx": { + "name": "tagpost_idx", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tag_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_tag_tag_id_tag_id_fk": { + "name": "post_tag_tag_id_tag_id_fk", + "tableFrom": "post_tag", + "tableTo": "tag", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "post_tag_post_id_post_id_fk": { + "name": "post_tag_post_id_post_id_fk", + "tableFrom": "post_tag", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "post_tag_algo_post_id_tag_id_unique": { + "name": "post_tag_algo_post_id_tag_id_unique", + "nullsNotDistinct": false, + "columns": [ + "algo", + "post_id", + "tag_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_texts": { + "name": "post_texts", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_postid": { + "name": "idx_postid", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_texts_post_id_post_id_fk": { + "name": "post_texts_post_id_post_id_fk", + "tableFrom": "post_texts", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_post_source": { + "name": "uniq_post_source", + "nullsNotDistinct": false, + "columns": [ + "post_id", + "source" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post": { + "name": "post", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "collection": { + "name": "collection", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'app.bsky.feed.post'" + }, + "content_flags": { + "name": "content_flags", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "modified": { + "name": "modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_created": { + "name": "idx_created", + "columns": [ + { + "expression": "created", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag": { + "name": "tag", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.follow": { + "name": "follow", + "schema": "", + "columns": { + "followed_by": { + "name": "followed_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "follows": { + "name": "follows", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "followedby_idx": { + "name": "followedby_idx", + "columns": [ + { + "expression": "followed_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "follow_followed_by_user_did_fk": { + "name": "follow_followed_by_user_did_fk", + "tableFrom": "follow", + "tableTo": "user", + "columnsFrom": [ + "followed_by" + ], + "columnsTo": [ + "did" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "follow_follows_followed_by_pk": { + "name": "follow_follows_followed_by_pk", + "columns": [ + "follows", + "followed_by" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "did": { + "name": "did", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "modified": { + "name": "modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": { + "public.posts_tag_avg": { + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "definition": "select \"post_id\", \"tag_id\", round(avg(\"score\"), 0) as \"avg_score\", ARRAY_AGG(DISTINCT \"algo\") as \"algos\" from \"post_tag\" group by \"post_tag\".\"post_id\", \"post_tag\".\"tag_id\"", + "name": "posts_tag_avg", + "schema": "public", + "isExisting": false, + "materialized": false + } + }, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/atproto/db/drizzle/meta/0028_snapshot.json b/packages/atproto/db/drizzle/meta/0028_snapshot.json new file mode 100644 index 0000000..13598d3 --- /dev/null +++ b/packages/atproto/db/drizzle/meta/0028_snapshot.json @@ -0,0 +1,602 @@ +{ + "id": "7a32f0a7-0447-45cb-8e70-306bdb01bceb", + "prevId": "fe8426fc-970d-4f1a-815a-a1869137c552", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.app": { + "name": "app", + "schema": "", + "columns": { + "k": { + "name": "k", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "v": { + "name": "v", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tfjs_model": { + "name": "tfjs_model", + "schema": "", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "model_json": { + "name": "model_json", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "weights": { + "name": "weights", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "unique_words": { + "name": "unique_words", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "word_index": { + "name": "word_index", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "(CURRENT_TIMESTAMP)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_ranking": { + "name": "post_ranking", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "algo": { + "name": "algo", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "post_ranking_post_id_post_id_fk": { + "name": "post_ranking_post_id_post_id_fk", + "tableFrom": "post_ranking", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "post_ranking_tag_id_tag_id_fk": { + "name": "post_ranking_tag_id_tag_id_fk", + "tableFrom": "post_ranking", + "tableTo": "tag", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_record": { + "name": "post_record", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cid": { + "name": "cid", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "post_idx": { + "name": "post_idx", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_record_post_id_post_id_fk": { + "name": "post_record_post_id_post_id_fk", + "tableFrom": "post_record", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_tag": { + "name": "post_tag", + "schema": "", + "columns": { + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "algo": { + "name": "algo", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "tagpost_idx": { + "name": "tagpost_idx", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tag_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_tag_tag_id_tag_id_fk": { + "name": "post_tag_tag_id_tag_id_fk", + "tableFrom": "post_tag", + "tableTo": "tag", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "post_tag_post_id_post_id_fk": { + "name": "post_tag_post_id_post_id_fk", + "tableFrom": "post_tag", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "post_tag_algo_post_id_tag_id_unique": { + "name": "post_tag_algo_post_id_tag_id_unique", + "nullsNotDistinct": false, + "columns": [ + "algo", + "post_id", + "tag_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_texts": { + "name": "post_texts", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_postid": { + "name": "idx_postid", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_texts_post_id_post_id_fk": { + "name": "post_texts_post_id_post_id_fk", + "tableFrom": "post_texts", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_post_source": { + "name": "uniq_post_source", + "nullsNotDistinct": false, + "columns": [ + "post_id", + "source" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post": { + "name": "post", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "collection": { + "name": "collection", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'app.bsky.feed.post'" + }, + "flags": { + "name": "flags", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "modified": { + "name": "modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_created": { + "name": "idx_created", + "columns": [ + { + "expression": "created", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag": { + "name": "tag", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.follow": { + "name": "follow", + "schema": "", + "columns": { + "followed_by": { + "name": "followed_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "follows": { + "name": "follows", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "followedby_idx": { + "name": "followedby_idx", + "columns": [ + { + "expression": "followed_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "follow_followed_by_user_did_fk": { + "name": "follow_followed_by_user_did_fk", + "tableFrom": "follow", + "tableTo": "user", + "columnsFrom": [ + "followed_by" + ], + "columnsTo": [ + "did" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "follow_follows_followed_by_pk": { + "name": "follow_follows_followed_by_pk", + "columns": [ + "follows", + "followed_by" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "did": { + "name": "did", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "modified": { + "name": "modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": { + "public.posts_tag_avg": { + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "definition": "select \"post_id\", \"tag_id\", round(avg(\"score\"), 0) as \"avg_score\", ARRAY_AGG(DISTINCT \"algo\") as \"algos\" from \"post_tag\" group by \"post_tag\".\"post_id\", \"post_tag\".\"tag_id\"", + "name": "posts_tag_avg", + "schema": "public", + "isExisting": false, + "materialized": false + } + }, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/atproto/db/drizzle/meta/0029_snapshot.json b/packages/atproto/db/drizzle/meta/0029_snapshot.json new file mode 100644 index 0000000..cb9b096 --- /dev/null +++ b/packages/atproto/db/drizzle/meta/0029_snapshot.json @@ -0,0 +1,596 @@ +{ + "id": "587b114e-a10e-458f-985f-015b7b4da5a4", + "prevId": "7a32f0a7-0447-45cb-8e70-306bdb01bceb", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.app": { + "name": "app", + "schema": "", + "columns": { + "k": { + "name": "k", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "v": { + "name": "v", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tfjs_model": { + "name": "tfjs_model", + "schema": "", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "model_json": { + "name": "model_json", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "weights": { + "name": "weights", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "unique_words": { + "name": "unique_words", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "word_index": { + "name": "word_index", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "(CURRENT_TIMESTAMP)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_ranking": { + "name": "post_ranking", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "algo": { + "name": "algo", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "post_ranking_post_id_post_id_fk": { + "name": "post_ranking_post_id_post_id_fk", + "tableFrom": "post_ranking", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "post_ranking_tag_id_tag_id_fk": { + "name": "post_ranking_tag_id_tag_id_fk", + "tableFrom": "post_ranking", + "tableTo": "tag", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_record": { + "name": "post_record", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cid": { + "name": "cid", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "post_idx": { + "name": "post_idx", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_record_post_id_post_id_fk": { + "name": "post_record_post_id_post_id_fk", + "tableFrom": "post_record", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_tag": { + "name": "post_tag", + "schema": "", + "columns": { + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "algo": { + "name": "algo", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "tagpost_idx": { + "name": "tagpost_idx", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tag_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_tag_tag_id_tag_id_fk": { + "name": "post_tag_tag_id_tag_id_fk", + "tableFrom": "post_tag", + "tableTo": "tag", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "post_tag_post_id_post_id_fk": { + "name": "post_tag_post_id_post_id_fk", + "tableFrom": "post_tag", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "post_tag_algo_post_id_tag_id_unique": { + "name": "post_tag_algo_post_id_tag_id_unique", + "nullsNotDistinct": false, + "columns": [ + "algo", + "post_id", + "tag_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_texts": { + "name": "post_texts", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_postid": { + "name": "idx_postid", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_texts_post_id_post_id_fk": { + "name": "post_texts_post_id_post_id_fk", + "tableFrom": "post_texts", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_post_source": { + "name": "uniq_post_source", + "nullsNotDistinct": false, + "columns": [ + "post_id", + "source" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post": { + "name": "post", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "collection": { + "name": "collection", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'app.bsky.feed.post'" + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "modified": { + "name": "modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_created": { + "name": "idx_created", + "columns": [ + { + "expression": "created", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag": { + "name": "tag", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.follow": { + "name": "follow", + "schema": "", + "columns": { + "followed_by": { + "name": "followed_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "follows": { + "name": "follows", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "followedby_idx": { + "name": "followedby_idx", + "columns": [ + { + "expression": "followed_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "follow_followed_by_user_did_fk": { + "name": "follow_followed_by_user_did_fk", + "tableFrom": "follow", + "tableTo": "user", + "columnsFrom": [ + "followed_by" + ], + "columnsTo": [ + "did" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "follow_follows_followed_by_pk": { + "name": "follow_follows_followed_by_pk", + "columns": [ + "follows", + "followed_by" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "did": { + "name": "did", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "modified": { + "name": "modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": { + "public.posts_tag_avg": { + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "definition": "select \"post_id\", \"tag_id\", round(avg(\"score\"), 0) as \"avg_score\", ARRAY_AGG(DISTINCT \"algo\") as \"algos\" from \"post_tag\" group by \"post_tag\".\"post_id\", \"post_tag\".\"tag_id\"", + "name": "posts_tag_avg", + "schema": "public", + "isExisting": false, + "materialized": false + } + }, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/atproto/db/drizzle/meta/0030_snapshot.json b/packages/atproto/db/drizzle/meta/0030_snapshot.json new file mode 100644 index 0000000..870686b --- /dev/null +++ b/packages/atproto/db/drizzle/meta/0030_snapshot.json @@ -0,0 +1,603 @@ +{ + "id": "e09df0e1-93ca-4980-bb26-c0c839d5eb3a", + "prevId": "587b114e-a10e-458f-985f-015b7b4da5a4", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.app": { + "name": "app", + "schema": "", + "columns": { + "k": { + "name": "k", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "v": { + "name": "v", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tfjs_model": { + "name": "tfjs_model", + "schema": "", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "model_json": { + "name": "model_json", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "weights": { + "name": "weights", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "unique_words": { + "name": "unique_words", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "word_index": { + "name": "word_index", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "(CURRENT_TIMESTAMP)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_ranking": { + "name": "post_ranking", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "algo": { + "name": "algo", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "post_ranking_post_id_post_id_fk": { + "name": "post_ranking_post_id_post_id_fk", + "tableFrom": "post_ranking", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "post_ranking_tag_id_tag_id_fk": { + "name": "post_ranking_tag_id_tag_id_fk", + "tableFrom": "post_ranking", + "tableTo": "tag", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_record": { + "name": "post_record", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cid": { + "name": "cid", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "post_idx": { + "name": "post_idx", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_record_post_id_post_id_fk": { + "name": "post_record_post_id_post_id_fk", + "tableFrom": "post_record", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_tag": { + "name": "post_tag", + "schema": "", + "columns": { + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "algo": { + "name": "algo", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "tagpost_idx": { + "name": "tagpost_idx", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tag_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_tag_tag_id_tag_id_fk": { + "name": "post_tag_tag_id_tag_id_fk", + "tableFrom": "post_tag", + "tableTo": "tag", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "post_tag_post_id_post_id_fk": { + "name": "post_tag_post_id_post_id_fk", + "tableFrom": "post_tag", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "post_tag_algo_post_id_tag_id_unique": { + "name": "post_tag_algo_post_id_tag_id_unique", + "nullsNotDistinct": false, + "columns": [ + "algo", + "post_id", + "tag_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post_texts": { + "name": "post_texts", + "schema": "", + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_postid": { + "name": "idx_postid", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_texts_post_id_post_id_fk": { + "name": "post_texts_post_id_post_id_fk", + "tableFrom": "post_texts", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_post_source": { + "name": "uniq_post_source", + "nullsNotDistinct": false, + "columns": [ + "post_id", + "source" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post": { + "name": "post", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "collection": { + "name": "collection", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'app.bsky.feed.post'" + }, + "flags": { + "name": "flags", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "modified": { + "name": "modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_created": { + "name": "idx_created", + "columns": [ + { + "expression": "created", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag": { + "name": "tag", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.follow": { + "name": "follow", + "schema": "", + "columns": { + "followed_by": { + "name": "followed_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "follows": { + "name": "follows", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "followedby_idx": { + "name": "followedby_idx", + "columns": [ + { + "expression": "followed_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "follow_followed_by_user_did_fk": { + "name": "follow_followed_by_user_did_fk", + "tableFrom": "follow", + "tableTo": "user", + "columnsFrom": [ + "followed_by" + ], + "columnsTo": [ + "did" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "follow_follows_followed_by_pk": { + "name": "follow_follows_followed_by_pk", + "columns": [ + "follows", + "followed_by" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "did": { + "name": "did", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "created": { + "name": "created", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "modified": { + "name": "modified", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": { + "public.posts_tag_avg": { + "columns": { + "post_id": { + "name": "post_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_id": { + "name": "tag_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "definition": "select \"post_id\", \"tag_id\", round(avg(\"score\"), 0) as \"avg_score\", ARRAY_AGG(DISTINCT \"algo\") as \"algos\" from \"post_tag\" group by \"post_tag\".\"post_id\", \"post_tag\".\"tag_id\"", + "name": "posts_tag_avg", + "schema": "public", + "isExisting": false, + "materialized": false + } + }, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/atproto/db/drizzle/meta/_journal.json b/packages/atproto/db/drizzle/meta/_journal.json index bee190f..ba12829 100644 --- a/packages/atproto/db/drizzle/meta/_journal.json +++ b/packages/atproto/db/drizzle/meta/_journal.json @@ -190,6 +190,34 @@ "when": 1735749507222, "tag": "0026_nifty_jimmy_woo", "breakpoints": true + }, + { + "idx": 27, + "version": "7", + "when": 1736085165021, + "tag": "0027_faulty_madame_masque", + "breakpoints": true + }, + { + "idx": 28, + "version": "7", + "when": 1736086460696, + "tag": "0028_normal_valeria_richards", + "breakpoints": true + }, + { + "idx": 29, + "version": "7", + "when": 1736086502447, + "tag": "0029_wonderful_quasimodo", + "breakpoints": true + }, + { + "idx": 30, + "version": "7", + "when": 1736086520878, + "tag": "0030_last_texas_twister", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/atproto/domain/post/content-flags.test.ts b/packages/atproto/domain/post/content-flags.test.ts deleted file mode 100644 index 239bc38..0000000 --- a/packages/atproto/domain/post/content-flags.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { expect, test } from "bun:test"; -import { BitFlags } from "../../helpers/bitmask"; -import { ContentFlags } from "./content-flags"; - -test("BitFlags.From", () => { - const flags = BitFlags.FromFlags( - ContentFlags.ExternalLink, - ContentFlags.EmbedRecord, - ContentFlags.Body - ); - const bitmask = flags.toBitmask(); - const origin = BitFlags.FromBitmask(bitmask); - - expect(origin.has(ContentFlags.Body)).toBe(true); - expect(origin.has(ContentFlags.ExternalLink)).toBe(true); - expect(origin.has(ContentFlags.EmbedRecord)).toBe(true); - expect(origin.has(ContentFlags.EmbedMedia)).toBe(false); -}); - -test("For zero values", () => { - const flags = BitFlags.FromBitmask(0); - expect(flags.has(ContentFlags.Body)).toBe(false); -}); - -test("BitFlags constructor", () => { - const mask = BitFlags.FromFlags( - ContentFlags.Body, - ContentFlags.EmbedMedia, - ContentFlags.ExternalLink - ); - expect(mask.has(ContentFlags.Body)).toBe(true); - expect(mask.has(ContentFlags.ExternalLink)).toBe(true); - expect(mask.has(ContentFlags.EmbedRecord)).toBe(false); - expect(mask.has(ContentFlags.EmbedMedia)).toBe(true); -}); - -test("BitFlags.add", () => { - const flags = BitFlags.FromBitmask(0); - flags.add(ContentFlags.Body); - expect(flags.has(ContentFlags.Body)).toBe(true); - expect(flags.has(ContentFlags.ExternalLink)).toBe(false); - expect(flags.has(ContentFlags.EmbedRecord)).toBe(false); - expect(flags.has(ContentFlags.EmbedMedia)).toBe(false); -}); diff --git a/packages/atproto/domain/post/post-flags.test.ts b/packages/atproto/domain/post/post-flags.test.ts new file mode 100644 index 0000000..5228407 --- /dev/null +++ b/packages/atproto/domain/post/post-flags.test.ts @@ -0,0 +1,10 @@ +import { expect, test } from "bun:test"; +import { PostFlags } from "./post-flags"; + +test("BitFlags.From", () => { + const bodyAndEmbedMedia = PostFlags.Body | PostFlags.EmbedMedia; + const mask = 9; + expect(mask & bodyAndEmbedMedia).not.toBe(0); + + //expect(origin.has(ContentFlags.EmbedMedia)).toBe(false); +}); diff --git a/packages/atproto/domain/post/content-flags.ts b/packages/atproto/domain/post/post-flags.ts similarity index 85% rename from packages/atproto/domain/post/content-flags.ts rename to packages/atproto/domain/post/post-flags.ts index fb54960..0fcea39 100644 --- a/packages/atproto/domain/post/content-flags.ts +++ b/packages/atproto/domain/post/post-flags.ts @@ -1,5 +1,5 @@ /** Used to quickly identify what sort of content this post has */ -export enum ContentFlags { +export enum PostFlags { Body = 1 << 0, ExternalLink = 1 << 1, EmbedRecord = 1 << 2, diff --git a/packages/atproto/domain/post/post.table.ts b/packages/atproto/domain/post/post.table.ts index df64792..0b9718f 100644 --- a/packages/atproto/domain/post/post.table.ts +++ b/packages/atproto/domain/post/post.table.ts @@ -6,7 +6,7 @@ export const postTable = pgTable( id: text().primaryKey(), // aturi authorId: text("author_id").notNull(), collection: text("collection").default("app.bsky.feed.post").notNull(), - contentFlags: integer("content_flags"), // bitmask for content types + flags: integer("flags").notNull().default(0), // See PostFlags created: timestamp({ withTimezone: true, }) diff --git a/packages/atproto/domain/queue-for-classification.ts b/packages/atproto/domain/queue-for-classification.ts index 70d4009..635a7de 100644 --- a/packages/atproto/domain/queue-for-classification.ts +++ b/packages/atproto/domain/queue-for-classification.ts @@ -13,6 +13,7 @@ export type FeedPostWithUri = { record: AppBskyFeedPost.Record; }; +// TODO: This should probably receive the full jetstream event export async function queueForClassification( ctx: AtContext, post: FeedPostWithUri @@ -29,6 +30,8 @@ export async function queueForClassification( const uri = new AtUri(post.uri); const authorId = uri.hostname; + // TODO: Post Flags for the database + try { await ctx.db.transaction(async (tx) => { await tx @@ -38,6 +41,8 @@ export async function queueForClassification( id: post.uri, created: new Date(post.record.createdAt), modified: new Date(post.record.createdAt), + collection: "app.bsky.feed.post", + flags: 0, }) .onConflictDoNothing(); // TODO: Maybe store author in a table later for scoring diff --git a/packages/atproto/helpers/bitmask.ts b/packages/atproto/helpers/bitmask.ts deleted file mode 100644 index 3ae510d..0000000 --- a/packages/atproto/helpers/bitmask.ts +++ /dev/null @@ -1,56 +0,0 @@ -/** Retrospective. This is stupid, and I should just learn to love bitwise operations - * - * @deprecated - */ -export class BitFlags { - private bitmask: number; - - private constructor(...modifiers: FN[]) { - this.bitmask = modifiers.reduce((mask, modifier) => mask | modifier, 0); - } - - static FromFlags(...modifiers: Array) { - return new BitFlags(); - } - - static FromBitmask(bitmask: number): BitFlags { - return new BitFlags(...this.GetModifiersFromBitmask(bitmask)); - } - - has(modifier: FN): boolean { - return (this.bitmask & modifier) === modifier; - } - - toBitmask(): number { - return this.bitmask as number; - } - - add(...modifiers: FN[]): BitFlags { - const newBitmask = modifiers.reduce( - (mask, modifier) => mask | modifier, - this.bitmask - ); - return new BitFlags(...BitFlags.GetModifiersFromBitmask(newBitmask)); - } - - remove(...modifiers: FN[]): BitFlags { - const newBitmask = modifiers.reduce( - (mask, modifier) => mask & ~modifier, - this.bitmask - ); - return new BitFlags(...BitFlags.GetModifiersFromBitmask(newBitmask)); - } - - private static GetModifiersFromBitmask( - bitmask: number - ): M[] { - const modifiers: M[] = []; - for (let i = 0; i < 32; i++) { - const modifier = 1 << i; - if ((bitmask & modifier) === modifier) { - modifiers.push(modifier as M); - } - } - return modifiers; - } -} -- 2.51.2