feat(category): save collapse state for signed in users (#2134)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE `section_collapse_state` (
|
||||
`user_id` varchar(64) NOT NULL,
|
||||
`section_id` varchar(64) NOT NULL,
|
||||
`collapsed` boolean NOT NULL DEFAULT false,
|
||||
CONSTRAINT `section_collapse_state_user_id_section_id_pk` PRIMARY KEY(`user_id`,`section_id`)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `section_collapse_state` ADD CONSTRAINT `section_collapse_state_user_id_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `section_collapse_state` ADD CONSTRAINT `section_collapse_state_section_id_section_id_fk` FOREIGN KEY (`section_id`) REFERENCES `section`(`id`) ON DELETE cascade ON UPDATE no action;
|
||||
1764
packages/db/migrations/mysql/meta/0022_snapshot.json
Normal file
1764
packages/db/migrations/mysql/meta/0022_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -155,6 +155,13 @@
|
||||
"when": 1737883744729,
|
||||
"tag": "0021_fluffy_jocasta",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 22,
|
||||
"version": "5",
|
||||
"when": 1737927618711,
|
||||
"tag": "0022_famous_otto_octavius",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
8
packages/db/migrations/sqlite/0022_modern_sunfire.sql
Normal file
8
packages/db/migrations/sqlite/0022_modern_sunfire.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE `section_collapse_state` (
|
||||
`user_id` text NOT NULL,
|
||||
`section_id` text NOT NULL,
|
||||
`collapsed` integer DEFAULT false NOT NULL,
|
||||
PRIMARY KEY(`user_id`, `section_id`),
|
||||
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade,
|
||||
FOREIGN KEY (`section_id`) REFERENCES `section`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
1689
packages/db/migrations/sqlite/meta/0022_snapshot.json
Normal file
1689
packages/db/migrations/sqlite/meta/0022_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -155,6 +155,13 @@
|
||||
"when": 1737883733050,
|
||||
"tag": "0021_famous_bruce_banner",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 22,
|
||||
"version": "6",
|
||||
"when": 1737927609085,
|
||||
"tag": "0022_modern_sunfire",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ export const {
|
||||
sessions,
|
||||
users,
|
||||
verificationTokens,
|
||||
sectionCollapseStates,
|
||||
} = schema;
|
||||
|
||||
export type User = InferSelectModel<typeof schema.users>;
|
||||
|
||||
@@ -326,6 +326,24 @@ export const sections = mysqlTable("section", {
|
||||
}),
|
||||
});
|
||||
|
||||
export const sectionCollapseStates = mysqlTable(
|
||||
"section_collapse_state",
|
||||
{
|
||||
userId: varchar({ length: 64 })
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
sectionId: varchar({ length: 64 })
|
||||
.notNull()
|
||||
.references(() => sections.id, { onDelete: "cascade" }),
|
||||
collapsed: boolean().default(false).notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({
|
||||
columns: [table.userId, table.sectionId],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const items = mysqlTable("item", {
|
||||
id: varchar({ length: 64 }).notNull().primaryKey(),
|
||||
sectionId: varchar({ length: 64 })
|
||||
@@ -563,6 +581,18 @@ export const sectionRelations = relations(sections, ({ many, one }) => ({
|
||||
fields: [sections.boardId],
|
||||
references: [boards.id],
|
||||
}),
|
||||
collapseStates: many(sectionCollapseStates),
|
||||
}));
|
||||
|
||||
export const sectionCollapseStateRelations = relations(sectionCollapseStates, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [sectionCollapseStates.userId],
|
||||
references: [users.id],
|
||||
}),
|
||||
section: one(sections, {
|
||||
fields: [sectionCollapseStates.sectionId],
|
||||
references: [sections.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const itemRelations = relations(items, ({ one, many }) => ({
|
||||
|
||||
@@ -312,6 +312,24 @@ export const sections = sqliteTable("section", {
|
||||
}),
|
||||
});
|
||||
|
||||
export const sectionCollapseStates = sqliteTable(
|
||||
"section_collapse_state",
|
||||
{
|
||||
userId: text()
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
sectionId: text()
|
||||
.notNull()
|
||||
.references(() => sections.id, { onDelete: "cascade" }),
|
||||
collapsed: int({ mode: "boolean" }).default(false).notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({
|
||||
columns: [table.userId, table.sectionId],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const items = sqliteTable("item", {
|
||||
id: text().notNull().primaryKey(),
|
||||
sectionId: text()
|
||||
@@ -550,6 +568,18 @@ export const sectionRelations = relations(sections, ({ many, one }) => ({
|
||||
fields: [sections.boardId],
|
||||
references: [boards.id],
|
||||
}),
|
||||
collapseStates: many(sectionCollapseStates),
|
||||
}));
|
||||
|
||||
export const sectionCollapseStateRelations = relations(sectionCollapseStates, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [sectionCollapseStates.userId],
|
||||
references: [users.id],
|
||||
}),
|
||||
section: one(sections, {
|
||||
fields: [sectionCollapseStates.sectionId],
|
||||
references: [sections.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const itemRelations = relations(items, ({ one, many }) => ({
|
||||
|
||||
Reference in New Issue
Block a user