CREATE TABLE "modules" (
	"module_id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"active" boolean DEFAULT false,
	"roles" text DEFAULT '["view", "systemAdmin"]' NOT NULL,
	"add_User" text DEFAULT 'LST_System' NOT NULL,
	"add_Date" timestamp DEFAULT now(),
	"upd_User" text DEFAULT 'LST_System' NOT NULL,
	"upd_date" timestamp DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "roles" (
	"role_id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"add_User" text DEFAULT 'LST_System' NOT NULL,
	"add_Date" timestamp DEFAULT now(),
	"upd_User" text DEFAULT 'LST_System' NOT NULL,
	"upd_date" timestamp DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "userRoles" (
	"user_id" uuid NOT NULL,
	"role_id" uuid NOT NULL,
	"module_id" uuid NOT NULL,
	"role" text NOT NULL,
	"add_User" text DEFAULT 'LST_System' NOT NULL,
	"add_Date" timestamp DEFAULT now(),
	"upd_User" text DEFAULT 'LST_System' NOT NULL,
	"upd_date" timestamp DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "users" (
	"user_id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"username" text NOT NULL,
	"email" text NOT NULL,
	"password" text NOT NULL,
	"passwordToken" text,
	"passwordTokenExpires" timestamp,
	"active" boolean DEFAULT true NOT NULL,
	"pingcode" numeric,
	"role" text DEFAULT 'user' NOT NULL,
	"lastLogin" timestamp DEFAULT now(),
	"add_User" text DEFAULT 'LST_System' NOT NULL,
	"add_Date" timestamp DEFAULT now(),
	"upd_User" text DEFAULT 'LST_System' NOT NULL,
	"upd_date" timestamp DEFAULT now()
);
--> statement-breakpoint
ALTER TABLE "userRoles" ADD CONSTRAINT "userRoles_user_id_users_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("user_id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "userRoles" ADD CONSTRAINT "userRoles_role_id_roles_role_id_fk" FOREIGN KEY ("role_id") REFERENCES "public"."roles"("role_id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "userRoles" ADD CONSTRAINT "userRoles_module_id_modules_module_id_fk" FOREIGN KEY ("module_id") REFERENCES "public"."modules"("module_id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "module_name" ON "modules" USING btree ("name");--> statement-breakpoint
CREATE UNIQUE INDEX "role_name" ON "roles" USING btree ("name");--> statement-breakpoint
CREATE UNIQUE INDEX "user_module_unique" ON "userRoles" USING btree ("user_id","module_id");--> statement-breakpoint
CREATE UNIQUE INDEX "username" ON "users" USING btree ("username");