Skip to content

Commit ff4dd1b

Browse files
feat(db): user invitations and rbac (#1937)
* feat: add user_canvases table and related functionality - Created a new table "user_canvases" to store user-specific canvas data including scale, x, and y coordinates. - Implemented row-level security and foreign key constraints for user and canvas references. - Added migration to copy existing canvas data to the new user_canvases table. - Updated project and canvas routers to handle user canvas retrieval and updates. - Introduced utility functions for creating default user canvas entries. - Adjusted relevant components to utilize user canvas data instead of general canvas data. * feat: add project invitations and roles - Introduced a new "project_invitations" table with fields for inviter, invitee, status, role, and expiration. - Created ENUM types for "invitation_status" and "project_role". - Updated "user_projects" to include a role field and set default values for existing records. - Added foreign key constraints for project and user references in invitations. - Implemented row-level security for the new invitations table. - Updated relevant schemas and seed data to accommodate new functionality.
1 parent 414371a commit ff4dd1b

File tree

14 files changed

+918
-68
lines changed

14 files changed

+918
-68
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
CREATE TYPE "public"."invitation_status" AS ENUM('pending', 'accepted', 'expired');--> statement-breakpoint
2+
CREATE TYPE "public"."project_role" AS ENUM('owner', 'admin');--> statement-breakpoint
3+
CREATE TABLE "project_invitations" (
4+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
5+
"project_id" uuid NOT NULL,
6+
"inviter_id" uuid NOT NULL,
7+
"invitee_email" varchar NOT NULL,
8+
"status" "invitation_status" DEFAULT 'pending' NOT NULL,
9+
"token" varchar NOT NULL,
10+
"role" "project_role" NOT NULL,
11+
"expires_at" timestamp with time zone NOT NULL,
12+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
13+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
14+
CONSTRAINT "project_invitations_token_unique" UNIQUE("token")
15+
);
16+
--> statement-breakpoint
17+
ALTER TABLE "project_invitations" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
18+
19+
ALTER TABLE "user_projects" ADD COLUMN "role" "project_role";--> statement-breakpoint
20+
-- Set all existing records to 'owner' role (assuming existing users should be owners)
21+
UPDATE "user_projects" SET "role" = 'owner' WHERE "role" IS NULL;
22+
-- Make the role column NOT NULL after setting default values
23+
ALTER TABLE "user_projects" ALTER COLUMN "role" SET NOT NULL;
24+
25+
ALTER TABLE "project_invitations" ADD CONSTRAINT "project_invitations_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
26+
ALTER TABLE "project_invitations" ADD CONSTRAINT "project_invitations_inviter_id_users_id_fk" FOREIGN KEY ("inviter_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;

0 commit comments

Comments
 (0)