mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38: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
|
|
@ -1,153 +1,160 @@
|
||||||
{
|
{
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"dialect": "pg",
|
"dialect": "pg",
|
||||||
"entries": [
|
"entries": [
|
||||||
{
|
{
|
||||||
"idx": 0,
|
"idx": 0,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1712805159664,
|
"when": 1712805159664,
|
||||||
"tag": "0000_illegal_living_lightning",
|
"tag": "0000_illegal_living_lightning",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713055774123,
|
"when": 1713055774123,
|
||||||
"tag": "0001_salty_night_thrasher",
|
"tag": "0001_salty_night_thrasher",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 2,
|
"idx": 2,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713056370431,
|
"when": 1713056370431,
|
||||||
"tag": "0002_stiff_ares",
|
"tag": "0002_stiff_ares",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 3,
|
"idx": 3,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713056528340,
|
"when": 1713056528340,
|
||||||
"tag": "0003_spicy_arachne",
|
"tag": "0003_spicy_arachne",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 4,
|
"idx": 4,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713056712218,
|
"when": 1713056712218,
|
||||||
"tag": "0004_burly_lockjaw",
|
"tag": "0004_burly_lockjaw",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 5,
|
"idx": 5,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713056917973,
|
"when": 1713056917973,
|
||||||
"tag": "0005_sleepy_puma",
|
"tag": "0005_sleepy_puma",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 6,
|
"idx": 6,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713057159867,
|
"when": 1713057159867,
|
||||||
"tag": "0006_messy_network",
|
"tag": "0006_messy_network",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 7,
|
"idx": 7,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713227918208,
|
"when": 1713227918208,
|
||||||
"tag": "0007_naive_sleeper",
|
"tag": "0007_naive_sleeper",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 8,
|
"idx": 8,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713246700119,
|
"when": 1713246700119,
|
||||||
"tag": "0008_flawless_brother_voodoo",
|
"tag": "0008_flawless_brother_voodoo",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 9,
|
"idx": 9,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713327832438,
|
"when": 1713327832438,
|
||||||
"tag": "0009_easy_slyde",
|
"tag": "0009_easy_slyde",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 10,
|
"idx": 10,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713327880929,
|
"when": 1713327880929,
|
||||||
"tag": "0010_daffy_frightful_four",
|
"tag": "0010_daffy_frightful_four",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 11,
|
"idx": 11,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713333611707,
|
"when": 1713333611707,
|
||||||
"tag": "0011_special_the_fury",
|
"tag": "0011_special_the_fury",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 12,
|
"idx": 12,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713336108114,
|
"when": 1713336108114,
|
||||||
"tag": "0012_certain_thor_girl",
|
"tag": "0012_certain_thor_girl",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 13,
|
"idx": 13,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713336611301,
|
"when": 1713336611301,
|
||||||
"tag": "0013_wandering_celestials",
|
"tag": "0013_wandering_celestials",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 14,
|
"idx": 14,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713389937821,
|
"when": 1713389937821,
|
||||||
"tag": "0014_wonderful_sandman",
|
"tag": "0014_wonderful_sandman",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 15,
|
"idx": 15,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713399438164,
|
"when": 1713399438164,
|
||||||
"tag": "0015_easy_mojo",
|
"tag": "0015_easy_mojo",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 16,
|
"idx": 16,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713413369623,
|
"when": 1713413369623,
|
||||||
"tag": "0016_keen_mindworm",
|
"tag": "0016_keen_mindworm",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 17,
|
"idx": 17,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713417089150,
|
"when": 1713417089150,
|
||||||
"tag": "0017_dusty_black_knight",
|
"tag": "0017_dusty_black_knight",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 18,
|
"idx": 18,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713418575392,
|
"when": 1713418575392,
|
||||||
"tag": "0018_rapid_hairball",
|
"tag": "0018_rapid_hairball",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 19,
|
"idx": 19,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1713421706451,
|
"when": 1713421706451,
|
||||||
"tag": "0019_mushy_lorna_dane",
|
"tag": "0019_mushy_lorna_dane",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 20,
|
"idx": 20,
|
||||||
"version": "5",
|
"version": "5",
|
||||||
"when": 1714017186457,
|
"when": 1714017186457,
|
||||||
"tag": "0020_giant_the_stranger",
|
"tag": "0020_giant_the_stranger",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
|
"idx": 21,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1714165180389,
|
||||||
|
"tag": "0021_wise_stephen_strange",
|
||||||
|
"breakpoints": true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ import {
|
||||||
timestamp,
|
timestamp,
|
||||||
uniqueIndex,
|
uniqueIndex,
|
||||||
uuid,
|
uuid,
|
||||||
|
type AnyPgColumn,
|
||||||
} from "drizzle-orm/pg-core";
|
} from "drizzle-orm/pg-core";
|
||||||
import type * as Lysand from "lysand-types";
|
import type * as Lysand from "lysand-types";
|
||||||
import type { Source as APISource } from "~types/mastodon/source";
|
import type { Source as APISource } from "~types/mastodon/source";
|
||||||
|
|
@ -272,64 +273,47 @@ export const Notifications = pgTable("Notifications", {
|
||||||
dismissed: boolean("dismissed").default(false).notNull(),
|
dismissed: boolean("dismissed").default(false).notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Notes = pgTable(
|
export const Notes = pgTable("Notes", {
|
||||||
"Notes",
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
||||||
{
|
uri: text("uri").unique(),
|
||||||
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
authorId: uuid("authorId")
|
||||||
uri: text("uri"),
|
.notNull()
|
||||||
authorId: uuid("authorId")
|
.references(() => Users.id, {
|
||||||
.notNull()
|
onDelete: "cascade",
|
||||||
.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",
|
|
||||||
onUpdate: "cascade",
|
onUpdate: "cascade",
|
||||||
}),
|
}),
|
||||||
contentSource: text("content_source").default("").notNull(),
|
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
|
||||||
},
|
.defaultNow()
|
||||||
(table) => {
|
.notNull(),
|
||||||
return {
|
updatedAt: timestamp("updatedAt", {
|
||||||
uriKey: uniqueIndex().on(table.uri),
|
precision: 3,
|
||||||
noteReblogIdFkey: foreignKey({
|
mode: "string",
|
||||||
columns: [table.reblogId],
|
})
|
||||||
foreignColumns: [table.id],
|
.defaultNow()
|
||||||
})
|
.notNull(),
|
||||||
.onUpdate("cascade")
|
reblogId: uuid("reblogId").references((): AnyPgColumn => Notes.id, {
|
||||||
.onDelete("cascade"),
|
onDelete: "cascade",
|
||||||
noteReplyIdFkey: foreignKey({
|
onUpdate: "cascade",
|
||||||
columns: [table.replyId],
|
}),
|
||||||
foreignColumns: [table.id],
|
content: text("content").default("").notNull(),
|
||||||
})
|
contentType: text("content_type").default("text/plain").notNull(),
|
||||||
.onUpdate("cascade")
|
visibility: text("visibility").notNull(),
|
||||||
.onDelete("set null"),
|
replyId: uuid("replyId").references((): AnyPgColumn => Notes.id, {
|
||||||
noteQuotingIdFkey: foreignKey({
|
onDelete: "cascade",
|
||||||
columns: [table.quotingId],
|
onUpdate: "cascade",
|
||||||
foreignColumns: [table.id],
|
}),
|
||||||
})
|
quotingId: uuid("quoteId").references((): AnyPgColumn => Notes.id, {
|
||||||
.onUpdate("cascade")
|
onDelete: "cascade",
|
||||||
.onDelete("set null"),
|
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", {
|
export const Instances = pgTable("Instances", {
|
||||||
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue