feat: Implement role-based access control and enhance permissions system

This commit is contained in:
beilunyang
2024-12-27 13:35:29 +08:00
parent e815d1bec5
commit 5a7c17752a
22 changed files with 1888 additions and 39 deletions

View File

@@ -0,0 +1,33 @@
CREATE TABLE `permission` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`description` text,
`created_at` integer,
`updated_at` integer
);
--> statement-breakpoint
CREATE TABLE `role_permission` (
`role_id` text NOT NULL,
`permission_id` text NOT NULL,
`created_at` integer,
PRIMARY KEY(`role_id`, `permission_id`),
FOREIGN KEY (`role_id`) REFERENCES `role`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`permission_id`) REFERENCES `permission`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `role` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`description` text,
`created_at` integer,
`updated_at` integer
);
--> statement-breakpoint
CREATE TABLE `user_role` (
`user_id` text NOT NULL,
`role_id` text NOT NULL,
`created_at` integer,
PRIMARY KEY(`user_id`, `role_id`),
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`role_id`) REFERENCES `role`(`id`) ON UPDATE no action ON DELETE cascade
);