refactor(database): 🎨 Update database and schema names to be clearer

This commit is contained in:
Jesse Wierzbinski 2024-04-16 20:36:01 -10:00
parent 9081036c6d
commit 88b3ec7b43
No known key found for this signature in database
92 changed files with 6785 additions and 1018 deletions

331
drizzle/0009_easy_slyde.sql Normal file
View file

@ -0,0 +1,331 @@
ALTER TABLE "Application" RENAME TO "Applications";--> statement-breakpoint
ALTER TABLE "Attachment" RENAME TO "Attachments";--> statement-breakpoint
ALTER TABLE "Emoji" RENAME TO "Emojis";--> statement-breakpoint
ALTER TABLE "EmojiToStatus" RENAME TO "EmojiToNote";--> statement-breakpoint
ALTER TABLE "Flag" RENAME TO "Flags";--> statement-breakpoint
ALTER TABLE "Instance" RENAME TO "Instances";--> statement-breakpoint
ALTER TABLE "Like" RENAME TO "Likes";--> statement-breakpoint
ALTER TABLE "ModNote" RENAME TO "ModNotes";--> statement-breakpoint
ALTER TABLE "ModTag" RENAME TO "ModTags";--> statement-breakpoint
ALTER TABLE "Notification" RENAME TO "Notifications";--> statement-breakpoint
ALTER TABLE "OpenIdAccount" RENAME TO "OpenIdAccounts";--> statement-breakpoint
ALTER TABLE "OpenIdLoginFlow" RENAME TO "OpenIdLoginFlows";--> statement-breakpoint
ALTER TABLE "Relationship" RENAME TO "Relationships";--> statement-breakpoint
ALTER TABLE "Status" RENAME TO "Notes";--> statement-breakpoint
ALTER TABLE "StatusToMentions" RENAME TO "NoteToMentions";--> statement-breakpoint
ALTER TABLE "Token" RENAME TO "Tokens";--> statement-breakpoint
ALTER TABLE "User" RENAME TO "Users";--> statement-breakpoint
ALTER TABLE "UserToPinnedNotes" RENAME COLUMN "statusId" TO "noteId";--> statement-breakpoint
ALTER TABLE "Attachments" RENAME COLUMN "statusId" TO "noteId";--> statement-breakpoint
ALTER TABLE "EmojiToNote" RENAME COLUMN "statusId" TO "noteId";--> statement-breakpoint
ALTER TABLE "Flags" RENAME COLUMN "flaggeStatusId" TO "noteId";--> statement-breakpoint
ALTER TABLE "Flags" RENAME COLUMN "flaggedUserId" TO "userId";--> statement-breakpoint
ALTER TABLE "ModNotes" RENAME COLUMN "notedStatusId" TO "noteId";--> statement-breakpoint
ALTER TABLE "ModNotes" RENAME COLUMN "notedUserId" TO "userId";--> statement-breakpoint
ALTER TABLE "ModTags" RENAME COLUMN "taggedStatusId" TO "statusId";--> statement-breakpoint
ALTER TABLE "ModTags" RENAME COLUMN "taggedUserId" TO "userId";--> statement-breakpoint
ALTER TABLE "Notifications" RENAME COLUMN "statusId" TO "noteId";--> statement-breakpoint
ALTER TABLE "Notes" RENAME COLUMN "inReplyToPostId" TO "replyId";--> statement-breakpoint
ALTER TABLE "Notes" RENAME COLUMN "quotingPostId" TO "quoteId";--> statement-breakpoint
ALTER TABLE "NoteToMentions" RENAME COLUMN "statusId" TO "noteId";--> statement-breakpoint
ALTER TABLE "EmojiToUser" DROP CONSTRAINT "EmojiToUser_emojiId_Emoji_id_fk";
--> statement-breakpoint
ALTER TABLE "EmojiToUser" DROP CONSTRAINT "EmojiToUser_userId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "UserToPinnedNotes" DROP CONSTRAINT "UserToPinnedNotes_userId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "UserToPinnedNotes" DROP CONSTRAINT "UserToPinnedNotes_statusId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Attachments" DROP CONSTRAINT "Attachment_statusId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "Emojis" DROP CONSTRAINT "Emoji_instanceId_Instance_id_fk";
--> statement-breakpoint
ALTER TABLE "EmojiToNote" DROP CONSTRAINT "EmojiToStatus_emojiId_Emoji_id_fk";
--> statement-breakpoint
ALTER TABLE "EmojiToNote" DROP CONSTRAINT "EmojiToStatus_statusId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "Flags" DROP CONSTRAINT "Flag_flaggeStatusId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "Flags" DROP CONSTRAINT "Flag_flaggedUserId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Likes" DROP CONSTRAINT "Like_likerId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Likes" DROP CONSTRAINT "Like_likedId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "ModNotes" DROP CONSTRAINT "ModNote_notedStatusId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "ModNotes" DROP CONSTRAINT "ModNote_notedUserId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "ModNotes" DROP CONSTRAINT "ModNote_modId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "ModTags" DROP CONSTRAINT "ModTag_taggedStatusId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "ModTags" DROP CONSTRAINT "ModTag_taggedUserId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "ModTags" DROP CONSTRAINT "ModTag_modId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Notifications" DROP CONSTRAINT "Notification_notifiedId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Notifications" DROP CONSTRAINT "Notification_accountId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Notifications" DROP CONSTRAINT "Notification_statusId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "OpenIdAccounts" DROP CONSTRAINT "OpenIdAccount_userId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "OpenIdLoginFlows" DROP CONSTRAINT "OpenIdLoginFlow_applicationId_Application_id_fk";
--> statement-breakpoint
ALTER TABLE "Relationships" DROP CONSTRAINT "Relationship_ownerId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Relationships" DROP CONSTRAINT "Relationship_subjectId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Notes" DROP CONSTRAINT "Status_authorId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Notes" DROP CONSTRAINT "Status_applicationId_Application_id_fk";
--> statement-breakpoint
ALTER TABLE "Notes" DROP CONSTRAINT "Status_reblogId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "Notes" DROP CONSTRAINT "Status_inReplyToPostId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "Notes" DROP CONSTRAINT "Status_quotingPostId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "NoteToMentions" DROP CONSTRAINT "StatusToMentions_statusId_Status_id_fk";
--> statement-breakpoint
ALTER TABLE "NoteToMentions" DROP CONSTRAINT "StatusToMentions_userId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Tokens" DROP CONSTRAINT "Token_userId_User_id_fk";
--> statement-breakpoint
ALTER TABLE "Tokens" DROP CONSTRAINT "Token_applicationId_Application_id_fk";
--> statement-breakpoint
ALTER TABLE "Users" DROP CONSTRAINT "User_instanceId_Instance_id_fk";
--> statement-breakpoint
DROP INDEX IF EXISTS "UserToPinnedNotes_userId_statusId_index";--> statement-breakpoint
DROP INDEX IF EXISTS "UserToPinnedNotes_statusId_index";--> statement-breakpoint
DROP INDEX IF EXISTS "Application_client_id_index";--> statement-breakpoint
DROP INDEX IF EXISTS "EmojiToStatus_emojiId_statusId_index";--> statement-breakpoint
DROP INDEX IF EXISTS "EmojiToStatus_statusId_index";--> statement-breakpoint
DROP INDEX IF EXISTS "Status_uri_index";--> statement-breakpoint
DROP INDEX IF EXISTS "StatusToMentions_statusId_userId_index";--> statement-breakpoint
DROP INDEX IF EXISTS "StatusToMentions_userId_index";--> statement-breakpoint
DROP INDEX IF EXISTS "User_uri_index";--> statement-breakpoint
DROP INDEX IF EXISTS "User_username_index";--> statement-breakpoint
DROP INDEX IF EXISTS "User_email_index";--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "UserToPinnedNotes_userId_noteId_index" ON "UserToPinnedNotes" ("userId","noteId");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "UserToPinnedNotes_noteId_index" ON "UserToPinnedNotes" ("noteId");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "Applications_client_id_index" ON "Applications" ("client_id");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "EmojiToNote_emojiId_noteId_index" ON "EmojiToNote" ("emojiId","noteId");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "EmojiToNote_noteId_index" ON "EmojiToNote" ("noteId");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "Notes_uri_index" ON "Notes" ("uri");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "NoteToMentions_noteId_userId_index" ON "NoteToMentions" ("noteId","userId");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "NoteToMentions_userId_index" ON "NoteToMentions" ("userId");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "Users_uri_index" ON "Users" ("uri");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "Users_username_index" ON "Users" ("username");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "Users_email_index" ON "Users" ("email");--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "EmojiToUser" ADD CONSTRAINT "EmojiToUser_emojiId_Emojis_id_fk" FOREIGN KEY ("emojiId") REFERENCES "Emojis"("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_Users_id_fk" FOREIGN KEY ("userId") REFERENCES "Users"("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_Notes_id_fk" FOREIGN KEY ("userId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "UserToPinnedNotes" ADD CONSTRAINT "UserToPinnedNotes_noteId_Users_id_fk" FOREIGN KEY ("noteId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Attachments" ADD CONSTRAINT "Attachments_noteId_Notes_id_fk" FOREIGN KEY ("noteId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Emojis" ADD CONSTRAINT "Emojis_instanceId_Instances_id_fk" FOREIGN KEY ("instanceId") REFERENCES "Instances"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "EmojiToNote" ADD CONSTRAINT "EmojiToNote_emojiId_Emojis_id_fk" FOREIGN KEY ("emojiId") REFERENCES "Emojis"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "EmojiToNote" ADD CONSTRAINT "EmojiToNote_noteId_Notes_id_fk" FOREIGN KEY ("noteId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Flags" ADD CONSTRAINT "Flags_noteId_Notes_id_fk" FOREIGN KEY ("noteId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Flags" ADD CONSTRAINT "Flags_userId_Users_id_fk" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Likes" ADD CONSTRAINT "Likes_likerId_Users_id_fk" FOREIGN KEY ("likerId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Likes" ADD CONSTRAINT "Likes_likedId_Notes_id_fk" FOREIGN KEY ("likedId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModNotes" ADD CONSTRAINT "ModNotes_noteId_Notes_id_fk" FOREIGN KEY ("noteId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModNotes" ADD CONSTRAINT "ModNotes_userId_Users_id_fk" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModNotes" ADD CONSTRAINT "ModNotes_modId_Users_id_fk" FOREIGN KEY ("modId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModTags" ADD CONSTRAINT "ModTags_statusId_Notes_id_fk" FOREIGN KEY ("statusId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModTags" ADD CONSTRAINT "ModTags_userId_Users_id_fk" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModTags" ADD CONSTRAINT "ModTags_modId_Users_id_fk" FOREIGN KEY ("modId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notifications" ADD CONSTRAINT "Notifications_notifiedId_Users_id_fk" FOREIGN KEY ("notifiedId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notifications" ADD CONSTRAINT "Notifications_accountId_Users_id_fk" FOREIGN KEY ("accountId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notifications" ADD CONSTRAINT "Notifications_noteId_Notes_id_fk" FOREIGN KEY ("noteId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "OpenIdAccounts" ADD CONSTRAINT "OpenIdAccounts_userId_Users_id_fk" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE set null ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "OpenIdLoginFlows" ADD CONSTRAINT "OpenIdLoginFlows_applicationId_Applications_id_fk" FOREIGN KEY ("applicationId") REFERENCES "Applications"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Relationships" ADD CONSTRAINT "Relationships_ownerId_Users_id_fk" FOREIGN KEY ("ownerId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Relationships" ADD CONSTRAINT "Relationships_subjectId_Users_id_fk" FOREIGN KEY ("subjectId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notes" ADD CONSTRAINT "Notes_authorId_Users_id_fk" FOREIGN KEY ("authorId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notes" ADD CONSTRAINT "Notes_applicationId_Applications_id_fk" FOREIGN KEY ("applicationId") REFERENCES "Applications"("id") ON DELETE set null ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notes" ADD CONSTRAINT "Notes_reblogId_Notes_id_fk" FOREIGN KEY ("reblogId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notes" ADD CONSTRAINT "Notes_replyId_Notes_id_fk" FOREIGN KEY ("replyId") REFERENCES "Notes"("id") ON DELETE set null ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Notes" ADD CONSTRAINT "Notes_quoteId_Notes_id_fk" FOREIGN KEY ("quoteId") REFERENCES "Notes"("id") ON DELETE set null ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "NoteToMentions" ADD CONSTRAINT "NoteToMentions_noteId_Notes_id_fk" FOREIGN KEY ("noteId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "NoteToMentions" ADD CONSTRAINT "NoteToMentions_userId_Users_id_fk" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Tokens" ADD CONSTRAINT "Tokens_userId_Users_id_fk" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Tokens" ADD CONSTRAINT "Tokens_applicationId_Applications_id_fk" FOREIGN KEY ("applicationId") REFERENCES "Applications"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "Users" ADD CONSTRAINT "Users_instanceId_Instances_id_fk" FOREIGN KEY ("instanceId") REFERENCES "Instances"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

View file

@ -0,0 +1,8 @@
ALTER TABLE "ModTags" RENAME COLUMN "statusId" TO "noteId";--> statement-breakpoint
ALTER TABLE "ModTags" DROP CONSTRAINT "ModTags_statusId_Notes_id_fk";
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "ModTags" ADD CONSTRAINT "ModTags_noteId_Notes_id_fk" FOREIGN KEY ("noteId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

View file

@ -0,0 +1,15 @@
ALTER TABLE "UserToPinnedNotes" DROP CONSTRAINT "UserToPinnedNotes_userId_Notes_id_fk";
--> statement-breakpoint
ALTER TABLE "UserToPinnedNotes" DROP CONSTRAINT "UserToPinnedNotes_noteId_Users_id_fk";
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "UserToPinnedNotes" ADD CONSTRAINT "UserToPinnedNotes_userId_Users_id_fk" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "UserToPinnedNotes" ADD CONSTRAINT "UserToPinnedNotes_noteId_Notes_id_fk" FOREIGN KEY ("noteId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,69 +1,90 @@
{
"version": "5",
"dialect": "pg",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1712805159664,
"tag": "0000_illegal_living_lightning",
"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
},
{
"idx": 7,
"version": "5",
"when": 1713227918208,
"tag": "0007_naive_sleeper",
"breakpoints": true
},
{
"idx": 8,
"version": "5",
"when": 1713246700119,
"tag": "0008_flawless_brother_voodoo",
"breakpoints": true
}
]
}
"version": "5",
"dialect": "pg",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1712805159664,
"tag": "0000_illegal_living_lightning",
"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
},
{
"idx": 7,
"version": "5",
"when": 1713227918208,
"tag": "0007_naive_sleeper",
"breakpoints": true
},
{
"idx": 8,
"version": "5",
"when": 1713246700119,
"tag": "0008_flawless_brother_voodoo",
"breakpoints": true
},
{
"idx": 9,
"version": "5",
"when": 1713327832438,
"tag": "0009_easy_slyde",
"breakpoints": true
},
{
"idx": 10,
"version": "5",
"when": 1713327880929,
"tag": "0010_daffy_frightful_four",
"breakpoints": true
},
{
"idx": 11,
"version": "5",
"when": 1713333611707,
"tag": "0011_special_the_fury",
"breakpoints": true
}
]
}

View file

@ -11,31 +11,32 @@ import {
uniqueIndex,
uuid,
} from "drizzle-orm/pg-core";
import type { Source as APISource } from "~types/mastodon/source";
export const emoji = pgTable("Emoji", {
export const Emojis = pgTable("Emojis", {
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, {
instanceId: uuid("instanceId").references(() => Instances.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
});
export const like = pgTable("Like", {
export const Likes = pgTable("Likes", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
likerId: uuid("likerId")
.notNull()
.references(() => user.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
likedId: uuid("likedId")
.notNull()
.references(() => status.id, {
.references(() => Notes.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
@ -44,7 +45,7 @@ export const like = pgTable("Like", {
.notNull(),
});
export const lysandObject = pgTable(
export const LysandObjects = pgTable(
"LysandObject",
{
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
@ -72,17 +73,17 @@ export const lysandObject = pgTable(
},
);
export const relationship = pgTable("Relationship", {
export const Relationships = pgTable("Relationships", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
ownerId: uuid("ownerId")
.notNull()
.references(() => user.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
subjectId: uuid("subjectId")
.notNull()
.references(() => user.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
@ -110,8 +111,8 @@ export const relationship = pgTable("Relationship", {
.notNull(),
});
export const application = pgTable(
"Application",
export const Applications = pgTable(
"Applications",
{
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
name: text("name").notNull(),
@ -129,12 +130,12 @@ export const application = pgTable(
},
);
export const applicationRelations = relations(application, ({ many }) => ({
tokens: many(token),
loginFlows: many(openIdLoginFlow),
export const ApplicationsRelations = relations(Applications, ({ many }) => ({
tokens: many(Tokens),
loginFlows: many(OpenIdLoginFlows),
}));
export const token = pgTable("Token", {
export const Tokens = pgTable("Tokens", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
tokenType: text("token_type").notNull(),
scope: text("scope").notNull(),
@ -143,17 +144,17 @@ export const token = pgTable("Token", {
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
userId: uuid("userId").references(() => user.id, {
userId: uuid("userId").references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
applicationId: uuid("applicationId").references(() => application.id, {
applicationId: uuid("applicationId").references(() => Applications.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
});
export const attachment = pgTable("Attachment", {
export const Attachments = pgTable("Attachments", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
url: text("url").notNull(),
remoteUrl: text("remote_url"),
@ -167,13 +168,13 @@ export const attachment = pgTable("Attachment", {
width: integer("width"),
height: integer("height"),
size: integer("size"),
statusId: uuid("statusId").references(() => status.id, {
noteId: uuid("noteId").references(() => Notes.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
});
export const notification = pgTable("Notification", {
export const Notifications = pgTable("Notifications", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
type: text("type").notNull(),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
@ -181,31 +182,31 @@ export const notification = pgTable("Notification", {
.notNull(),
notifiedId: uuid("notifiedId")
.notNull()
.references(() => user.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
accountId: uuid("accountId")
.notNull()
.references(() => user.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
statusId: uuid("statusId").references(() => status.id, {
noteId: uuid("noteId").references(() => Notes.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
dismissed: boolean("dismissed").default(false).notNull(),
});
export const status = pgTable(
"Status",
export const Notes = pgTable(
"Notes",
{
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
uri: text("uri"),
authorId: uuid("authorId")
.notNull()
.references(() => user.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
@ -222,11 +223,11 @@ export const status = pgTable(
content: text("content").default("").notNull(),
contentType: text("content_type").default("text/plain").notNull(),
visibility: text("visibility").notNull(),
inReplyToPostId: uuid("inReplyToPostId"),
quotingPostId: uuid("quotingPostId"),
replyId: uuid("replyId"),
quotingId: uuid("quoteId"),
sensitive: boolean("sensitive").notNull(),
spoilerText: text("spoiler_text").default("").notNull(),
applicationId: uuid("applicationId").references(() => application.id, {
applicationId: uuid("applicationId").references(() => Applications.id, {
onDelete: "set null",
onUpdate: "cascade",
}),
@ -235,20 +236,20 @@ export const status = pgTable(
(table) => {
return {
uriKey: uniqueIndex().on(table.uri),
statusReblogIdFkey: foreignKey({
noteReblogIdFkey: foreignKey({
columns: [table.reblogId],
foreignColumns: [table.id],
})
.onUpdate("cascade")
.onDelete("cascade"),
statusInReplyToPostIdFkey: foreignKey({
columns: [table.inReplyToPostId],
noteReplyIdFkey: foreignKey({
columns: [table.replyId],
foreignColumns: [table.id],
})
.onUpdate("cascade")
.onDelete("set null"),
statusQuotingPostIdFkey: foreignKey({
columns: [table.quotingPostId],
noteQuotingIdFkey: foreignKey({
columns: [table.quotingId],
foreignColumns: [table.id],
})
.onUpdate("cascade")
@ -257,7 +258,7 @@ export const status = pgTable(
},
);
export const instance = pgTable("Instance", {
export const Instances = pgTable("Instances", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
baseUrl: text("base_url").notNull(),
name: text("name").notNull(),
@ -268,9 +269,9 @@ export const instance = pgTable("Instance", {
.notNull(),
});
export const openIdAccount = pgTable("OpenIdAccount", {
export const OpenIdAccounts = pgTable("OpenIdAccounts", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
userId: uuid("userId").references(() => user.id, {
userId: uuid("userId").references(() => Users.id, {
onDelete: "set null",
onUpdate: "cascade",
}),
@ -278,8 +279,8 @@ export const openIdAccount = pgTable("OpenIdAccount", {
issuerId: text("issuer_id").notNull(),
});
export const user = pgTable(
"User",
export const Users = pgTable(
"Users",
{
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
uri: text("uri"),
@ -298,7 +299,7 @@ export const user = pgTable(
inbox: string;
outbox: string;
}> | null>(),
source: jsonb("source").notNull(),
source: jsonb("source").notNull().$type<APISource>(),
avatar: text("avatar").notNull(),
header: text("header").notNull(),
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
@ -316,7 +317,7 @@ export const user = pgTable(
sanctions: text("sanctions").array(),
publicKey: text("public_key").notNull(),
privateKey: text("private_key"),
instanceId: uuid("instanceId").references(() => instance.id, {
instanceId: uuid("instanceId").references(() => Instances.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
@ -333,55 +334,55 @@ export const user = pgTable(
},
);
export const openIdLoginFlow = pgTable("OpenIdLoginFlow", {
export const OpenIdLoginFlows = pgTable("OpenIdLoginFlows", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
codeVerifier: text("code_verifier").notNull(),
applicationId: uuid("applicationId").references(() => application.id, {
applicationId: uuid("applicationId").references(() => Applications.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
issuerId: text("issuer_id").notNull(),
});
export const openIdLoginFlowRelations = relations(
openIdLoginFlow,
export const OpenIdLoginFlowsRelations = relations(
OpenIdLoginFlows,
({ one }) => ({
application: one(application, {
fields: [openIdLoginFlow.applicationId],
references: [application.id],
application: one(Applications, {
fields: [OpenIdLoginFlows.applicationId],
references: [Applications.id],
}),
}),
);
export const flag = pgTable("Flag", {
export const Flags = pgTable("Flags", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
flagType: text("flag_type").default("other").notNull(),
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
flaggeStatusId: uuid("flaggeStatusId").references(() => status.id, {
noteId: uuid("noteId").references(() => Notes.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
flaggedUserId: uuid("flaggedUserId").references(() => user.id, {
userId: uuid("userId").references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
});
export const modNote = pgTable("ModNote", {
export const ModNotes = pgTable("ModNotes", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
notedStatusId: uuid("notedStatusId").references(() => status.id, {
nodeId: uuid("noteId").references(() => Notes.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
notedUserId: uuid("notedUserId").references(() => user.id, {
userId: uuid("userId").references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
modId: uuid("modId")
.notNull()
.references(() => user.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
@ -391,19 +392,19 @@ export const modNote = pgTable("ModNote", {
.notNull(),
});
export const modTag = pgTable("ModTag", {
export const ModTags = pgTable("ModTags", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
taggedStatusId: uuid("taggedStatusId").references(() => status.id, {
noteId: uuid("noteId").references(() => Notes.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
taggedUserId: uuid("taggedUserId").references(() => user.id, {
userId: uuid("userId").references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
modId: uuid("modId")
.notNull()
.references(() => user.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
@ -413,18 +414,18 @@ export const modTag = pgTable("ModTag", {
.notNull(),
});
export const emojiToUser = pgTable(
export const EmojiToUser = pgTable(
"EmojiToUser",
{
emojiId: uuid("emojiId")
.notNull()
.references(() => emoji.id, {
.references(() => Emojis.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
userId: uuid("userId")
.notNull()
.references(() => user.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
@ -437,267 +438,267 @@ export const emojiToUser = pgTable(
},
);
export const emojiToUserRelations = relations(emojiToUser, ({ one }) => ({
emoji: one(emoji, {
fields: [emojiToUser.emojiId],
references: [emoji.id],
export const EmojiToUserRelations = relations(EmojiToUser, ({ one }) => ({
emoji: one(Emojis, {
fields: [EmojiToUser.emojiId],
references: [Emojis.id],
}),
user: one(user, {
fields: [emojiToUser.userId],
references: [user.id],
user: one(Users, {
fields: [EmojiToUser.userId],
references: [Users.id],
}),
}));
export const emojiToStatus = pgTable(
"EmojiToStatus",
export const EmojiToNote = pgTable(
"EmojiToNote",
{
emojiId: uuid("emojiId")
.notNull()
.references(() => emoji.id, {
.references(() => Emojis.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
statusId: uuid("statusId")
noteId: uuid("noteId")
.notNull()
.references(() => status.id, {
.references(() => Notes.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
},
(table) => {
return {
abUnique: uniqueIndex().on(table.emojiId, table.statusId),
bIdx: index().on(table.statusId),
abUnique: uniqueIndex().on(table.emojiId, table.noteId),
bIdx: index().on(table.noteId),
};
},
);
export const statusToMentions = pgTable(
"StatusToMentions",
export const NoteToMentions = pgTable(
"NoteToMentions",
{
statusId: uuid("statusId")
noteId: uuid("noteId")
.notNull()
.references(() => status.id, {
.references(() => Notes.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
userId: uuid("userId")
.notNull()
.references(() => user.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
},
(table) => {
return {
abUnique: uniqueIndex().on(table.statusId, table.userId),
abUnique: uniqueIndex().on(table.noteId, table.userId),
bIdx: index().on(table.userId),
};
},
);
export const userPinnedNotes = pgTable(
export const UserToPinnedNotes = pgTable(
"UserToPinnedNotes",
{
userId: uuid("userId")
.notNull()
.references(() => status.id, {
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
statusId: uuid("statusId")
noteId: uuid("noteId")
.notNull()
.references(() => user.id, {
.references(() => Notes.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
},
(table) => {
return {
abUnique: uniqueIndex().on(table.userId, table.statusId),
bIdx: index().on(table.statusId),
abUnique: uniqueIndex().on(table.userId, table.noteId),
bIdx: index().on(table.noteId),
};
},
);
export const attachmentRelations = relations(attachment, ({ one }) => ({
status: one(status, {
fields: [attachment.statusId],
references: [status.id],
export const AttachmentsRelations = relations(Attachments, ({ one }) => ({
notes: one(Notes, {
fields: [Attachments.noteId],
references: [Notes.id],
}),
}));
export const userRelations = relations(user, ({ many, one }) => ({
emojis: many(emojiToUser),
pinnedNotes: many(userPinnedNotes),
statuses: many(status, {
relationName: "StatusToAuthor",
export const UsersRelations = relations(Users, ({ many, one }) => ({
emojis: many(EmojiToUser),
pinnedNotes: many(UserToPinnedNotes),
notes: many(Notes, {
relationName: "NoteToAuthor",
}),
likes: many(like),
relationships: many(relationship, {
likes: many(Likes),
relationships: many(Relationships, {
relationName: "RelationshipToOwner",
}),
relationshipSubjects: many(relationship, {
relationshipSubjects: many(Relationships, {
relationName: "RelationshipToSubject",
}),
notificationsMade: many(notification, {
notificationsMade: many(Notifications, {
relationName: "NotificationToAccount",
}),
notificationsReceived: many(notification, {
notificationsReceived: many(Notifications, {
relationName: "NotificationToNotified",
}),
openIdAccounts: many(openIdAccount),
flags: many(flag),
modNotes: many(modNote),
modTags: many(modTag),
tokens: many(token),
instance: one(instance, {
fields: [user.instanceId],
references: [instance.id],
openIdAccounts: many(OpenIdAccounts),
flags: many(Flags),
modNotes: many(ModNotes),
modTags: many(ModTags),
tokens: many(Tokens),
instance: one(Instances, {
fields: [Users.instanceId],
references: [Instances.id],
}),
mentionedIn: many(statusToMentions),
mentionedIn: many(NoteToMentions),
}));
export const relationshipRelations = relations(relationship, ({ one }) => ({
owner: one(user, {
fields: [relationship.ownerId],
references: [user.id],
export const RelationshipsRelations = relations(Relationships, ({ one }) => ({
owner: one(Users, {
fields: [Relationships.ownerId],
references: [Users.id],
relationName: "RelationshipToOwner",
}),
subject: one(user, {
fields: [relationship.subjectId],
references: [user.id],
subject: one(Users, {
fields: [Relationships.subjectId],
references: [Users.id],
relationName: "RelationshipToSubject",
}),
}));
export const tokenRelations = relations(token, ({ one }) => ({
user: one(user, {
fields: [token.userId],
references: [user.id],
export const TokensRelations = relations(Tokens, ({ one }) => ({
user: one(Users, {
fields: [Tokens.userId],
references: [Users.id],
}),
application: one(application, {
fields: [token.applicationId],
references: [application.id],
application: one(Applications, {
fields: [Tokens.applicationId],
references: [Applications.id],
}),
}));
export const statusToUserRelations = relations(statusToMentions, ({ one }) => ({
status: one(status, {
fields: [statusToMentions.statusId],
references: [status.id],
export const NotesToUsersRelations = relations(NoteToMentions, ({ one }) => ({
note: one(Notes, {
fields: [NoteToMentions.noteId],
references: [Notes.id],
}),
user: one(user, {
fields: [statusToMentions.userId],
references: [user.id],
user: one(Users, {
fields: [NoteToMentions.userId],
references: [Users.id],
}),
}));
export const userPinnedNotesRelations = relations(
userPinnedNotes,
export const UserToPinnedNotesRelations = relations(
UserToPinnedNotes,
({ one }) => ({
status: one(status, {
fields: [userPinnedNotes.statusId],
references: [status.id],
note: one(Notes, {
fields: [UserToPinnedNotes.noteId],
references: [Notes.id],
}),
user: one(user, {
fields: [userPinnedNotes.userId],
references: [user.id],
user: one(Users, {
fields: [UserToPinnedNotes.userId],
references: [Users.id],
}),
}),
);
export const statusRelations = relations(status, ({ many, one }) => ({
emojis: many(emojiToStatus),
author: one(user, {
fields: [status.authorId],
references: [user.id],
relationName: "StatusToAuthor",
export const NotesRelations = relations(Notes, ({ many, one }) => ({
emojis: many(EmojiToNote),
author: one(Users, {
fields: [Notes.authorId],
references: [Users.id],
relationName: "NoteToAuthor",
}),
attachments: many(attachment),
mentions: many(statusToMentions),
reblog: one(status, {
fields: [status.reblogId],
references: [status.id],
relationName: "StatusToReblog",
attachments: many(Attachments),
mentions: many(NoteToMentions),
reblog: one(Notes, {
fields: [Notes.reblogId],
references: [Notes.id],
relationName: "NoteToReblogs",
}),
usersThatHavePinned: many(userPinnedNotes),
inReplyTo: one(status, {
fields: [status.inReplyToPostId],
references: [status.id],
relationName: "StatusToReplying",
usersThatHavePinned: many(UserToPinnedNotes),
reply: one(Notes, {
fields: [Notes.replyId],
references: [Notes.id],
relationName: "NoteToReplies",
}),
quoting: one(status, {
fields: [status.quotingPostId],
references: [status.id],
relationName: "StatusToQuoting",
quote: one(Notes, {
fields: [Notes.quotingId],
references: [Notes.id],
relationName: "NoteToQuotes",
}),
application: one(application, {
fields: [status.applicationId],
references: [application.id],
application: one(Applications, {
fields: [Notes.applicationId],
references: [Applications.id],
}),
quotes: many(status, {
relationName: "StatusToQuoting",
quotes: many(Notes, {
relationName: "NoteToQuotes",
}),
replies: many(status, {
relationName: "StatusToReplying",
replies: many(Notes, {
relationName: "NoteToReplies",
}),
likes: many(like),
reblogs: many(status, {
relationName: "StatusToReblog",
likes: many(Likes),
reblogs: many(Notes, {
relationName: "NoteToReblogs",
}),
notifications: many(notification),
notifications: many(Notifications),
}));
export const notificationRelations = relations(notification, ({ one }) => ({
account: one(user, {
fields: [notification.accountId],
references: [user.id],
export const NotificationsRelations = relations(Notifications, ({ one }) => ({
account: one(Users, {
fields: [Notifications.accountId],
references: [Users.id],
relationName: "NotificationToAccount",
}),
notified: one(user, {
fields: [notification.notifiedId],
references: [user.id],
notified: one(Users, {
fields: [Notifications.notifiedId],
references: [Users.id],
relationName: "NotificationToNotified",
}),
status: one(status, {
fields: [notification.statusId],
references: [status.id],
note: one(Notes, {
fields: [Notifications.noteId],
references: [Notes.id],
}),
}));
export const likeRelations = relations(like, ({ one }) => ({
liker: one(user, {
fields: [like.likerId],
references: [user.id],
export const LikesRelations = relations(Likes, ({ one }) => ({
liker: one(Users, {
fields: [Likes.likerId],
references: [Users.id],
}),
liked: one(status, {
fields: [like.likedId],
references: [status.id],
liked: one(Notes, {
fields: [Likes.likedId],
references: [Notes.id],
}),
}));
export const emojiRelations = relations(emoji, ({ one, many }) => ({
instance: one(instance, {
fields: [emoji.instanceId],
references: [instance.id],
export const EmojisRelations = relations(Emojis, ({ one, many }) => ({
instance: one(Instances, {
fields: [Emojis.instanceId],
references: [Instances.id],
}),
users: many(emojiToUser),
statuses: many(emojiToStatus),
users: many(EmojiToUser),
notes: many(EmojiToNote),
}));
export const instanceRelations = relations(instance, ({ many }) => ({
users: many(user),
emojis: many(emoji),
export const InstancesRelations = relations(Instances, ({ many }) => ({
users: many(Users),
emojis: many(Emojis),
}));
export const emojiToStatusRelations = relations(emojiToStatus, ({ one }) => ({
emoji: one(emoji, {
fields: [emojiToStatus.emojiId],
references: [emoji.id],
export const EmojisToNotesRelations = relations(EmojiToNote, ({ one }) => ({
emoji: one(Emojis, {
fields: [EmojiToNote.emojiId],
references: [Emojis.id],
}),
status: one(status, {
fields: [emojiToStatus.statusId],
references: [status.id],
note: one(Notes, {
fields: [EmojiToNote.noteId],
references: [Notes.id],
}),
}));