mirror of
https://github.com/ajnart/homarr.git
synced 2026-01-31 11:49:14 +01:00
* feat: add user groups * wip: add unit tests * wip: add more tests and normalized name for creation and update * test: add unit tests for group router * fix: type issues, missing mysql schema, rename column creator_id to owner_id * fix: lint and format issues * fix: deepsource issues * fix: forgot to add log message * fix: build not working * chore: address pull request feedback * feat: add mysql migration and fix merge conflicts * fix: format issue and test issue
168 lines
7.5 KiB
SQL
168 lines
7.5 KiB
SQL
CREATE TABLE `account` (
|
|
`userId` varchar(256) NOT NULL,
|
|
`type` text NOT NULL,
|
|
`provider` varchar(256) NOT NULL,
|
|
`providerAccountId` varchar(256) NOT NULL,
|
|
`refresh_token` text,
|
|
`access_token` text,
|
|
`expires_at` int,
|
|
`token_type` text,
|
|
`scope` text,
|
|
`id_token` text,
|
|
`session_state` text,
|
|
CONSTRAINT `account_provider_providerAccountId_pk` PRIMARY KEY(`provider`,`providerAccountId`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `app` (
|
|
`id` varchar(256) NOT NULL,
|
|
`name` text NOT NULL,
|
|
`description` text,
|
|
`icon_url` text NOT NULL,
|
|
`href` text,
|
|
CONSTRAINT `app_id` PRIMARY KEY(`id`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `boardPermission` (
|
|
`board_id` text NOT NULL,
|
|
`user_id` text NOT NULL,
|
|
`permission` text NOT NULL,
|
|
CONSTRAINT `boardPermission_board_id_user_id_permission_pk` PRIMARY KEY(`board_id`,`user_id`,`permission`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `board` (
|
|
`id` varchar(256) NOT NULL,
|
|
`name` varchar(256) NOT NULL,
|
|
`is_public` boolean NOT NULL DEFAULT false,
|
|
`creator_id` text,
|
|
`page_title` text,
|
|
`meta_title` text,
|
|
`logo_image_url` text,
|
|
`favicon_image_url` text,
|
|
`background_image_url` text,
|
|
`background_image_attachment` text NOT NULL DEFAULT ('fixed'),
|
|
`background_image_repeat` text NOT NULL DEFAULT ('no-repeat'),
|
|
`background_image_size` text NOT NULL DEFAULT ('cover'),
|
|
`primary_color` text NOT NULL DEFAULT ('#fa5252'),
|
|
`secondary_color` text NOT NULL DEFAULT ('#fd7e14'),
|
|
`opacity` int NOT NULL DEFAULT 100,
|
|
`custom_css` text,
|
|
`column_count` int NOT NULL DEFAULT 10,
|
|
CONSTRAINT `board_id` PRIMARY KEY(`id`),
|
|
CONSTRAINT `board_name_unique` UNIQUE(`name`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `groupMember` (
|
|
`groupId` varchar(256) NOT NULL,
|
|
`userId` varchar(256) NOT NULL,
|
|
CONSTRAINT `groupMember_groupId_userId_pk` PRIMARY KEY(`groupId`,`userId`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `groupPermission` (
|
|
`groupId` varchar(256) NOT NULL,
|
|
`permission` text NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `group` (
|
|
`id` varchar(256) NOT NULL,
|
|
`name` varchar(64) NOT NULL,
|
|
`owner_id` varchar(256),
|
|
CONSTRAINT `group_id` PRIMARY KEY(`id`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `integration_item` (
|
|
`item_id` varchar(256) NOT NULL,
|
|
`integration_id` varchar(256) NOT NULL,
|
|
CONSTRAINT `integration_item_item_id_integration_id_pk` PRIMARY KEY(`item_id`,`integration_id`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `integrationSecret` (
|
|
`kind` varchar(16) NOT NULL,
|
|
`value` text NOT NULL,
|
|
`updated_at` timestamp NOT NULL,
|
|
`integration_id` varchar(256) NOT NULL,
|
|
CONSTRAINT `integrationSecret_integration_id_kind_pk` PRIMARY KEY(`integration_id`,`kind`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `integration` (
|
|
`id` varchar(256) NOT NULL,
|
|
`name` text NOT NULL,
|
|
`url` text NOT NULL,
|
|
`kind` varchar(128) NOT NULL,
|
|
CONSTRAINT `integration_id` PRIMARY KEY(`id`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `invite` (
|
|
`id` varchar(256) NOT NULL,
|
|
`token` varchar(512) NOT NULL,
|
|
`expiration_date` timestamp NOT NULL,
|
|
`creator_id` varchar(256) NOT NULL,
|
|
CONSTRAINT `invite_id` PRIMARY KEY(`id`),
|
|
CONSTRAINT `invite_token_unique` UNIQUE(`token`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `item` (
|
|
`id` varchar(256) NOT NULL,
|
|
`section_id` varchar(256) NOT NULL,
|
|
`kind` text NOT NULL,
|
|
`x_offset` int NOT NULL,
|
|
`y_offset` int NOT NULL,
|
|
`width` int NOT NULL,
|
|
`height` int NOT NULL,
|
|
`options` text NOT NULL DEFAULT ('{"json": {}}'),
|
|
CONSTRAINT `item_id` PRIMARY KEY(`id`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `section` (
|
|
`id` varchar(256) NOT NULL,
|
|
`board_id` varchar(256) NOT NULL,
|
|
`kind` text NOT NULL,
|
|
`position` int NOT NULL,
|
|
`name` text,
|
|
CONSTRAINT `section_id` PRIMARY KEY(`id`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `session` (
|
|
`sessionToken` varchar(512) NOT NULL,
|
|
`userId` varchar(256) NOT NULL,
|
|
`expires` timestamp NOT NULL,
|
|
CONSTRAINT `session_sessionToken` PRIMARY KEY(`sessionToken`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `user` (
|
|
`id` varchar(256) NOT NULL,
|
|
`name` text,
|
|
`email` text,
|
|
`emailVerified` timestamp,
|
|
`image` text,
|
|
`password` text,
|
|
`salt` text,
|
|
CONSTRAINT `user_id` PRIMARY KEY(`id`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `verificationToken` (
|
|
`identifier` varchar(256) NOT NULL,
|
|
`token` varchar(512) NOT NULL,
|
|
`expires` timestamp NOT NULL,
|
|
CONSTRAINT `verificationToken_identifier_token_pk` PRIMARY KEY(`identifier`,`token`)
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `userId_idx` ON `account` (`userId`);--> statement-breakpoint
|
|
CREATE INDEX `integration_secret__kind_idx` ON `integrationSecret` (`kind`);--> statement-breakpoint
|
|
CREATE INDEX `integration_secret__updated_at_idx` ON `integrationSecret` (`updated_at`);--> statement-breakpoint
|
|
CREATE INDEX `integration__kind_idx` ON `integration` (`kind`);--> statement-breakpoint
|
|
CREATE INDEX `user_id_idx` ON `session` (`userId`);--> statement-breakpoint
|
|
ALTER TABLE `account` ADD CONSTRAINT `account_userId_user_id_fk` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `boardPermission` ADD CONSTRAINT `boardPermission_board_id_board_id_fk` FOREIGN KEY (`board_id`) REFERENCES `board`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `boardPermission` ADD CONSTRAINT `boardPermission_user_id_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `board` ADD CONSTRAINT `board_creator_id_user_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `user`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `groupMember` ADD CONSTRAINT `groupMember_groupId_group_id_fk` FOREIGN KEY (`groupId`) REFERENCES `group`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `groupMember` ADD CONSTRAINT `groupMember_userId_user_id_fk` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `groupPermission` ADD CONSTRAINT `groupPermission_groupId_group_id_fk` FOREIGN KEY (`groupId`) REFERENCES `group`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `group` ADD CONSTRAINT `group_owner_id_user_id_fk` FOREIGN KEY (`owner_id`) REFERENCES `user`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `integration_item` ADD CONSTRAINT `integration_item_item_id_item_id_fk` FOREIGN KEY (`item_id`) REFERENCES `item`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `integration_item` ADD CONSTRAINT `integration_item_integration_id_integration_id_fk` FOREIGN KEY (`integration_id`) REFERENCES `integration`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `integrationSecret` ADD CONSTRAINT `integrationSecret_integration_id_integration_id_fk` FOREIGN KEY (`integration_id`) REFERENCES `integration`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `invite` ADD CONSTRAINT `invite_creator_id_user_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `item` ADD CONSTRAINT `item_section_id_section_id_fk` FOREIGN KEY (`section_id`) REFERENCES `section`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `section` ADD CONSTRAINT `section_board_id_board_id_fk` FOREIGN KEY (`board_id`) REFERENCES `board`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE `session` ADD CONSTRAINT `session_userId_user_id_fk` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action; |