mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 23:34:04 +00:00
18 lines
938 B
SQL
18 lines
938 B
SQL
CREATE TABLE "households" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"name" text NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "members" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"household_id" uuid NOT NULL,
|
|
"telegram_user_id" text NOT NULL,
|
|
"display_name" text NOT NULL,
|
|
"is_admin" integer DEFAULT 0 NOT NULL,
|
|
"joined_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "members" ADD CONSTRAINT "members_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
CREATE INDEX "members_household_idx" ON "members" USING btree ("household_id");--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "members_household_tg_user_unique" ON "members" USING btree ("household_id","telegram_user_id"); |