49 lines
1.8 KiB
SQL
49 lines
1.8 KiB
SQL
CREATE TABLE "memberships" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"organization_id" text NOT NULL,
|
|
"role" text DEFAULT 'user' NOT NULL,
|
|
"business_role" text DEFAULT 'sales_support' NOT NULL,
|
|
"permissions" text[] DEFAULT '{}' NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "organizations" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"name" text NOT NULL,
|
|
"slug" text NOT NULL,
|
|
"image_url" text,
|
|
"plan" text DEFAULT 'free' NOT NULL,
|
|
"created_by" text NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "products" (
|
|
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "products_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
|
"organization_id" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"category" text NOT NULL,
|
|
"description" text NOT NULL,
|
|
"photo_url" text NOT NULL,
|
|
"price" double precision NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "users" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"name" text NOT NULL,
|
|
"email" text NOT NULL,
|
|
"password_hash" text NOT NULL,
|
|
"system_role" text DEFAULT 'user' NOT NULL,
|
|
"image" text,
|
|
"active_organization_id" text,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "organizations_slug_idx" ON "organizations" USING btree ("slug");--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "users_email_idx" ON "users" USING btree ("email");
|