From cd87b145968a623383ae02d91d68bd752e5f028b Mon Sep 17 00:00:00 2001 From: Damien Sedgwick Date: Sat, 24 Aug 2024 09:53:20 +0100 Subject: [PATCH] added createStatusColumn helper --- packages/frontpage/lib/data/db/post.ts | 9 --------- packages/frontpage/lib/schema.ts | 11 +++++------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/frontpage/lib/data/db/post.ts b/packages/frontpage/lib/data/db/post.ts index c7b5fad0..4c7086b1 100644 --- a/packages/frontpage/lib/data/db/post.ts +++ b/packages/frontpage/lib/data/db/post.ts @@ -200,15 +200,6 @@ export async function unauthed_createPost({ createdAt: new Date(post.createdAt).toISOString(), }); - await tx.insert(schema.Post).values({ - rkey, - cid, - authorDid, - title: post.title, - url: post.url, - createdAt: new Date(post.createdAt).toISOString(), - }); - await tx.insert(schema.ConsumedOffset).values({ offset }); }); diff --git a/packages/frontpage/lib/schema.ts b/packages/frontpage/lib/schema.ts index 416a5859..62882084 100644 --- a/packages/frontpage/lib/schema.ts +++ b/packages/frontpage/lib/schema.ts @@ -20,6 +20,9 @@ const did = customType<{ data: DID }>({ }, }); +const createStatusColumn = (col: string) => + text(col, { enum: ["live", "deleted", "moderator_hidden"] }).default("live"); + export const Post = sqliteTable( "posts", { @@ -37,9 +40,7 @@ export const Post = sqliteTable( .notNull(), authorDid: did("author_did").notNull(), // TODO: add notNull once this is rolled out - status: text("status", { - enum: ["live", "deleted", "moderator_hidden"], - }).default("live"), + status: createStatusColumn("status"), }, (t) => ({ unique_author_rkey: unique().on(t.authorDid, t.rkey), @@ -84,9 +85,7 @@ export const Comment = sqliteTable( .notNull(), authorDid: did("author_did").notNull(), // TODO: add notNull once this is rolled out - status: text("status", { - enum: ["live", "deleted", "moderator_hidden"], - }).default("live"), + status: createStatusColumn("status"), parentCommentId: integer("parent_comment_id"), }, (t) => ({