feat(groups): add home board settings (#2321)
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
ALTER TABLE `group` ADD `home_board_id` varchar(64);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `group` ADD `mobile_home_board_id` varchar(64);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `group` ADD `position` smallint;
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `temp_group` (
|
||||
`id` varchar(64) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`position` smallint NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `temp_group`(`id`, `name`, `position`) SELECT `id`, `name`, ROW_NUMBER() OVER(ORDER BY `name`) FROM `group` WHERE `name` != 'everyone';
|
||||
--> statement-breakpoint
|
||||
UPDATE `group` SET `position`=(SELECT `position` FROM `temp_group` WHERE `temp_group`.`id`=`group`.`id`);
|
||||
--> statement-breakpoint
|
||||
DROP TABLE `temp_group`;
|
||||
--> statement-breakpoint
|
||||
UPDATE `group` SET `position` = -1 WHERE `name` = 'everyone';
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `group` MODIFY `position` smallint NOT NULL;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `group` ADD CONSTRAINT `group_home_board_id_board_id_fk` FOREIGN KEY (`home_board_id`) REFERENCES `board`(`id`) ON DELETE set null ON UPDATE no action;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `group` ADD CONSTRAINT `group_mobile_home_board_id_board_id_fk` FOREIGN KEY (`mobile_home_board_id`) REFERENCES `board`(`id`) ON DELETE set null ON UPDATE no action;
|
||||
1811
packages/db/migrations/mysql/meta/0025_snapshot.json
Normal file
1811
packages/db/migrations/mysql/meta/0025_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -176,6 +176,13 @@
|
||||
"when": 1738961147412,
|
||||
"tag": "0024_mean_vin_gonzales",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 25,
|
||||
"version": "5",
|
||||
"when": 1739469710187,
|
||||
"tag": "0025_add-group-home-board-settings",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ const seedEveryoneGroupAsync = async (db: Database) => {
|
||||
await db.insert(groups).values({
|
||||
id: createId(),
|
||||
name: everyoneGroup,
|
||||
position: -1,
|
||||
});
|
||||
console.log("Created group 'everyone' through seed");
|
||||
};
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
COMMIT TRANSACTION;
|
||||
--> statement-breakpoint
|
||||
PRAGMA foreign_keys = OFF;
|
||||
--> statement-breakpoint
|
||||
BEGIN TRANSACTION;
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE `__new_group` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
`owner_id` text,
|
||||
`home_board_id` text,
|
||||
`mobile_home_board_id` text,
|
||||
`position` integer NOT NULL,
|
||||
FOREIGN KEY (`owner_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE set null,
|
||||
FOREIGN KEY (`home_board_id`) REFERENCES `board`(`id`) ON UPDATE no action ON DELETE set null,
|
||||
FOREIGN KEY (`mobile_home_board_id`) REFERENCES `board`(`id`) ON UPDATE no action ON DELETE set null
|
||||
);
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `__new_group`("id", "name", "owner_id", "position") SELECT "id", "name", "owner_id", -1 FROM `group` WHERE "name" = 'everyone';
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `__new_group`("id", "name", "owner_id", "position") SELECT "id", "name", "owner_id", ROW_NUMBER() OVER(ORDER BY "name") FROM `group` WHERE "name" != 'everyone';
|
||||
--> statement-breakpoint
|
||||
DROP TABLE `group`;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `__new_group` RENAME TO `group`;
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `group_name_unique` ON `group` (`name`);
|
||||
--> statement-breakpoint
|
||||
COMMIT TRANSACTION;
|
||||
--> statement-breakpoint
|
||||
PRAGMA foreign_keys = ON;
|
||||
--> statement-breakpoint
|
||||
BEGIN TRANSACTION;
|
||||
1736
packages/db/migrations/sqlite/meta/0025_snapshot.json
Normal file
1736
packages/db/migrations/sqlite/meta/0025_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -176,6 +176,13 @@
|
||||
"when": 1738961178990,
|
||||
"tag": "0024_bitter_scrambler",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 25,
|
||||
"version": "6",
|
||||
"when": 1739468826756,
|
||||
"tag": "0025_add-group-home-board-settings",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
11
packages/db/queries/group.ts
Normal file
11
packages/db/queries/group.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { max } from "drizzle-orm";
|
||||
|
||||
import type { HomarrDatabase } from "../driver";
|
||||
import { groups } from "../schema";
|
||||
|
||||
export const getMaxGroupPositionAsync = async (db: HomarrDatabase) => {
|
||||
return await db
|
||||
.select({ value: max(groups.position) })
|
||||
.from(groups)
|
||||
.then((result) => result[0]?.value ?? 1);
|
||||
};
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from "./item";
|
||||
export * from "./server-setting";
|
||||
export * from "./group";
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
int,
|
||||
mysqlTable,
|
||||
primaryKey,
|
||||
smallint,
|
||||
text,
|
||||
timestamp,
|
||||
tinyint,
|
||||
@@ -150,6 +151,13 @@ export const groups = mysqlTable("group", {
|
||||
ownerId: varchar({ length: 64 }).references(() => users.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
homeBoardId: varchar({ length: 64 }).references(() => boards.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
mobileHomeBoardId: varchar({ length: 64 }).references(() => boards.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
position: smallint().notNull(),
|
||||
});
|
||||
|
||||
export const groupPermissions = mysqlTable("groupPermission", {
|
||||
@@ -499,6 +507,16 @@ export const groupRelations = relations(groups, ({ one, many }) => ({
|
||||
fields: [groups.ownerId],
|
||||
references: [users.id],
|
||||
}),
|
||||
homeBoard: one(boards, {
|
||||
fields: [groups.homeBoardId],
|
||||
references: [boards.id],
|
||||
relationName: "groupRelations__board__homeBoardId",
|
||||
}),
|
||||
mobileHomeBoard: one(boards, {
|
||||
fields: [groups.mobileHomeBoardId],
|
||||
references: [boards.id],
|
||||
relationName: "groupRelations__board__mobileHomeBoardId",
|
||||
}),
|
||||
}));
|
||||
|
||||
export const groupPermissionRelations = relations(groupPermissions, ({ one }) => ({
|
||||
@@ -574,6 +592,12 @@ export const boardRelations = relations(boards, ({ many, one }) => ({
|
||||
}),
|
||||
userPermissions: many(boardUserPermissions),
|
||||
groupPermissions: many(boardGroupPermissions),
|
||||
groupHomes: many(groups, {
|
||||
relationName: "groupRelations__board__homeBoardId",
|
||||
}),
|
||||
mobileHomeBoard: many(groups, {
|
||||
relationName: "groupRelations__board__mobileHomeBoardId",
|
||||
}),
|
||||
}));
|
||||
|
||||
export const sectionRelations = relations(sections, ({ many, one }) => ({
|
||||
|
||||
@@ -133,6 +133,13 @@ export const groups = sqliteTable("group", {
|
||||
ownerId: text().references(() => users.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
homeBoardId: text().references(() => boards.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
mobileHomeBoardId: text().references(() => boards.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
position: int().notNull(),
|
||||
});
|
||||
|
||||
export const groupPermissions = sqliteTable("groupPermission", {
|
||||
@@ -486,6 +493,16 @@ export const groupRelations = relations(groups, ({ one, many }) => ({
|
||||
fields: [groups.ownerId],
|
||||
references: [users.id],
|
||||
}),
|
||||
homeBoard: one(boards, {
|
||||
fields: [groups.homeBoardId],
|
||||
references: [boards.id],
|
||||
relationName: "groupRelations__board__homeBoardId",
|
||||
}),
|
||||
mobileHomeBoard: one(boards, {
|
||||
fields: [groups.mobileHomeBoardId],
|
||||
references: [boards.id],
|
||||
relationName: "groupRelations__board__mobileHomeBoardId",
|
||||
}),
|
||||
}));
|
||||
|
||||
export const groupPermissionRelations = relations(groupPermissions, ({ one }) => ({
|
||||
@@ -561,6 +578,12 @@ export const boardRelations = relations(boards, ({ many, one }) => ({
|
||||
}),
|
||||
userPermissions: many(boardUserPermissions),
|
||||
groupPermissions: many(boardGroupPermissions),
|
||||
groupHomes: many(groups, {
|
||||
relationName: "groupRelations__board__homeBoardId",
|
||||
}),
|
||||
mobileHomeBoard: many(groups, {
|
||||
relationName: "groupRelations__board__mobileHomeBoardId",
|
||||
}),
|
||||
}));
|
||||
|
||||
export const sectionRelations = relations(sections, ({ many, one }) => ({
|
||||
|
||||
Reference in New Issue
Block a user