Skip to content

Commit

Permalink
added createStatusColumn helper
Browse files Browse the repository at this point in the history
  • Loading branch information
damiensedgwick committed Aug 24, 2024
1 parent 7d664d6 commit cd87b14
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
9 changes: 0 additions & 9 deletions packages/frontpage/lib/data/db/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});

Expand Down
11 changes: 5 additions & 6 deletions packages/frontpage/lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand All @@ -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),
Expand Down Expand Up @@ -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) => ({
Expand Down

0 comments on commit cd87b14

Please sign in to comment.