Begin moving project to use Drizzle instead of prisma

This commit is contained in:
Jesse Wierzbinski 2024-04-11 01:39:07 -10:00
parent b107bed935
commit f7abe06a60
No known key found for this signature in database
49 changed files with 7602 additions and 1267 deletions

View file

@ -0,0 +1,462 @@
-- Current sql file was generated after introspecting the database
-- If you want to run this migration please uncomment this code before executing migrations
/*
CREATE TABLE IF NOT EXISTS "_prisma_migrations" (
"id" varchar(36) PRIMARY KEY NOT NULL,
"checksum" varchar(64) NOT NULL,
"finished_at" timestamp with time zone,
"migration_name" varchar(255) NOT NULL,
"logs" text,
"rolled_back_at" timestamp with time zone,
"started_at" timestamp with time zone DEFAULT now() NOT NULL,
"applied_steps_count" integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Emoji" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"shortcode" text NOT NULL,
"url" text NOT NULL,
"visible_in_picker" boolean NOT NULL,
"instanceId" uuid,
"alt" text,
"content_type" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Like" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"likerId" uuid NOT NULL,
"likedId" uuid NOT NULL,
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "LysandObject" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"remote_id" text NOT NULL,
"type" text NOT NULL,
"uri" text NOT NULL,
"created_at" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
"authorId" uuid,
"extra_data" jsonb NOT NULL,
"extensions" jsonb NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Relationship" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"ownerId" uuid NOT NULL,
"subjectId" uuid NOT NULL,
"following" boolean NOT NULL,
"showingReblogs" boolean NOT NULL,
"notifying" boolean NOT NULL,
"followedBy" boolean NOT NULL,
"blocking" boolean NOT NULL,
"blockedBy" boolean NOT NULL,
"muting" boolean NOT NULL,
"mutingNotifications" boolean NOT NULL,
"requested" boolean NOT NULL,
"domainBlocking" boolean NOT NULL,
"endorsed" boolean NOT NULL,
"languages" text[],
"note" text NOT NULL,
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
"updatedAt" timestamp(3) NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Application" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"name" text NOT NULL,
"website" text,
"vapid_key" text,
"client_id" text NOT NULL,
"secret" text NOT NULL,
"scopes" text NOT NULL,
"redirect_uris" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Token" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"token_type" text NOT NULL,
"scope" text NOT NULL,
"access_token" text NOT NULL,
"code" text NOT NULL,
"created_at" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
"userId" uuid,
"applicationId" uuid
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "_EmojiToUser" (
"A" uuid NOT NULL,
"B" uuid NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "_EmojiToStatus" (
"A" uuid NOT NULL,
"B" uuid NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "_StatusToUser" (
"A" uuid NOT NULL,
"B" uuid NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "_UserPinnedNotes" (
"A" uuid NOT NULL,
"B" uuid NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Attachment" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"url" text NOT NULL,
"remote_url" text,
"thumbnail_url" text,
"mime_type" text NOT NULL,
"description" text,
"blurhash" text,
"sha256" text,
"fps" integer,
"duration" integer,
"width" integer,
"height" integer,
"size" integer,
"statusId" uuid
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Notification" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"type" text NOT NULL,
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
"notifiedId" uuid NOT NULL,
"accountId" uuid NOT NULL,
"statusId" uuid
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Status" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"uri" text,
"authorId" uuid NOT NULL,
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
"updatedAt" timestamp(3) NOT NULL,
"reblogId" uuid,
"content" text DEFAULT '' NOT NULL,
"contentType" text DEFAULT 'text/plain' NOT NULL,
"visibility" text NOT NULL,
"inReplyToPostId" uuid,
"quotingPostId" uuid,
"instanceId" uuid,
"sensitive" boolean NOT NULL,
"spoilerText" text DEFAULT '' NOT NULL,
"applicationId" uuid,
"contentSource" text DEFAULT '' NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Instance" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"base_url" text NOT NULL,
"name" text NOT NULL,
"version" text NOT NULL,
"logo" jsonb NOT NULL,
"disableAutomoderation" boolean DEFAULT false NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "OpenIdAccount" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"userId" uuid,
"serverId" text NOT NULL,
"issuerId" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "User" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"uri" text,
"username" text NOT NULL,
"displayName" text NOT NULL,
"password" text,
"email" text,
"note" text DEFAULT '' NOT NULL,
"isAdmin" boolean DEFAULT false NOT NULL,
"endpoints" jsonb,
"source" jsonb NOT NULL,
"avatar" text NOT NULL,
"header" text NOT NULL,
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
"updatedAt" timestamp(3) NOT NULL,
"isBot" boolean DEFAULT false NOT NULL,
"isLocked" boolean DEFAULT false NOT NULL,
"isDiscoverable" boolean DEFAULT false NOT NULL,
"sanctions" text[] DEFAULT 'RRAY[',
"publicKey" text NOT NULL,
"privateKey" text,
"instanceId" uuid,
"disableAutomoderation" boolean DEFAULT false NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "OpenIdLoginFlow" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"codeVerifier" text NOT NULL,
"applicationId" uuid,
"issuerId" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "Flag" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"flagType" text DEFAULT 'other' NOT NULL,
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL,
"flaggeStatusId" uuid,
"flaggedUserId" uuid
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "ModNote" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"notedStatusId" uuid,
"notedUserId" uuid,
"modId" uuid NOT NULL,
"note" text NOT NULL,
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "ModTag" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"taggedStatusId" uuid,
"taggedUserId" uuid,
"modId" uuid NOT NULL,
"tag" text NOT NULL,
"createdAt" timestamp(3) DEFAULT CURRENT_TIMESTAMP NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "LysandObject_remote_id_key" ON "LysandObject" ("remote_id");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "LysandObject_uri_key" ON "LysandObject" ("uri");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "Application_client_id_key" ON "Application" ("client_id");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "_EmojiToUser_AB_unique" ON "_EmojiToUser" ("A","B");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "_EmojiToUser_B_index" ON "_EmojiToUser" ("B");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "_EmojiToStatus_AB_unique" ON "_EmojiToStatus" ("A","B");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "_EmojiToStatus_B_index" ON "_EmojiToStatus" ("B");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "_StatusToUser_AB_unique" ON "_StatusToUser" ("A","B");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "_StatusToUser_B_index" ON "_StatusToUser" ("B");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "_UserPinnedNotes_AB_unique" ON "_UserPinnedNotes" ("A","B");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "_UserPinnedNotes_B_index" ON "_UserPinnedNotes" ("B");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "Status_uri_key" ON "Status" ("uri");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "User_uri_key" ON "User" ("uri");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "User_username_key" ON "User" ("username");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "User_email_key" ON "User" ("email");--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Emoji" ADD CONSTRAINT "Emoji_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "public"."Instance"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Like" ADD CONSTRAINT "Like_likerId_fkey" FOREIGN KEY ("likerId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Like" ADD CONSTRAINT "Like_likedId_fkey" FOREIGN KEY ("likedId") REFERENCES "public"."Status"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "LysandObject" ADD CONSTRAINT "LysandObject_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "public"."LysandObject"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Relationship" ADD CONSTRAINT "Relationship_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Relationship" ADD CONSTRAINT "Relationship_subjectId_fkey" FOREIGN KEY ("subjectId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Token" ADD CONSTRAINT "Token_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Token" ADD CONSTRAINT "Token_applicationId_fkey" FOREIGN KEY ("applicationId") REFERENCES "public"."Application"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "_EmojiToUser" ADD CONSTRAINT "_EmojiToUser_A_fkey" FOREIGN KEY ("A") REFERENCES "public"."Emoji"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "_EmojiToUser" ADD CONSTRAINT "_EmojiToUser_B_fkey" FOREIGN KEY ("B") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "_EmojiToStatus" ADD CONSTRAINT "_EmojiToStatus_A_fkey" FOREIGN KEY ("A") REFERENCES "public"."Emoji"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "_EmojiToStatus" ADD CONSTRAINT "_EmojiToStatus_B_fkey" FOREIGN KEY ("B") REFERENCES "public"."Status"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "_StatusToUser" ADD CONSTRAINT "_StatusToUser_A_fkey" FOREIGN KEY ("A") REFERENCES "public"."Status"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "_StatusToUser" ADD CONSTRAINT "_StatusToUser_B_fkey" FOREIGN KEY ("B") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "_UserPinnedNotes" ADD CONSTRAINT "_UserPinnedNotes_A_fkey" FOREIGN KEY ("A") REFERENCES "public"."Status"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "_UserPinnedNotes" ADD CONSTRAINT "_UserPinnedNotes_B_fkey" FOREIGN KEY ("B") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Attachment" ADD CONSTRAINT "Attachment_statusId_fkey" FOREIGN KEY ("statusId") REFERENCES "public"."Status"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notification" ADD CONSTRAINT "Notification_notifiedId_fkey" FOREIGN KEY ("notifiedId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notification" ADD CONSTRAINT "Notification_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notification" ADD CONSTRAINT "Notification_statusId_fkey" FOREIGN KEY ("statusId") REFERENCES "public"."Status"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Status" ADD CONSTRAINT "Status_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Status" ADD CONSTRAINT "Status_reblogId_fkey" FOREIGN KEY ("reblogId") REFERENCES "public"."Status"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Status" ADD CONSTRAINT "Status_inReplyToPostId_fkey" FOREIGN KEY ("inReplyToPostId") REFERENCES "public"."Status"("id") ON DELETE set null ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Status" ADD CONSTRAINT "Status_quotingPostId_fkey" FOREIGN KEY ("quotingPostId") REFERENCES "public"."Status"("id") ON DELETE set null ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Status" ADD CONSTRAINT "Status_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "public"."Instance"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Status" ADD CONSTRAINT "Status_applicationId_fkey" FOREIGN KEY ("applicationId") REFERENCES "public"."Application"("id") ON DELETE set null ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "OpenIdAccount" ADD CONSTRAINT "OpenIdAccount_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE set null ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "User" ADD CONSTRAINT "User_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "public"."Instance"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "OpenIdLoginFlow" ADD CONSTRAINT "OpenIdLoginFlow_applicationId_fkey" FOREIGN KEY ("applicationId") REFERENCES "public"."Application"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Flag" ADD CONSTRAINT "Flag_flaggeStatusId_fkey" FOREIGN KEY ("flaggeStatusId") REFERENCES "public"."Status"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Flag" ADD CONSTRAINT "Flag_flaggedUserId_fkey" FOREIGN KEY ("flaggedUserId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModNote" ADD CONSTRAINT "ModNote_notedStatusId_fkey" FOREIGN KEY ("notedStatusId") REFERENCES "public"."Status"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModNote" ADD CONSTRAINT "ModNote_notedUserId_fkey" FOREIGN KEY ("notedUserId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModNote" ADD CONSTRAINT "ModNote_modId_fkey" FOREIGN KEY ("modId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModTag" ADD CONSTRAINT "ModTag_taggedStatusId_fkey" FOREIGN KEY ("taggedStatusId") REFERENCES "public"."Status"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModTag" ADD CONSTRAINT "ModTag_taggedUserId_fkey" FOREIGN KEY ("taggedUserId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModTag" ADD CONSTRAINT "ModTag_modId_fkey" FOREIGN KEY ("modId") REFERENCES "public"."User"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
*/

14
drizzle/db.ts Normal file
View file

@ -0,0 +1,14 @@
import { Client } from "pg";
import { config } from "config-manager";
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from "./schema";
export const client = new Client({
host: config.database.host,
port: Number(config.database.port),
user: config.database.username,
password: config.database.password,
database: config.database.database,
});
export const db = drizzle(client, { schema });

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
{
"version": "5",
"dialect": "pg",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1712805159664,
"tag": "0000_illegal_living_lightning",
"breakpoints": true
}
]
}

677
drizzle/schema.ts Normal file
View file

@ -0,0 +1,677 @@
import {
pgTable,
timestamp,
text,
integer,
foreignKey,
uuid,
boolean,
uniqueIndex,
jsonb,
index,
} from "drizzle-orm/pg-core";
import { relations, sql } from "drizzle-orm";
export const emoji = pgTable("Emoji", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
shortcode: text("shortcode").notNull(),
url: text("url").notNull(),
visibleInPicker: boolean("visible_in_picker").notNull(),
alt: text("alt"),
contentType: text("content_type").notNull(),
instanceId: uuid("instanceId").references(() => instance.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
});
export const like = pgTable("Like", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
likerId: uuid("likerId")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
likedId: uuid("likedId")
.notNull()
.references(() => status.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
});
export const lysandObject = pgTable(
"LysandObject",
{
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
remoteId: text("remote_id").notNull(),
type: text("type").notNull(),
uri: text("uri").notNull(),
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
authorId: uuid("authorId"),
extraData: jsonb("extra_data").notNull(),
extensions: jsonb("extensions").notNull(),
},
(table) => {
return {
remoteIdKey: uniqueIndex("LysandObject_remote_id_key").on(
table.remoteId,
),
uriKey: uniqueIndex("LysandObject_uri_key").on(table.uri),
lysandObjectAuthorIdFkey: foreignKey({
columns: [table.authorId],
foreignColumns: [table.id],
name: "LysandObject_authorId_fkey",
})
.onUpdate("cascade")
.onDelete("cascade"),
};
},
);
export const relationship = pgTable("Relationship", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
ownerId: uuid("ownerId")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
subjectId: uuid("subjectId")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
following: boolean("following").notNull(),
showingReblogs: boolean("showingReblogs").notNull(),
notifying: boolean("notifying").notNull(),
followedBy: boolean("followedBy").notNull(),
blocking: boolean("blocking").notNull(),
blockedBy: boolean("blockedBy").notNull(),
muting: boolean("muting").notNull(),
mutingNotifications: boolean("mutingNotifications").notNull(),
requested: boolean("requested").notNull(),
domainBlocking: boolean("domainBlocking").notNull(),
endorsed: boolean("endorsed").notNull(),
languages: text("languages").array(),
note: text("note").notNull(),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
updatedAt: timestamp("updatedAt", {
precision: 3,
mode: "string",
}).notNull(),
});
export const application = pgTable(
"Application",
{
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
name: text("name").notNull(),
website: text("website"),
vapidKey: text("vapid_key"),
clientId: text("client_id").notNull(),
secret: text("secret").notNull(),
scopes: text("scopes").notNull(),
redirectUris: text("redirect_uris").notNull(),
},
(table) => {
return {
clientIdKey: uniqueIndex("Application_client_id_key").on(
table.clientId,
),
};
},
);
export const token = pgTable("Token", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
tokenType: text("token_type").notNull(),
scope: text("scope").notNull(),
accessToken: text("access_token").notNull(),
code: text("code").notNull(),
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
userId: uuid("userId").references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
applicationId: uuid("applicationId").references(() => application.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
});
export const attachment = pgTable("Attachment", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
url: text("url").notNull(),
remoteUrl: text("remote_url"),
thumbnailUrl: text("thumbnail_url"),
mimeType: text("mime_type").notNull(),
description: text("description"),
blurhash: text("blurhash"),
sha256: text("sha256"),
fps: integer("fps"),
duration: integer("duration"),
width: integer("width"),
height: integer("height"),
size: integer("size"),
statusId: uuid("statusId").references(() => status.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
});
export const notification = pgTable("Notification", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
type: text("type").notNull(),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
notifiedId: uuid("notifiedId")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
accountId: uuid("accountId")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
statusId: uuid("statusId").references(() => status.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
});
export const status = pgTable(
"Status",
{
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
uri: text("uri"),
authorId: uuid("authorId")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
updatedAt: timestamp("updatedAt", {
precision: 3,
mode: "string",
}).notNull(),
reblogId: uuid("reblogId"),
content: text("content").default("").notNull(),
contentType: text("contentType").default("text/plain").notNull(),
visibility: text("visibility").notNull(),
inReplyToPostId: uuid("inReplyToPostId"),
quotingPostId: uuid("quotingPostId"),
instanceId: uuid("instanceId").references(() => instance.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
sensitive: boolean("sensitive").notNull(),
spoilerText: text("spoilerText").default("").notNull(),
applicationId: uuid("applicationId").references(() => application.id, {
onDelete: "set null",
onUpdate: "cascade",
}),
contentSource: text("contentSource").default("").notNull(),
},
(table) => {
return {
uriKey: uniqueIndex("Status_uri_key").on(table.uri),
statusReblogIdFkey: foreignKey({
columns: [table.reblogId],
foreignColumns: [table.id],
name: "Status_reblogId_fkey",
})
.onUpdate("cascade")
.onDelete("cascade"),
statusInReplyToPostIdFkey: foreignKey({
columns: [table.inReplyToPostId],
foreignColumns: [table.id],
name: "Status_inReplyToPostId_fkey",
})
.onUpdate("cascade")
.onDelete("set null"),
statusQuotingPostIdFkey: foreignKey({
columns: [table.quotingPostId],
foreignColumns: [table.id],
name: "Status_quotingPostId_fkey",
})
.onUpdate("cascade")
.onDelete("set null"),
};
},
);
export const instance = pgTable("Instance", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
baseUrl: text("base_url").notNull(),
name: text("name").notNull(),
version: text("version").notNull(),
logo: jsonb("logo").notNull(),
disableAutomoderation: boolean("disableAutomoderation")
.default(false)
.notNull(),
});
export const openIdAccount = pgTable("OpenIdAccount", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
userId: uuid("userId").references(() => user.id, {
onDelete: "set null",
onUpdate: "cascade",
}),
serverId: text("serverId").notNull(),
issuerId: text("issuerId").notNull(),
});
export const user = pgTable(
"User",
{
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
uri: text("uri"),
username: text("username").notNull(),
displayName: text("displayName").notNull(),
password: text("password"),
email: text("email"),
note: text("note").default("").notNull(),
isAdmin: boolean("isAdmin").default(false).notNull(),
endpoints: jsonb("endpoints"),
source: jsonb("source").notNull(),
avatar: text("avatar").notNull(),
header: text("header").notNull(),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
updatedAt: timestamp("updatedAt", {
precision: 3,
mode: "string",
})
.defaultNow()
.notNull(),
isBot: boolean("isBot").default(false).notNull(),
isLocked: boolean("isLocked").default(false).notNull(),
isDiscoverable: boolean("isDiscoverable").default(false).notNull(),
sanctions: text("sanctions").default("RRAY[").array(),
publicKey: text("publicKey").notNull(),
privateKey: text("privateKey"),
instanceId: uuid("instanceId").references(() => instance.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
disableAutomoderation: boolean("disableAutomoderation")
.default(false)
.notNull(),
},
(table) => {
return {
uriKey: uniqueIndex("User_uri_key").on(table.uri),
usernameKey: uniqueIndex("User_username_key").on(table.username),
emailKey: uniqueIndex("User_email_key").on(table.email),
};
},
);
export const openIdLoginFlow = pgTable("OpenIdLoginFlow", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
codeVerifier: text("codeVerifier").notNull(),
applicationId: uuid("applicationId").references(() => application.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
issuerId: text("issuerId").notNull(),
});
export const flag = pgTable("Flag", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
flagType: text("flagType").default("other").notNull(),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
flaggeStatusId: uuid("flaggeStatusId").references(() => status.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
flaggedUserId: uuid("flaggedUserId").references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
});
export const modNote = pgTable("ModNote", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
notedStatusId: uuid("notedStatusId").references(() => status.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
notedUserId: uuid("notedUserId").references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
modId: uuid("modId")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
note: text("note").notNull(),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
});
export const modTag = pgTable("ModTag", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
taggedStatusId: uuid("taggedStatusId").references(() => status.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
taggedUserId: uuid("taggedUserId").references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
modId: uuid("modId")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
tag: text("tag").notNull(),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
});
export const emojiToUser = pgTable(
"_EmojiToUser",
{
a: uuid("A")
.notNull()
.references(() => emoji.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
b: uuid("B")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
},
(table) => {
return {
abUnique: uniqueIndex("_EmojiToUser_AB_unique").on(
table.a,
table.b,
),
bIdx: index().on(table.b),
};
},
);
export const emojiToUserRelations = relations(emojiToUser, ({ one }) => ({
emoji: one(emoji, {
fields: [emojiToUser.a],
references: [emoji.id],
}),
user: one(user, {
fields: [emojiToUser.b],
references: [user.id],
}),
}));
export const emojiToStatus = pgTable(
"_EmojiToStatus",
{
a: uuid("A")
.notNull()
.references(() => emoji.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
b: uuid("B")
.notNull()
.references(() => status.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
},
(table) => {
return {
abUnique: uniqueIndex("_EmojiToStatus_AB_unique").on(
table.a,
table.b,
),
bIdx: index().on(table.b),
};
},
);
export const statusToUser = pgTable(
"_StatusToUser",
{
a: uuid("A")
.notNull()
.references(() => status.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
b: uuid("B")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
},
(table) => {
return {
abUnique: uniqueIndex("_StatusToUser_AB_unique").on(
table.a,
table.b,
),
bIdx: index().on(table.b),
};
},
);
export const userPinnedNotes = pgTable(
"_UserPinnedNotes",
{
a: uuid("A")
.notNull()
.references(() => status.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
b: uuid("B")
.notNull()
.references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
},
(table) => {
return {
abUnique: uniqueIndex("_UserPinnedNotes_AB_unique").on(
table.a,
table.b,
),
bIdx: index().on(table.b),
};
},
);
export const attachmentRelations = relations(attachment, ({ one }) => ({
status: one(status, {
fields: [attachment.statusId],
references: [status.id],
}),
}));
export const userRelations = relations(user, ({ many, one }) => ({
emojis: many(emojiToUser),
pinnedNotes: many(userPinnedNotes),
statuses: many(status, {
relationName: "StatusToAuthor",
}),
likes: many(like),
relationships: many(relationship, {
relationName: "RelationshipToOwner",
}),
relationshipSubjects: many(relationship, {
relationName: "RelationshipToSubject",
}),
notifications: many(notification),
openIdAccounts: many(openIdAccount),
flags: many(flag),
modNotes: many(modNote),
modTags: many(modTag),
tokens: many(token),
instance: one(instance, {
fields: [user.instanceId],
references: [instance.id],
}),
mentionedIn: many(statusToUser),
}));
export const relationshipRelations = relations(relationship, ({ one }) => ({
owner: one(user, {
fields: [relationship.ownerId],
references: [user.id],
relationName: "RelationshipToOwner",
}),
subject: one(user, {
fields: [relationship.subjectId],
references: [user.id],
relationName: "RelationshipToSubject",
}),
}));
export const tokenRelations = relations(token, ({ one }) => ({
user: one(user, {
fields: [token.userId],
references: [user.id],
}),
application: one(application, {
fields: [token.applicationId],
references: [application.id],
}),
}));
export const statusToUserRelations = relations(statusToUser, ({ one }) => ({
status: one(status, {
fields: [statusToUser.a],
references: [status.id],
}),
user: one(user, {
fields: [statusToUser.b],
references: [user.id],
}),
}));
export const userPinnedNotesRelations = relations(
userPinnedNotes,
({ one }) => ({
status: one(status, {
fields: [userPinnedNotes.a],
references: [status.id],
}),
user: one(user, {
fields: [userPinnedNotes.b],
references: [user.id],
}),
}),
);
export const statusRelations = relations(status, ({ many, one }) => ({
emojis: many(emojiToStatus),
author: one(user, {
fields: [status.authorId],
references: [user.id],
relationName: "StatusToAuthor",
}),
attachments: many(attachment),
mentions: many(statusToUser),
reblog: one(status, {
fields: [status.reblogId],
references: [status.id],
relationName: "StatusToReblog",
}),
usersThatHavePinned: many(userPinnedNotes),
inReplyTo: one(status, {
fields: [status.inReplyToPostId],
references: [status.id],
relationName: "StatusToReplying",
}),
quoting: one(status, {
fields: [status.quotingPostId],
references: [status.id],
relationName: "StatusToQuoting",
}),
application: one(application, {
fields: [status.applicationId],
references: [application.id],
}),
quotes: many(status, {
relationName: "StatusToQuoting",
}),
replies: many(status, {
relationName: "StatusToReplying",
}),
likes: many(like),
reblogs: many(status, {
relationName: "StatusToReblog",
}),
}));
export const likeRelations = relations(like, ({ one }) => ({
liker: one(user, {
fields: [like.likerId],
references: [user.id],
}),
liked: one(status, {
fields: [like.likedId],
references: [status.id],
}),
}));
export const emojiRelations = relations(emoji, ({ one, many }) => ({
instance: one(instance, {
fields: [emoji.instanceId],
references: [instance.id],
}),
users: many(emojiToUser),
statuses: many(emojiToStatus),
}));
export const instanceRelations = relations(instance, ({ many }) => ({
users: many(user),
statuses: many(status),
emojis: many(emoji),
}));
export const emojiToStatusRelations = relations(emojiToStatus, ({ one }) => ({
emoji: one(emoji, {
fields: [emojiToStatus.a],
references: [emoji.id],
}),
status: one(status, {
fields: [emojiToStatus.b],
references: [status.id],
}),
}));