refactor(database): ♻️ Cleanup Notes database declaration

This commit is contained in:
Jesse Wierzbinski 2024-04-26 11:19:01 -10:00
parent a45a4b3652
commit db35ba6f93
No known key found for this signature in database
4 changed files with 2207 additions and 208 deletions

View 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");

File diff suppressed because it is too large Load diff

View file

@ -1,153 +1,160 @@
{
"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
},
{
"idx": 12,
"version": "5",
"when": 1713336108114,
"tag": "0012_certain_thor_girl",
"breakpoints": true
},
{
"idx": 13,
"version": "5",
"when": 1713336611301,
"tag": "0013_wandering_celestials",
"breakpoints": true
},
{
"idx": 14,
"version": "5",
"when": 1713389937821,
"tag": "0014_wonderful_sandman",
"breakpoints": true
},
{
"idx": 15,
"version": "5",
"when": 1713399438164,
"tag": "0015_easy_mojo",
"breakpoints": true
},
{
"idx": 16,
"version": "5",
"when": 1713413369623,
"tag": "0016_keen_mindworm",
"breakpoints": true
},
{
"idx": 17,
"version": "5",
"when": 1713417089150,
"tag": "0017_dusty_black_knight",
"breakpoints": true
},
{
"idx": 18,
"version": "5",
"when": 1713418575392,
"tag": "0018_rapid_hairball",
"breakpoints": true
},
{
"idx": 19,
"version": "5",
"when": 1713421706451,
"tag": "0019_mushy_lorna_dane",
"breakpoints": true
},
{
"idx": 20,
"version": "5",
"when": 1714017186457,
"tag": "0020_giant_the_stranger",
"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
},
{
"idx": 12,
"version": "5",
"when": 1713336108114,
"tag": "0012_certain_thor_girl",
"breakpoints": true
},
{
"idx": 13,
"version": "5",
"when": 1713336611301,
"tag": "0013_wandering_celestials",
"breakpoints": true
},
{
"idx": 14,
"version": "5",
"when": 1713389937821,
"tag": "0014_wonderful_sandman",
"breakpoints": true
},
{
"idx": 15,
"version": "5",
"when": 1713399438164,
"tag": "0015_easy_mojo",
"breakpoints": true
},
{
"idx": 16,
"version": "5",
"when": 1713413369623,
"tag": "0016_keen_mindworm",
"breakpoints": true
},
{
"idx": 17,
"version": "5",
"when": 1713417089150,
"tag": "0017_dusty_black_knight",
"breakpoints": true
},
{
"idx": 18,
"version": "5",
"when": 1713418575392,
"tag": "0018_rapid_hairball",
"breakpoints": true
},
{
"idx": 19,
"version": "5",
"when": 1713421706451,
"tag": "0019_mushy_lorna_dane",
"breakpoints": true
},
{
"idx": 20,
"version": "5",
"when": 1714017186457,
"tag": "0020_giant_the_stranger",
"breakpoints": true
},
{
"idx": 21,
"version": "5",
"when": 1714165180389,
"tag": "0021_wise_stephen_strange",
"breakpoints": true
}
]
}

View file

@ -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,64 +273,47 @@ export const Notifications = pgTable("Notifications", {
dismissed: boolean("dismissed").default(false).notNull(),
});
export const Notes = pgTable(
"Notes",
{
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
uri: text("uri"),
authorId: uuid("authorId")
.notNull()
.references(() => Users.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
updatedAt: timestamp("updatedAt", {
precision: 3,
mode: "string",
})
.defaultNow()
.notNull(),
reblogId: uuid("reblogId"),
content: text("content").default("").notNull(),
contentType: text("content_type").default("text/plain").notNull(),
visibility: text("visibility").notNull(),
replyId: uuid("replyId"),
quotingId: uuid("quoteId"),
sensitive: boolean("sensitive").notNull(),
spoilerText: text("spoiler_text").default("").notNull(),
applicationId: uuid("applicationId").references(() => Applications.id, {
onDelete: "set null",
export const Notes = pgTable("Notes", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
uri: text("uri").unique(),
authorId: uuid("authorId")
.notNull()
.references(() => Users.id, {
onDelete: "cascade",
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"),
};
},
);
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
updatedAt: timestamp("updatedAt", {
precision: 3,
mode: "string",
})
.defaultNow()
.notNull(),
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").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, {
onDelete: "set null",
onUpdate: "cascade",
}),
contentSource: text("content_source").default("").notNull(),
});
export const Instances = pgTable("Instances", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),