mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
refactor(database): ♻️ Cleanup Notes database declaration
This commit is contained in:
parent
a45a4b3652
commit
db35ba6f93
10
drizzle/0021_wise_stephen_strange.sql
Normal file
10
drizzle/0021_wise_stephen_strange.sql
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
ALTER TABLE "Notes" DROP CONSTRAINT "Notes_replyId_Notes_id_fk";
|
||||
--> statement-breakpoint
|
||||
DROP INDEX IF EXISTS "Notes_uri_index";--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "Notes" ADD CONSTRAINT "Notes_replyId_Notes_id_fk" FOREIGN KEY ("replyId") REFERENCES "Notes"("id") ON DELETE cascade ON UPDATE cascade;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "Notes" ADD CONSTRAINT "Notes_uri_unique" UNIQUE("uri");
|
||||
1998
drizzle/meta/0021_snapshot.json
Normal file
1998
drizzle/meta/0021_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -148,6 +148,13 @@
|
|||
"when": 1714017186457,
|
||||
"tag": "0020_giant_the_stranger",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 21,
|
||||
"version": "5",
|
||||
"when": 1714165180389,
|
||||
"tag": "0021_wise_stephen_strange",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import {
|
|||
timestamp,
|
||||
uniqueIndex,
|
||||
uuid,
|
||||
type AnyPgColumn,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import type * as Lysand from "lysand-types";
|
||||
import type { Source as APISource } from "~types/mastodon/source";
|
||||
|
|
@ -272,11 +273,9 @@ export const Notifications = pgTable("Notifications", {
|
|||
dismissed: boolean("dismissed").default(false).notNull(),
|
||||
});
|
||||
|
||||
export const Notes = pgTable(
|
||||
"Notes",
|
||||
{
|
||||
export const Notes = pgTable("Notes", {
|
||||
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
||||
uri: text("uri"),
|
||||
uri: text("uri").unique(),
|
||||
authorId: uuid("authorId")
|
||||
.notNull()
|
||||
.references(() => Users.id, {
|
||||
|
|
@ -292,12 +291,21 @@ export const Notes = pgTable(
|
|||
})
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
reblogId: uuid("reblogId"),
|
||||
reblogId: uuid("reblogId").references((): AnyPgColumn => Notes.id, {
|
||||
onDelete: "cascade",
|
||||
onUpdate: "cascade",
|
||||
}),
|
||||
content: text("content").default("").notNull(),
|
||||
contentType: text("content_type").default("text/plain").notNull(),
|
||||
visibility: text("visibility").notNull(),
|
||||
replyId: uuid("replyId"),
|
||||
quotingId: uuid("quoteId"),
|
||||
replyId: uuid("replyId").references((): AnyPgColumn => Notes.id, {
|
||||
onDelete: "cascade",
|
||||
onUpdate: "cascade",
|
||||
}),
|
||||
quotingId: uuid("quoteId").references((): AnyPgColumn => Notes.id, {
|
||||
onDelete: "cascade",
|
||||
onUpdate: "cascade",
|
||||
}),
|
||||
sensitive: boolean("sensitive").notNull(),
|
||||
spoilerText: text("spoiler_text").default("").notNull(),
|
||||
applicationId: uuid("applicationId").references(() => Applications.id, {
|
||||
|
|
@ -305,31 +313,7 @@ export const Notes = pgTable(
|
|||
onUpdate: "cascade",
|
||||
}),
|
||||
contentSource: text("content_source").default("").notNull(),
|
||||
},
|
||||
(table) => {
|
||||
return {
|
||||
uriKey: uniqueIndex().on(table.uri),
|
||||
noteReblogIdFkey: foreignKey({
|
||||
columns: [table.reblogId],
|
||||
foreignColumns: [table.id],
|
||||
})
|
||||
.onUpdate("cascade")
|
||||
.onDelete("cascade"),
|
||||
noteReplyIdFkey: foreignKey({
|
||||
columns: [table.replyId],
|
||||
foreignColumns: [table.id],
|
||||
})
|
||||
.onUpdate("cascade")
|
||||
.onDelete("set null"),
|
||||
noteQuotingIdFkey: foreignKey({
|
||||
columns: [table.quotingId],
|
||||
foreignColumns: [table.id],
|
||||
})
|
||||
.onUpdate("cascade")
|
||||
.onDelete("set null"),
|
||||
};
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
export const Instances = pgTable("Instances", {
|
||||
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue