swadhinbiswas feat: push-mirror, webhook queue, auth-cache, gists/discussions · 8/28/2026
96005fc
55 lines · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
 * Gists Schema - Drizzle ORM
 * GitHub-style standalone code snippets (multi-file, public or secret).
 * V1 scope: no stars, forks, or comments.
 */

import { relations } from "drizzle-orm";
import {
  boolean,
  index,
  jsonb,
  pgTable,
  text,
  timestamp,
} from "drizzle-orm/pg-core";
import { users } from "./users";

/** A single file inside a gist */
export interface GistFile {
  filename: string;
  content: string;
}

export const gists = pgTable(
  "gists",
  {
    id: text("id").primaryKey(),
    userId: text("user_id")
      .notNull()
      .references(() => users.id, { onDelete: "cascade" }),
    description: text("description").notNull().default(""),
    // false = secret (unlisted but link-accessible), true = public
    public: boolean("public").notNull().default(false),
    files: jsonb("files").$type<GistFile[]>().notNull(),
    createdAt: timestamp("created_at").notNull().defaultNow(),
    updatedAt: timestamp("updated_at").notNull().defaultNow(),
  },
  (t) => ({
    userUpdatedIdx: index("gists_user_updated_idx").on(t.userId, t.updatedAt),
    publicIdx: index("gists_public_idx").on(t.public),
  }),
);

// Relations
export const gistsRelations = relations(gists, ({ one }) => ({
  user: one(users, {
    fields: [gists.userId],
    references: [users.id],
  }),
}));

// Types
export type Gist = typeof gists.$inferSelect;
export type NewGist = typeof gists.$inferInsert;