mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Clean up database with new schema
This commit is contained in:
parent
a65249b79d
commit
0ca77e9dcc
|
|
@ -23,7 +23,7 @@ import {
|
||||||
instance,
|
instance,
|
||||||
type like,
|
type like,
|
||||||
status,
|
status,
|
||||||
statusToUser,
|
statusToMentions,
|
||||||
user,
|
user,
|
||||||
} from "~drizzle/schema";
|
} from "~drizzle/schema";
|
||||||
import type { APIAttachment } from "~types/entities/attachment";
|
import type { APIAttachment } from "~types/entities/attachment";
|
||||||
|
|
@ -946,8 +946,8 @@ export const createNewStatus = async (
|
||||||
await db
|
await db
|
||||||
.insert(emojiToStatus)
|
.insert(emojiToStatus)
|
||||||
.values({
|
.values({
|
||||||
a: emoji.id,
|
emojiId: emoji.id,
|
||||||
b: newStatus.id,
|
statusId: newStatus.id,
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
@ -955,10 +955,10 @@ export const createNewStatus = async (
|
||||||
// Connect mentions
|
// Connect mentions
|
||||||
for (const mention of mentions ?? []) {
|
for (const mention of mentions ?? []) {
|
||||||
await db
|
await db
|
||||||
.insert(statusToUser)
|
.insert(statusToMentions)
|
||||||
.values({
|
.values({
|
||||||
a: newStatus.id,
|
statusId: newStatus.id,
|
||||||
b: mention.id,
|
userId: mention.id,
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
@ -1109,8 +1109,8 @@ export const editStatus = async (
|
||||||
await db
|
await db
|
||||||
.insert(emojiToStatus)
|
.insert(emojiToStatus)
|
||||||
.values({
|
.values({
|
||||||
a: emoji.id,
|
emojiId: emoji.id,
|
||||||
b: updated.id,
|
statusId: updated.id,
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
@ -1118,10 +1118,10 @@ export const editStatus = async (
|
||||||
// Connect mentions
|
// Connect mentions
|
||||||
for (const mention of mentions) {
|
for (const mention of mentions) {
|
||||||
await db
|
await db
|
||||||
.insert(statusToUser)
|
.insert(statusToMentions)
|
||||||
.values({
|
.values({
|
||||||
a: updated.id,
|
statusId: updated.id,
|
||||||
b: mention.id,
|
userId: mention.id,
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
@ -1157,11 +1157,11 @@ export const statusToAPI = async (
|
||||||
userFetching?: UserWithRelations,
|
userFetching?: UserWithRelations,
|
||||||
): Promise<APIStatus> => {
|
): Promise<APIStatus> => {
|
||||||
const wasPinnedByUser = userFetching
|
const wasPinnedByUser = userFetching
|
||||||
? !!(await db.query.statusToUser.findFirst({
|
? !!(await db.query.userPinnedNotes.findFirst({
|
||||||
where: (relation, { and, eq }) =>
|
where: (relation, { and, eq }) =>
|
||||||
and(
|
and(
|
||||||
eq(relation.a, statusToConvert.id),
|
eq(relation.statusId, statusToConvert.id),
|
||||||
eq(relation.b, userFetching?.id),
|
eq(relation.userId, userFetching?.id),
|
||||||
),
|
),
|
||||||
}))
|
}))
|
||||||
: false;
|
: false;
|
||||||
|
|
|
||||||
|
|
@ -108,14 +108,14 @@ export const userExtrasTemplate = (name: string) => ({
|
||||||
instance: true,
|
instance: true,
|
||||||
emojis: {
|
emojis: {
|
||||||
with: {
|
with: {
|
||||||
instance: true,
|
emoji: {
|
||||||
|
with: {
|
||||||
|
instance: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extras: {
|
|
||||||
//
|
|
||||||
followerCount: sql`SELECT COUNT(*) FROM relationship WHERE owner_id = user.id AND following = true`,
|
|
||||||
},
|
|
||||||
}); */
|
}); */
|
||||||
|
|
||||||
export interface AuthData {
|
export interface AuthData {
|
||||||
|
|
@ -262,8 +262,8 @@ export const transformOutputToUserWithRelations = (
|
||||||
followingCount: unknown;
|
followingCount: unknown;
|
||||||
statusCount: unknown;
|
statusCount: unknown;
|
||||||
emojis: {
|
emojis: {
|
||||||
a: string;
|
userId: string;
|
||||||
b: string;
|
emojiId: string;
|
||||||
emoji?: EmojiWithInstance;
|
emoji?: EmojiWithInstance;
|
||||||
}[];
|
}[];
|
||||||
instance: InferSelectModel<typeof instance> | null;
|
instance: InferSelectModel<typeof instance> | null;
|
||||||
|
|
@ -447,8 +447,8 @@ export const resolveUser = async (
|
||||||
if (emojis.length > 0) {
|
if (emojis.length > 0) {
|
||||||
await db.insert(emojiToUser).values(
|
await db.insert(emojiToUser).values(
|
||||||
emojis.map((emoji) => ({
|
emojis.map((emoji) => ({
|
||||||
a: emoji.id,
|
emojiId: emoji.id,
|
||||||
b: newUser.id,
|
userId: newUser.id,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { config } from "config-manager";
|
// import { config } from "config-manager";
|
||||||
import type { Config } from "drizzle-kit";
|
import type { Config } from "drizzle-kit";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
@ -6,12 +6,19 @@ export default {
|
||||||
out: "./drizzle",
|
out: "./drizzle",
|
||||||
schema: "./drizzle/schema.ts",
|
schema: "./drizzle/schema.ts",
|
||||||
dbCredentials: {
|
dbCredentials: {
|
||||||
|
host: "localhost",
|
||||||
|
port: 40003,
|
||||||
|
user: "lysand",
|
||||||
|
password: "lysand",
|
||||||
|
database: "lysand",
|
||||||
|
},
|
||||||
|
/* dbCredentials: {
|
||||||
host: config.database.host,
|
host: config.database.host,
|
||||||
port: Number(config.database.port),
|
port: Number(config.database.port),
|
||||||
user: config.database.username,
|
user: config.database.username,
|
||||||
password: config.database.password,
|
password: config.database.password,
|
||||||
database: config.database.database,
|
database: config.database.database,
|
||||||
},
|
}, */
|
||||||
// Print all statements
|
// Print all statements
|
||||||
verbose: true,
|
verbose: true,
|
||||||
// Always ask for confirmation
|
// Always ask for confirmation
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
-- Current sql file was generated after introspecting the database
|
-- Current sql file was generated after introspecting the database
|
||||||
-- If you want to run this migration please uncomment this code before executing migrations
|
-- If you want to run this migration please uncomment this code before executing migrations
|
||||||
/*
|
|
||||||
CREATE TABLE IF NOT EXISTS "_prisma_migrations" (
|
CREATE TABLE IF NOT EXISTS "_prisma_migrations" (
|
||||||
"id" varchar(36) PRIMARY KEY NOT NULL,
|
"id" varchar(36) PRIMARY KEY NOT NULL,
|
||||||
"checksum" varchar(64) NOT NULL,
|
"checksum" varchar(64) NOT NULL,
|
||||||
|
|
@ -458,5 +457,3 @@ DO $$ BEGIN
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
WHEN duplicate_object THEN null;
|
WHEN duplicate_object THEN null;
|
||||||
END $$;
|
END $$;
|
||||||
|
|
||||||
*/
|
|
||||||
292
drizzle/0001_salty_night_thrasher.sql
Normal file
292
drizzle/0001_salty_night_thrasher.sql
Normal file
|
|
@ -0,0 +1,292 @@
|
||||||
|
DROP TABLE "_prisma_migrations";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Emoji" DROP CONSTRAINT "Emoji_instanceId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Like" DROP CONSTRAINT "Like_likerId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Like" DROP CONSTRAINT "Like_likedId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "LysandObject" DROP CONSTRAINT "LysandObject_authorId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" DROP CONSTRAINT "Relationship_ownerId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" DROP CONSTRAINT "Relationship_subjectId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Token" DROP CONSTRAINT "Token_userId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Token" DROP CONSTRAINT "Token_applicationId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "_EmojiToUser" DROP CONSTRAINT "_EmojiToUser_A_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "_EmojiToUser" DROP CONSTRAINT "_EmojiToUser_B_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "_EmojiToStatus" DROP CONSTRAINT "_EmojiToStatus_A_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "_EmojiToStatus" DROP CONSTRAINT "_EmojiToStatus_B_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "_StatusToUser" DROP CONSTRAINT "_StatusToUser_A_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "_StatusToUser" DROP CONSTRAINT "_StatusToUser_B_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "_UserPinnedNotes" DROP CONSTRAINT "_UserPinnedNotes_A_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "_UserPinnedNotes" DROP CONSTRAINT "_UserPinnedNotes_B_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Attachment" DROP CONSTRAINT "Attachment_statusId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Notification" DROP CONSTRAINT "Notification_notifiedId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Notification" DROP CONSTRAINT "Notification_accountId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Notification" DROP CONSTRAINT "Notification_statusId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" DROP CONSTRAINT "Status_authorId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" DROP CONSTRAINT "Status_instanceId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" DROP CONSTRAINT "Status_applicationId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" DROP CONSTRAINT "Status_reblogId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "OpenIdAccount" DROP CONSTRAINT "OpenIdAccount_userId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" DROP CONSTRAINT "User_instanceId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "OpenIdLoginFlow" DROP CONSTRAINT "OpenIdLoginFlow_applicationId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Flag" DROP CONSTRAINT "Flag_flaggeStatusId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Flag" DROP CONSTRAINT "Flag_flaggedUserId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "ModNote" DROP CONSTRAINT "ModNote_notedStatusId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "ModNote" DROP CONSTRAINT "ModNote_notedUserId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "ModNote" DROP CONSTRAINT "ModNote_modId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "ModTag" DROP CONSTRAINT "ModTag_taggedStatusId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "ModTag" DROP CONSTRAINT "ModTag_taggedUserId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "ModTag" DROP CONSTRAINT "ModTag_modId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Like" ALTER COLUMN "createdAt" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "LysandObject" ALTER COLUMN "created_at" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" ALTER COLUMN "createdAt" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "Token" ALTER COLUMN "created_at" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "Notification" ALTER COLUMN "createdAt" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" ALTER COLUMN "createdAt" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" ALTER COLUMN "createdAt" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" ALTER COLUMN "updatedAt" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" ALTER COLUMN "sanctions" DROP DEFAULT;--> statement-breakpoint
|
||||||
|
ALTER TABLE "Flag" ALTER COLUMN "createdAt" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "ModNote" ALTER COLUMN "createdAt" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "ModTag" ALTER COLUMN "createdAt" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "Emoji" ADD CONSTRAINT "Emoji_instanceId_Instance_id_fk" FOREIGN KEY ("instanceId") REFERENCES "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_User_id_fk" FOREIGN KEY ("likerId") REFERENCES "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_Status_id_fk" FOREIGN KEY ("likedId") REFERENCES "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 "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_User_id_fk" FOREIGN KEY ("ownerId") REFERENCES "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_User_id_fk" FOREIGN KEY ("subjectId") REFERENCES "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_User_id_fk" FOREIGN KEY ("userId") REFERENCES "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_Application_id_fk" FOREIGN KEY ("applicationId") REFERENCES "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_Emoji_id_fk" FOREIGN KEY ("A") REFERENCES "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_User_id_fk" FOREIGN KEY ("B") REFERENCES "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_Emoji_id_fk" FOREIGN KEY ("A") REFERENCES "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_Status_id_fk" FOREIGN KEY ("B") REFERENCES "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_Status_id_fk" FOREIGN KEY ("A") REFERENCES "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_User_id_fk" FOREIGN KEY ("B") REFERENCES "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_Status_id_fk" FOREIGN KEY ("A") REFERENCES "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_User_id_fk" FOREIGN KEY ("B") REFERENCES "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_Status_id_fk" FOREIGN KEY ("statusId") REFERENCES "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_User_id_fk" FOREIGN KEY ("notifiedId") REFERENCES "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_User_id_fk" FOREIGN KEY ("accountId") REFERENCES "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_Status_id_fk" FOREIGN KEY ("statusId") REFERENCES "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_User_id_fk" FOREIGN KEY ("authorId") REFERENCES "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_instanceId_Instance_id_fk" FOREIGN KEY ("instanceId") REFERENCES "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_Application_id_fk" FOREIGN KEY ("applicationId") REFERENCES "Application"("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_reblogId_fkey" FOREIGN KEY ("reblogId") REFERENCES "Status"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
|
--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "OpenIdAccount" ADD CONSTRAINT "OpenIdAccount_userId_User_id_fk" FOREIGN KEY ("userId") REFERENCES "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_Instance_id_fk" FOREIGN KEY ("instanceId") REFERENCES "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_Application_id_fk" FOREIGN KEY ("applicationId") REFERENCES "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_Status_id_fk" FOREIGN KEY ("flaggeStatusId") REFERENCES "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_User_id_fk" FOREIGN KEY ("flaggedUserId") REFERENCES "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_Status_id_fk" FOREIGN KEY ("notedStatusId") REFERENCES "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_User_id_fk" FOREIGN KEY ("notedUserId") REFERENCES "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_User_id_fk" FOREIGN KEY ("modId") REFERENCES "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_Status_id_fk" FOREIGN KEY ("taggedStatusId") REFERENCES "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_User_id_fk" FOREIGN KEY ("taggedUserId") REFERENCES "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_User_id_fk" FOREIGN KEY ("modId") REFERENCES "User"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
20
drizzle/0002_stiff_ares.sql
Normal file
20
drizzle/0002_stiff_ares.sql
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
ALTER TABLE "_StatusToUser" RENAME TO "StatusToMentions";--> statement-breakpoint
|
||||||
|
ALTER TABLE "StatusToMentions" DROP CONSTRAINT "_StatusToUser_A_Status_id_fk";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "StatusToMentions" DROP CONSTRAINT "_StatusToUser_B_User_id_fk";
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "_StatusToUser_AB_unique";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "_StatusToUser_B_index";--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "StatusToMentions_A_B_index" ON "StatusToMentions" ("A","B");--> statement-breakpoint
|
||||||
|
CREATE INDEX IF NOT EXISTS "StatusToMentions_B_index" ON "StatusToMentions" ("B");--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "StatusToMentions" ADD CONSTRAINT "StatusToMentions_A_Status_id_fk" FOREIGN KEY ("A") REFERENCES "Status"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
|
--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "StatusToMentions" ADD CONSTRAINT "StatusToMentions_B_User_id_fk" FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
21
drizzle/0003_spicy_arachne.sql
Normal file
21
drizzle/0003_spicy_arachne.sql
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
ALTER TABLE "StatusToMentions" RENAME COLUMN "A" TO "statusId";--> statement-breakpoint
|
||||||
|
ALTER TABLE "StatusToMentions" RENAME COLUMN "B" TO "userId";--> statement-breakpoint
|
||||||
|
ALTER TABLE "StatusToMentions" DROP CONSTRAINT "StatusToMentions_A_Status_id_fk";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "StatusToMentions" DROP CONSTRAINT "StatusToMentions_B_User_id_fk";
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "StatusToMentions_A_B_index";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "StatusToMentions_B_index";--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "StatusToMentions_statusId_userId_index" ON "StatusToMentions" ("statusId","userId");--> statement-breakpoint
|
||||||
|
CREATE INDEX IF NOT EXISTS "StatusToMentions_userId_index" ON "StatusToMentions" ("userId");--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "StatusToMentions" ADD CONSTRAINT "StatusToMentions_statusId_Status_id_fk" FOREIGN KEY ("statusId") REFERENCES "Status"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
|
--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "StatusToMentions" ADD CONSTRAINT "StatusToMentions_userId_User_id_fk" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
57
drizzle/0004_burly_lockjaw.sql
Normal file
57
drizzle/0004_burly_lockjaw.sql
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
ALTER TABLE "_EmojiToStatus" RENAME TO "EmojiToStatus";--> statement-breakpoint
|
||||||
|
ALTER TABLE "_UserPinnedNotes" RENAME TO "UserToPinnedNotes";--> statement-breakpoint
|
||||||
|
ALTER TABLE "EmojiToStatus" RENAME COLUMN "A" TO "emojiId";--> statement-breakpoint
|
||||||
|
ALTER TABLE "EmojiToStatus" RENAME COLUMN "B" TO "statusId";--> statement-breakpoint
|
||||||
|
ALTER TABLE "UserToPinnedNotes" RENAME COLUMN "A" TO "userId";--> statement-breakpoint
|
||||||
|
ALTER TABLE "UserToPinnedNotes" RENAME COLUMN "B" TO "statusId";--> statement-breakpoint
|
||||||
|
ALTER TABLE "LysandObject" DROP CONSTRAINT "LysandObject_authorId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "EmojiToStatus" DROP CONSTRAINT "_EmojiToStatus_A_Emoji_id_fk";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "EmojiToStatus" DROP CONSTRAINT "_EmojiToStatus_B_Status_id_fk";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "UserToPinnedNotes" DROP CONSTRAINT "_UserPinnedNotes_A_Status_id_fk";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "UserToPinnedNotes" DROP CONSTRAINT "_UserPinnedNotes_B_User_id_fk";
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "LysandObject_remote_id_key";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "LysandObject_uri_key";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "_EmojiToStatus_AB_unique";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "_EmojiToStatus_B_index";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "_UserPinnedNotes_AB_unique";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "_UserPinnedNotes_B_index";--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "LysandObject_remote_id_index" ON "LysandObject" ("remote_id");--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "LysandObject_uri_index" ON "LysandObject" ("uri");--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "EmojiToStatus_emojiId_statusId_index" ON "EmojiToStatus" ("emojiId","statusId");--> statement-breakpoint
|
||||||
|
CREATE INDEX IF NOT EXISTS "EmojiToStatus_statusId_index" ON "EmojiToStatus" ("statusId");--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "UserToPinnedNotes_userId_statusId_index" ON "UserToPinnedNotes" ("userId","statusId");--> statement-breakpoint
|
||||||
|
CREATE INDEX IF NOT EXISTS "UserToPinnedNotes_statusId_index" ON "UserToPinnedNotes" ("statusId");--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "LysandObject" ADD CONSTRAINT "LysandObject_authorId_LysandObject_id_fk" FOREIGN KEY ("authorId") REFERENCES "LysandObject"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
|
--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "EmojiToStatus" ADD CONSTRAINT "EmojiToStatus_emojiId_Emoji_id_fk" FOREIGN KEY ("emojiId") REFERENCES "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_statusId_Status_id_fk" FOREIGN KEY ("statusId") REFERENCES "Status"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
|
--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "UserToPinnedNotes" ADD CONSTRAINT "UserToPinnedNotes_userId_Status_id_fk" FOREIGN KEY ("userId") REFERENCES "Status"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
|
--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "UserToPinnedNotes" ADD CONSTRAINT "UserToPinnedNotes_statusId_User_id_fk" FOREIGN KEY ("statusId") REFERENCES "User"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
40
drizzle/0005_sleepy_puma.sql
Normal file
40
drizzle/0005_sleepy_puma.sql
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
ALTER TABLE "Instance" RENAME COLUMN "disableAutomoderation" TO "disable_automoderation";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" RENAME COLUMN "showingReblogs" TO "showing_reblogs";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" RENAME COLUMN "followedBy" TO "followed_by";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" RENAME COLUMN "blockedBy" TO "blocked_by";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" RENAME COLUMN "mutingNotifications" TO "muting_notifications";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" RENAME COLUMN "domainBlocking" TO "domain_blocking";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" RENAME COLUMN "createdAt" TO "created_at";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" RENAME COLUMN "updatedAt" TO "updated_at";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" RENAME COLUMN "contentType" TO "content_type";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" RENAME COLUMN "spoilerText" TO "spoiler_text";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" RENAME COLUMN "contentSource" TO "content_source";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" DROP CONSTRAINT "Status_reblogId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" DROP CONSTRAINT "Status_inReplyToPostId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" DROP CONSTRAINT "Status_quotingPostId_fkey";
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "Application_client_id_key";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "Status_uri_key";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Relationship" ALTER COLUMN "updated_at" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
ALTER TABLE "Status" ALTER COLUMN "updatedAt" SET DEFAULT now();--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "Application_client_id_index" ON "Application" ("client_id");--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "Status_uri_index" ON "Status" ("uri");--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "Status" ADD CONSTRAINT "Status_reblogId_Status_id_fk" FOREIGN KEY ("reblogId") REFERENCES "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_Status_id_fk" FOREIGN KEY ("inReplyToPostId") REFERENCES "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_Status_id_fk" FOREIGN KEY ("quotingPostId") REFERENCES "Status"("id") ON DELETE set null ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
46
drizzle/0006_messy_network.sql
Normal file
46
drizzle/0006_messy_network.sql
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
ALTER TABLE "_EmojiToUser" RENAME TO "EmojiToUser";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Flag" RENAME COLUMN "flagType" TO "flag_type";--> statement-breakpoint
|
||||||
|
ALTER TABLE "Flag" RENAME COLUMN "createdAt" TO "created_at";--> statement-breakpoint
|
||||||
|
ALTER TABLE "ModNote" RENAME COLUMN "createdAt" TO "created_at";--> statement-breakpoint
|
||||||
|
ALTER TABLE "ModTag" RENAME COLUMN "createdAt" TO "created_at";--> statement-breakpoint
|
||||||
|
ALTER TABLE "OpenIdAccount" RENAME COLUMN "serverId" TO "server_id";--> statement-breakpoint
|
||||||
|
ALTER TABLE "OpenIdAccount" RENAME COLUMN "issuerId" TO "issuer_id";--> statement-breakpoint
|
||||||
|
ALTER TABLE "OpenIdLoginFlow" RENAME COLUMN "codeVerifier" TO "code_verifier";--> statement-breakpoint
|
||||||
|
ALTER TABLE "OpenIdLoginFlow" RENAME COLUMN "issuerId" TO "issuer_id";--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" RENAME COLUMN "displayName" TO "display_name";--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" RENAME COLUMN "isAdmin" TO "is_admin";--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" RENAME COLUMN "createdAt" TO "created_at";--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" RENAME COLUMN "updatedAt" TO "updated_at";--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" RENAME COLUMN "isBot" TO "is_bot";--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" RENAME COLUMN "isLocked" TO "is_locked";--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" RENAME COLUMN "isDiscoverable" TO "is_discoverable";--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" RENAME COLUMN "publicKey" TO "public_key";--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" RENAME COLUMN "privateKey" TO "private_key";--> statement-breakpoint
|
||||||
|
ALTER TABLE "User" RENAME COLUMN "disableAutomoderation" TO "disable_automoderation";--> statement-breakpoint
|
||||||
|
ALTER TABLE "EmojiToUser" RENAME COLUMN "A" TO "emojiId";--> statement-breakpoint
|
||||||
|
ALTER TABLE "EmojiToUser" RENAME COLUMN "B" TO "userId";--> statement-breakpoint
|
||||||
|
ALTER TABLE "EmojiToUser" DROP CONSTRAINT "_EmojiToUser_A_Emoji_id_fk";
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "EmojiToUser" DROP CONSTRAINT "_EmojiToUser_B_User_id_fk";
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "User_uri_key";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "User_username_key";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "User_email_key";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "_EmojiToUser_AB_unique";--> statement-breakpoint
|
||||||
|
DROP INDEX IF EXISTS "_EmojiToUser_B_index";--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "User_uri_index" ON "User" ("uri");--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "User_username_index" ON "User" ("username");--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "User_email_index" ON "User" ("email");--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "EmojiToUser_emojiId_userId_index" ON "EmojiToUser" ("emojiId","userId");--> statement-breakpoint
|
||||||
|
CREATE INDEX IF NOT EXISTS "EmojiToUser_userId_index" ON "EmojiToUser" ("userId");--> statement-breakpoint
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "EmojiToUser" ADD CONSTRAINT "EmojiToUser_emojiId_Emoji_id_fk" FOREIGN KEY ("emojiId") REFERENCES "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_userId_User_id_fk" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE cascade ON UPDATE cascade;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
1588
drizzle/meta/0001_snapshot.json
Normal file
1588
drizzle/meta/0001_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
1588
drizzle/meta/0002_snapshot.json
Normal file
1588
drizzle/meta/0002_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
1588
drizzle/meta/0003_snapshot.json
Normal file
1588
drizzle/meta/0003_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
1588
drizzle/meta/0004_snapshot.json
Normal file
1588
drizzle/meta/0004_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
1590
drizzle/meta/0005_snapshot.json
Normal file
1590
drizzle/meta/0005_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
1590
drizzle/meta/0006_snapshot.json
Normal file
1590
drizzle/meta/0006_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -8,6 +8,48 @@
|
||||||
"when": 1712805159664,
|
"when": 1712805159664,
|
||||||
"tag": "0000_illegal_living_lightning",
|
"tag": "0000_illegal_living_lightning",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 1,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1713055774123,
|
||||||
|
"tag": "0001_salty_night_thrasher",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 2,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1713056370431,
|
||||||
|
"tag": "0002_stiff_ares",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 3,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1713056528340,
|
||||||
|
"tag": "0003_spicy_arachne",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 4,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1713056712218,
|
||||||
|
"tag": "0004_burly_lockjaw",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 5,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1713056917973,
|
||||||
|
"tag": "0005_sleepy_puma",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 6,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1713057159867,
|
||||||
|
"tag": "0006_messy_network",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,14 +60,11 @@ export const lysandObject = pgTable(
|
||||||
},
|
},
|
||||||
(table) => {
|
(table) => {
|
||||||
return {
|
return {
|
||||||
remoteIdKey: uniqueIndex("LysandObject_remote_id_key").on(
|
remoteIdKey: uniqueIndex().on(table.remoteId),
|
||||||
table.remoteId,
|
uriKey: uniqueIndex().on(table.uri),
|
||||||
),
|
|
||||||
uriKey: uniqueIndex("LysandObject_uri_key").on(table.uri),
|
|
||||||
lysandObjectAuthorIdFkey: foreignKey({
|
lysandObjectAuthorIdFkey: foreignKey({
|
||||||
columns: [table.authorId],
|
columns: [table.authorId],
|
||||||
foreignColumns: [table.id],
|
foreignColumns: [table.id],
|
||||||
name: "LysandObject_authorId_fkey",
|
|
||||||
})
|
})
|
||||||
.onUpdate("cascade")
|
.onUpdate("cascade")
|
||||||
.onDelete("cascade"),
|
.onDelete("cascade"),
|
||||||
|
|
@ -90,25 +87,27 @@ export const relationship = pgTable("Relationship", {
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
following: boolean("following").notNull(),
|
following: boolean("following").notNull(),
|
||||||
showingReblogs: boolean("showingReblogs").notNull(),
|
showingReblogs: boolean("showing_reblogs").notNull(),
|
||||||
notifying: boolean("notifying").notNull(),
|
notifying: boolean("notifying").notNull(),
|
||||||
followedBy: boolean("followedBy").notNull(),
|
followedBy: boolean("followed_by").notNull(),
|
||||||
blocking: boolean("blocking").notNull(),
|
blocking: boolean("blocking").notNull(),
|
||||||
blockedBy: boolean("blockedBy").notNull(),
|
blockedBy: boolean("blocked_by").notNull(),
|
||||||
muting: boolean("muting").notNull(),
|
muting: boolean("muting").notNull(),
|
||||||
mutingNotifications: boolean("mutingNotifications").notNull(),
|
mutingNotifications: boolean("muting_notifications").notNull(),
|
||||||
requested: boolean("requested").notNull(),
|
requested: boolean("requested").notNull(),
|
||||||
domainBlocking: boolean("domainBlocking").notNull(),
|
domainBlocking: boolean("domain_blocking").notNull(),
|
||||||
endorsed: boolean("endorsed").notNull(),
|
endorsed: boolean("endorsed").notNull(),
|
||||||
languages: text("languages").array(),
|
languages: text("languages").array(),
|
||||||
note: text("note").notNull(),
|
note: text("note").notNull(),
|
||||||
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
||||||
.defaultNow()
|
.defaultNow()
|
||||||
.notNull(),
|
.notNull(),
|
||||||
updatedAt: timestamp("updatedAt", {
|
updatedAt: timestamp("updated_at", {
|
||||||
precision: 3,
|
precision: 3,
|
||||||
mode: "string",
|
mode: "string",
|
||||||
}).notNull(),
|
})
|
||||||
|
.defaultNow()
|
||||||
|
.notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const application = pgTable(
|
export const application = pgTable(
|
||||||
|
|
@ -125,9 +124,7 @@ export const application = pgTable(
|
||||||
},
|
},
|
||||||
(table) => {
|
(table) => {
|
||||||
return {
|
return {
|
||||||
clientIdKey: uniqueIndex("Application_client_id_key").on(
|
clientIdKey: uniqueIndex().on(table.clientId),
|
||||||
table.clientId,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -217,10 +214,12 @@ export const status = pgTable(
|
||||||
updatedAt: timestamp("updatedAt", {
|
updatedAt: timestamp("updatedAt", {
|
||||||
precision: 3,
|
precision: 3,
|
||||||
mode: "string",
|
mode: "string",
|
||||||
}).notNull(),
|
})
|
||||||
|
.defaultNow()
|
||||||
|
.notNull(),
|
||||||
reblogId: uuid("reblogId"),
|
reblogId: uuid("reblogId"),
|
||||||
content: text("content").default("").notNull(),
|
content: text("content").default("").notNull(),
|
||||||
contentType: text("contentType").default("text/plain").notNull(),
|
contentType: text("content_type").default("text/plain").notNull(),
|
||||||
visibility: text("visibility").notNull(),
|
visibility: text("visibility").notNull(),
|
||||||
inReplyToPostId: uuid("inReplyToPostId"),
|
inReplyToPostId: uuid("inReplyToPostId"),
|
||||||
quotingPostId: uuid("quotingPostId"),
|
quotingPostId: uuid("quotingPostId"),
|
||||||
|
|
@ -229,34 +228,31 @@ export const status = pgTable(
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
sensitive: boolean("sensitive").notNull(),
|
sensitive: boolean("sensitive").notNull(),
|
||||||
spoilerText: text("spoilerText").default("").notNull(),
|
spoilerText: text("spoiler_text").default("").notNull(),
|
||||||
applicationId: uuid("applicationId").references(() => application.id, {
|
applicationId: uuid("applicationId").references(() => application.id, {
|
||||||
onDelete: "set null",
|
onDelete: "set null",
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
contentSource: text("contentSource").default("").notNull(),
|
contentSource: text("content_source").default("").notNull(),
|
||||||
},
|
},
|
||||||
(table) => {
|
(table) => {
|
||||||
return {
|
return {
|
||||||
uriKey: uniqueIndex("Status_uri_key").on(table.uri),
|
uriKey: uniqueIndex().on(table.uri),
|
||||||
statusReblogIdFkey: foreignKey({
|
statusReblogIdFkey: foreignKey({
|
||||||
columns: [table.reblogId],
|
columns: [table.reblogId],
|
||||||
foreignColumns: [table.id],
|
foreignColumns: [table.id],
|
||||||
name: "Status_reblogId_fkey",
|
|
||||||
})
|
})
|
||||||
.onUpdate("cascade")
|
.onUpdate("cascade")
|
||||||
.onDelete("cascade"),
|
.onDelete("cascade"),
|
||||||
statusInReplyToPostIdFkey: foreignKey({
|
statusInReplyToPostIdFkey: foreignKey({
|
||||||
columns: [table.inReplyToPostId],
|
columns: [table.inReplyToPostId],
|
||||||
foreignColumns: [table.id],
|
foreignColumns: [table.id],
|
||||||
name: "Status_inReplyToPostId_fkey",
|
|
||||||
})
|
})
|
||||||
.onUpdate("cascade")
|
.onUpdate("cascade")
|
||||||
.onDelete("set null"),
|
.onDelete("set null"),
|
||||||
statusQuotingPostIdFkey: foreignKey({
|
statusQuotingPostIdFkey: foreignKey({
|
||||||
columns: [table.quotingPostId],
|
columns: [table.quotingPostId],
|
||||||
foreignColumns: [table.id],
|
foreignColumns: [table.id],
|
||||||
name: "Status_quotingPostId_fkey",
|
|
||||||
})
|
})
|
||||||
.onUpdate("cascade")
|
.onUpdate("cascade")
|
||||||
.onDelete("set null"),
|
.onDelete("set null"),
|
||||||
|
|
@ -270,7 +266,7 @@ export const instance = pgTable("Instance", {
|
||||||
name: text("name").notNull(),
|
name: text("name").notNull(),
|
||||||
version: text("version").notNull(),
|
version: text("version").notNull(),
|
||||||
logo: jsonb("logo").notNull(),
|
logo: jsonb("logo").notNull(),
|
||||||
disableAutomoderation: boolean("disableAutomoderation")
|
disableAutomoderation: boolean("disable_automoderation")
|
||||||
.default(false)
|
.default(false)
|
||||||
.notNull(),
|
.notNull(),
|
||||||
});
|
});
|
||||||
|
|
@ -281,8 +277,8 @@ export const openIdAccount = pgTable("OpenIdAccount", {
|
||||||
onDelete: "set null",
|
onDelete: "set null",
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
serverId: text("serverId").notNull(),
|
serverId: text("server_id").notNull(),
|
||||||
issuerId: text("issuerId").notNull(),
|
issuerId: text("issuer_id").notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const user = pgTable(
|
export const user = pgTable(
|
||||||
|
|
@ -291,55 +287,55 @@ export const user = pgTable(
|
||||||
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
||||||
uri: text("uri"),
|
uri: text("uri"),
|
||||||
username: text("username").notNull(),
|
username: text("username").notNull(),
|
||||||
displayName: text("displayName").notNull(),
|
displayName: text("display_name").notNull(),
|
||||||
password: text("password"),
|
password: text("password"),
|
||||||
email: text("email"),
|
email: text("email"),
|
||||||
note: text("note").default("").notNull(),
|
note: text("note").default("").notNull(),
|
||||||
isAdmin: boolean("isAdmin").default(false).notNull(),
|
isAdmin: boolean("is_admin").default(false).notNull(),
|
||||||
endpoints: jsonb("endpoints"),
|
endpoints: jsonb("endpoints"),
|
||||||
source: jsonb("source").notNull(),
|
source: jsonb("source").notNull(),
|
||||||
avatar: text("avatar").notNull(),
|
avatar: text("avatar").notNull(),
|
||||||
header: text("header").notNull(),
|
header: text("header").notNull(),
|
||||||
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
||||||
.defaultNow()
|
.defaultNow()
|
||||||
.notNull(),
|
.notNull(),
|
||||||
updatedAt: timestamp("updatedAt", {
|
updatedAt: timestamp("updated_at", {
|
||||||
precision: 3,
|
precision: 3,
|
||||||
mode: "string",
|
mode: "string",
|
||||||
})
|
})
|
||||||
.defaultNow()
|
.defaultNow()
|
||||||
.notNull(),
|
.notNull(),
|
||||||
isBot: boolean("isBot").default(false).notNull(),
|
isBot: boolean("is_bot").default(false).notNull(),
|
||||||
isLocked: boolean("isLocked").default(false).notNull(),
|
isLocked: boolean("is_locked").default(false).notNull(),
|
||||||
isDiscoverable: boolean("isDiscoverable").default(false).notNull(),
|
isDiscoverable: boolean("is_discoverable").default(false).notNull(),
|
||||||
sanctions: text("sanctions").default("RRAY[").array(),
|
sanctions: text("sanctions").default("RRAY[").array(),
|
||||||
publicKey: text("publicKey").notNull(),
|
publicKey: text("public_key").notNull(),
|
||||||
privateKey: text("privateKey"),
|
privateKey: text("private_key"),
|
||||||
instanceId: uuid("instanceId").references(() => instance.id, {
|
instanceId: uuid("instanceId").references(() => instance.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
disableAutomoderation: boolean("disableAutomoderation")
|
disableAutomoderation: boolean("disable_automoderation")
|
||||||
.default(false)
|
.default(false)
|
||||||
.notNull(),
|
.notNull(),
|
||||||
},
|
},
|
||||||
(table) => {
|
(table) => {
|
||||||
return {
|
return {
|
||||||
uriKey: uniqueIndex("User_uri_key").on(table.uri),
|
uriKey: uniqueIndex().on(table.uri),
|
||||||
usernameKey: uniqueIndex("User_username_key").on(table.username),
|
usernameKey: uniqueIndex().on(table.username),
|
||||||
emailKey: uniqueIndex("User_email_key").on(table.email),
|
emailKey: uniqueIndex().on(table.email),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export const openIdLoginFlow = pgTable("OpenIdLoginFlow", {
|
export const openIdLoginFlow = pgTable("OpenIdLoginFlow", {
|
||||||
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
||||||
codeVerifier: text("codeVerifier").notNull(),
|
codeVerifier: text("code_verifier").notNull(),
|
||||||
applicationId: uuid("applicationId").references(() => application.id, {
|
applicationId: uuid("applicationId").references(() => application.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
issuerId: text("issuerId").notNull(),
|
issuerId: text("issuer_id").notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const openIdLoginFlowRelations = relations(
|
export const openIdLoginFlowRelations = relations(
|
||||||
|
|
@ -354,8 +350,8 @@ export const openIdLoginFlowRelations = relations(
|
||||||
|
|
||||||
export const flag = pgTable("Flag", {
|
export const flag = pgTable("Flag", {
|
||||||
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
||||||
flagType: text("flagType").default("other").notNull(),
|
flagType: text("flag_type").default("other").notNull(),
|
||||||
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
||||||
.defaultNow()
|
.defaultNow()
|
||||||
.notNull(),
|
.notNull(),
|
||||||
flaggeStatusId: uuid("flaggeStatusId").references(() => status.id, {
|
flaggeStatusId: uuid("flaggeStatusId").references(() => status.id, {
|
||||||
|
|
@ -385,7 +381,7 @@ export const modNote = pgTable("ModNote", {
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
note: text("note").notNull(),
|
note: text("note").notNull(),
|
||||||
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
||||||
.defaultNow()
|
.defaultNow()
|
||||||
.notNull(),
|
.notNull(),
|
||||||
});
|
});
|
||||||
|
|
@ -407,21 +403,21 @@ export const modTag = pgTable("ModTag", {
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
tag: text("tag").notNull(),
|
tag: text("tag").notNull(),
|
||||||
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
||||||
.defaultNow()
|
.defaultNow()
|
||||||
.notNull(),
|
.notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const emojiToUser = pgTable(
|
export const emojiToUser = pgTable(
|
||||||
"_EmojiToUser",
|
"EmojiToUser",
|
||||||
{
|
{
|
||||||
a: uuid("A")
|
emojiId: uuid("emojiId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => emoji.id, {
|
.references(() => emoji.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
b: uuid("B")
|
userId: uuid("userId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => user.id, {
|
.references(() => user.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
|
|
@ -430,36 +426,33 @@ export const emojiToUser = pgTable(
|
||||||
},
|
},
|
||||||
(table) => {
|
(table) => {
|
||||||
return {
|
return {
|
||||||
abUnique: uniqueIndex("_EmojiToUser_AB_unique").on(
|
abUnique: uniqueIndex().on(table.emojiId, table.userId),
|
||||||
table.a,
|
bIdx: index().on(table.userId),
|
||||||
table.b,
|
|
||||||
),
|
|
||||||
bIdx: index().on(table.b),
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export const emojiToUserRelations = relations(emojiToUser, ({ one }) => ({
|
export const emojiToUserRelations = relations(emojiToUser, ({ one }) => ({
|
||||||
emoji: one(emoji, {
|
emoji: one(emoji, {
|
||||||
fields: [emojiToUser.a],
|
fields: [emojiToUser.emojiId],
|
||||||
references: [emoji.id],
|
references: [emoji.id],
|
||||||
}),
|
}),
|
||||||
user: one(user, {
|
user: one(user, {
|
||||||
fields: [emojiToUser.b],
|
fields: [emojiToUser.userId],
|
||||||
references: [user.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const emojiToStatus = pgTable(
|
export const emojiToStatus = pgTable(
|
||||||
"_EmojiToStatus",
|
"EmojiToStatus",
|
||||||
{
|
{
|
||||||
a: uuid("A")
|
emojiId: uuid("emojiId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => emoji.id, {
|
.references(() => emoji.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
b: uuid("B")
|
statusId: uuid("statusId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => status.id, {
|
.references(() => status.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
|
|
@ -468,25 +461,22 @@ export const emojiToStatus = pgTable(
|
||||||
},
|
},
|
||||||
(table) => {
|
(table) => {
|
||||||
return {
|
return {
|
||||||
abUnique: uniqueIndex("_EmojiToStatus_AB_unique").on(
|
abUnique: uniqueIndex().on(table.emojiId, table.statusId),
|
||||||
table.a,
|
bIdx: index().on(table.statusId),
|
||||||
table.b,
|
|
||||||
),
|
|
||||||
bIdx: index().on(table.b),
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export const statusToUser = pgTable(
|
export const statusToMentions = pgTable(
|
||||||
"_StatusToUser",
|
"StatusToMentions",
|
||||||
{
|
{
|
||||||
a: uuid("A")
|
statusId: uuid("statusId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => status.id, {
|
.references(() => status.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
b: uuid("B")
|
userId: uuid("userId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => user.id, {
|
.references(() => user.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
|
|
@ -495,25 +485,22 @@ export const statusToUser = pgTable(
|
||||||
},
|
},
|
||||||
(table) => {
|
(table) => {
|
||||||
return {
|
return {
|
||||||
abUnique: uniqueIndex("_StatusToUser_AB_unique").on(
|
abUnique: uniqueIndex().on(table.statusId, table.userId),
|
||||||
table.a,
|
bIdx: index().on(table.userId),
|
||||||
table.b,
|
|
||||||
),
|
|
||||||
bIdx: index().on(table.b),
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export const userPinnedNotes = pgTable(
|
export const userPinnedNotes = pgTable(
|
||||||
"_UserPinnedNotes",
|
"UserToPinnedNotes",
|
||||||
{
|
{
|
||||||
a: uuid("A")
|
userId: uuid("userId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => status.id, {
|
.references(() => status.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
b: uuid("B")
|
statusId: uuid("statusId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => user.id, {
|
.references(() => user.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
|
|
@ -522,11 +509,8 @@ export const userPinnedNotes = pgTable(
|
||||||
},
|
},
|
||||||
(table) => {
|
(table) => {
|
||||||
return {
|
return {
|
||||||
abUnique: uniqueIndex("_UserPinnedNotes_AB_unique").on(
|
abUnique: uniqueIndex().on(table.userId, table.statusId),
|
||||||
table.a,
|
bIdx: index().on(table.statusId),
|
||||||
table.b,
|
|
||||||
),
|
|
||||||
bIdx: index().on(table.b),
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -566,7 +550,7 @@ export const userRelations = relations(user, ({ many, one }) => ({
|
||||||
fields: [user.instanceId],
|
fields: [user.instanceId],
|
||||||
references: [instance.id],
|
references: [instance.id],
|
||||||
}),
|
}),
|
||||||
mentionedIn: many(statusToUser),
|
mentionedIn: many(statusToMentions),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const relationshipRelations = relations(relationship, ({ one }) => ({
|
export const relationshipRelations = relations(relationship, ({ one }) => ({
|
||||||
|
|
@ -593,13 +577,13 @@ export const tokenRelations = relations(token, ({ one }) => ({
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const statusToUserRelations = relations(statusToUser, ({ one }) => ({
|
export const statusToUserRelations = relations(statusToMentions, ({ one }) => ({
|
||||||
status: one(status, {
|
status: one(status, {
|
||||||
fields: [statusToUser.a],
|
fields: [statusToMentions.statusId],
|
||||||
references: [status.id],
|
references: [status.id],
|
||||||
}),
|
}),
|
||||||
user: one(user, {
|
user: one(user, {
|
||||||
fields: [statusToUser.b],
|
fields: [statusToMentions.userId],
|
||||||
references: [user.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
@ -608,11 +592,11 @@ export const userPinnedNotesRelations = relations(
|
||||||
userPinnedNotes,
|
userPinnedNotes,
|
||||||
({ one }) => ({
|
({ one }) => ({
|
||||||
status: one(status, {
|
status: one(status, {
|
||||||
fields: [userPinnedNotes.a],
|
fields: [userPinnedNotes.statusId],
|
||||||
references: [status.id],
|
references: [status.id],
|
||||||
}),
|
}),
|
||||||
user: one(user, {
|
user: one(user, {
|
||||||
fields: [userPinnedNotes.b],
|
fields: [userPinnedNotes.userId],
|
||||||
references: [user.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|
@ -626,7 +610,7 @@ export const statusRelations = relations(status, ({ many, one }) => ({
|
||||||
relationName: "StatusToAuthor",
|
relationName: "StatusToAuthor",
|
||||||
}),
|
}),
|
||||||
attachments: many(attachment),
|
attachments: many(attachment),
|
||||||
mentions: many(statusToUser),
|
mentions: many(statusToMentions),
|
||||||
reblog: one(status, {
|
reblog: one(status, {
|
||||||
fields: [status.reblogId],
|
fields: [status.reblogId],
|
||||||
references: [status.id],
|
references: [status.id],
|
||||||
|
|
@ -705,11 +689,11 @@ export const instanceRelations = relations(instance, ({ many }) => ({
|
||||||
|
|
||||||
export const emojiToStatusRelations = relations(emojiToStatus, ({ one }) => ({
|
export const emojiToStatusRelations = relations(emojiToStatus, ({ one }) => ({
|
||||||
emoji: one(emoji, {
|
emoji: one(emoji, {
|
||||||
fields: [emojiToStatus.a],
|
fields: [emojiToStatus.emojiId],
|
||||||
references: [emoji.id],
|
references: [emoji.id],
|
||||||
}),
|
}),
|
||||||
status: one(status, {
|
status: one(status, {
|
||||||
fields: [emojiToStatus.b],
|
fields: [emojiToStatus.statusId],
|
||||||
references: [status.id],
|
references: [status.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
4
index.ts
4
index.ts
|
|
@ -4,12 +4,16 @@ import { connectMeili } from "@meilisearch";
|
||||||
import { moduleIsEntry } from "@module";
|
import { moduleIsEntry } from "@module";
|
||||||
import { config } from "config-manager";
|
import { config } from "config-manager";
|
||||||
import { count, sql } from "drizzle-orm";
|
import { count, sql } from "drizzle-orm";
|
||||||
|
import { migrate } from "drizzle-orm/postgres-js/migrator";
|
||||||
import { LogLevel, LogManager, MultiLogManager } from "log-manager";
|
import { LogLevel, LogManager, MultiLogManager } from "log-manager";
|
||||||
import { db, client as pgClient } from "~drizzle/db";
|
import { db, client as pgClient } from "~drizzle/db";
|
||||||
import { status } from "~drizzle/schema";
|
import { status } from "~drizzle/schema";
|
||||||
import { createServer } from "~server";
|
import { createServer } from "~server";
|
||||||
|
|
||||||
await pgClient.connect();
|
await pgClient.connect();
|
||||||
|
await migrate(db, {
|
||||||
|
migrationsFolder: "./drizzle",
|
||||||
|
});
|
||||||
const timeAtStart = performance.now();
|
const timeAtStart = performance.now();
|
||||||
|
|
||||||
// Create requests file if it doesnt exist
|
// Create requests file if it doesnt exist
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ export default apiRoute<{
|
||||||
since_id ? gte(status.id, since_id) : undefined,
|
since_id ? gte(status.id, since_id) : undefined,
|
||||||
min_id ? gt(status.id, min_id) : undefined,
|
min_id ? gt(status.id, min_id) : undefined,
|
||||||
eq(status.authorId, id),
|
eq(status.authorId, id),
|
||||||
sql`EXISTS (SELECT 1 FROM "_UserPinnedNotes" WHERE "_UserPinnedNotes"."A" = ${status.id} AND "_UserPinnedNotes"."B" = ${user.id})`,
|
sql`EXISTS (SELECT 1 FROM "UserToPinnedNotes" WHERE "UserToPinnedNotes"."statusId" = ${status.id} AND "UserToPinnedNotes"."userId" = ${user.id})`,
|
||||||
only_media
|
only_media
|
||||||
? sql`EXISTS (SELECT 1 FROM "Attachment" WHERE "Attachment"."statusId" = ${status.id})`
|
? sql`EXISTS (SELECT 1 FROM "Attachment" WHERE "Attachment"."statusId" = ${status.id})`
|
||||||
: undefined,
|
: undefined,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { apiRoute, applyConfig } from "@api";
|
||||||
import { errorResponse, jsonResponse } from "@response";
|
import { errorResponse, jsonResponse } from "@response";
|
||||||
import { findFirstStatuses, statusToAPI } from "~database/entities/Status";
|
import { findFirstStatuses, statusToAPI } from "~database/entities/Status";
|
||||||
import { db } from "~drizzle/db";
|
import { db } from "~drizzle/db";
|
||||||
import { statusToUser } from "~drizzle/schema";
|
import { statusToMentions } from "~drizzle/schema";
|
||||||
|
|
||||||
export const meta = applyConfig({
|
export const meta = applyConfig({
|
||||||
allowedMethods: ["POST"],
|
allowedMethods: ["POST"],
|
||||||
|
|
@ -50,7 +50,7 @@ export default apiRoute(async (req, matchedRoute, extraData) => {
|
||||||
return errorResponse("Already pinned", 422);
|
return errorResponse("Already pinned", 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.insert(statusToUser).values({
|
await db.insert(statusToMentions).values({
|
||||||
a: foundStatus.id,
|
a: foundStatus.id,
|
||||||
b: user.id,
|
b: user.id,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { errorResponse, jsonResponse } from "@response";
|
||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq } from "drizzle-orm";
|
||||||
import { findFirstStatuses, statusToAPI } from "~database/entities/Status";
|
import { findFirstStatuses, statusToAPI } from "~database/entities/Status";
|
||||||
import { db } from "~drizzle/db";
|
import { db } from "~drizzle/db";
|
||||||
import { statusToUser } from "~drizzle/schema";
|
import { statusToMentions } from "~drizzle/schema";
|
||||||
|
|
||||||
export const meta = applyConfig({
|
export const meta = applyConfig({
|
||||||
allowedMethods: ["POST"],
|
allowedMethods: ["POST"],
|
||||||
|
|
@ -38,8 +38,13 @@ export default apiRoute(async (req, matchedRoute, extraData) => {
|
||||||
if (status.authorId !== user.id) return errorResponse("Unauthorized", 401);
|
if (status.authorId !== user.id) return errorResponse("Unauthorized", 401);
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.delete(statusToUser)
|
.delete(statusToMentions)
|
||||||
.where(and(eq(statusToUser.a, status.id), eq(statusToUser.b, user.id)));
|
.where(
|
||||||
|
and(
|
||||||
|
eq(statusToMentions.statusId, status.id),
|
||||||
|
eq(statusToMentions.userId, user.id),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
if (!status) return errorResponse("Record not found", 404);
|
if (!status) return errorResponse("Record not found", 404);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ export default apiRoute<{
|
||||||
), */
|
), */
|
||||||
// All statuses where the user is mentioned, using table _StatusToUser which has a: status.id and b: user.id
|
// All statuses where the user is mentioned, using table _StatusToUser which has a: status.id and b: user.id
|
||||||
// WHERE format (... = ...)
|
// WHERE format (... = ...)
|
||||||
sql`EXISTS (SELECT 1 FROM "_StatusToUser" WHERE "_StatusToUser"."A" = ${status.id} AND "_StatusToUser"."B" = ${user.id})`,
|
sql`EXISTS (SELECT 1 FROM "StatusToMentions" WHERE "StatusToMentions"."statusId" = ${status.id} AND "StatusToMentions"."userId" = ${user.id})`,
|
||||||
// All statuses from users that the user is following
|
// All statuses from users that the user is following
|
||||||
// WHERE format (... = ...)
|
// WHERE format (... = ...)
|
||||||
sql`EXISTS (SELECT 1 FROM "Relationship" WHERE "Relationship"."subjectId" = ${status.authorId} AND "Relationship"."ownerId" = ${user.id} AND "Relationship"."following" = true)`,
|
sql`EXISTS (SELECT 1 FROM "Relationship" WHERE "Relationship"."subjectId" = ${status.authorId} AND "Relationship"."ownerId" = ${user.id} AND "Relationship"."following" = true)`,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import type { APIApplication } from "~types/entities/application";
|
import type { APIApplication } from "~types/entities/application";
|
||||||
|
import type { APIToken } from "~types/entities/token";
|
||||||
import {
|
import {
|
||||||
deleteOldTestUsers,
|
deleteOldTestUsers,
|
||||||
getTestUsers,
|
getTestUsers,
|
||||||
sendTestRequest,
|
sendTestRequest,
|
||||||
wrapRelativeUrl,
|
wrapRelativeUrl,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
import type { APIToken } from "~types/entities/token";
|
|
||||||
|
|
||||||
const base_url = "http://lysand.localhost:8080"; //config.http.base_url;
|
const base_url = "http://lysand.localhost:8080"; //config.http.base_url;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue