udemy-go-web-1/sql/schema.sql
2024-07-30 22:02:26 +02:00

97 lines
4.2 KiB
SQL

-- Adminer 4.8.1 PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1) dump
CREATE SEQUENCE reservations_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1;
CREATE TABLE "public"."reservations" (
"id" integer DEFAULT nextval('reservations_id_seq') NOT NULL,
"first_name" character varying(255) DEFAULT '' NOT NULL,
"last_name" character varying(255) DEFAULT '' NOT NULL,
"email" character varying(255) NOT NULL,
"phone" character varying(255) DEFAULT '' NOT NULL,
"start_date" date NOT NULL,
"end_date" date NOT NULL,
"room_id" integer NOT NULL,
"created_at" timestamp NOT NULL,
"updated_at" timestamp NOT NULL,
"processed" integer DEFAULT '0' NOT NULL,
CONSTRAINT "reservations_pkey" PRIMARY KEY ("id")
) WITH (oids = false);
CREATE INDEX "reservations_email_idx" ON "public"."reservations" USING btree ("email");
CREATE INDEX "reservations_last_name_idx" ON "public"."reservations" USING btree ("last_name");
CREATE SEQUENCE restrictions_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1;
CREATE TABLE "public"."restrictions" (
"id" integer DEFAULT nextval('restrictions_id_seq') NOT NULL,
"restriction_name" character varying(255) NOT NULL,
"created_at" timestamp NOT NULL,
"updated_at" timestamp NOT NULL,
CONSTRAINT "restrictions_pkey" PRIMARY KEY ("id")
) WITH (oids = false);
CREATE SEQUENCE room_restrictions_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1;
CREATE TABLE "public"."room_restrictions" (
"id" integer DEFAULT nextval('room_restrictions_id_seq') NOT NULL,
"start_date" date NOT NULL,
"end_date" date NOT NULL,
"room_id" integer NOT NULL,
"reservation_id" integer,
"restriction_id" integer NOT NULL,
"created_at" timestamp NOT NULL,
"updated_at" timestamp NOT NULL,
CONSTRAINT "room_restrictions_pkey" PRIMARY KEY ("id")
) WITH (oids = false);
CREATE INDEX "room_restrictions_reservation_id_idx" ON "public"."room_restrictions" USING btree ("reservation_id");
CREATE INDEX "room_restrictions_room_id_idx" ON "public"."room_restrictions" USING btree ("room_id");
CREATE INDEX "room_restrictions_start_date_end_date_idx" ON "public"."room_restrictions" USING btree ("start_date", "end_date");
CREATE SEQUENCE rooms_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1;
CREATE TABLE "public"."rooms" (
"id" integer DEFAULT nextval('rooms_id_seq') NOT NULL,
"room_name" character varying(255) NOT NULL,
"created_at" timestamp NOT NULL,
"updated_at" timestamp NOT NULL,
CONSTRAINT "rooms_pkey" PRIMARY KEY ("id")
) WITH (oids = false);
CREATE TABLE "public"."schema_migration" (
"version" character varying(14) NOT NULL,
CONSTRAINT "schema_migration_pkey" PRIMARY KEY ("version"),
CONSTRAINT "schema_migration_version_idx" UNIQUE ("version")
) WITH (oids = false);
CREATE SEQUENCE users_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1;
CREATE TABLE "public"."users" (
"id" integer DEFAULT nextval('users_id_seq') NOT NULL,
"first_name" character varying(255) DEFAULT '' NOT NULL,
"last_name" character varying(255) DEFAULT '' NOT NULL,
"email" character varying(255) NOT NULL,
"password" character varying(60) NOT NULL,
"access_level" integer DEFAULT '1' NOT NULL,
"created_at" timestamp NOT NULL,
"updated_at" timestamp NOT NULL,
CONSTRAINT "users_email_idx" UNIQUE ("email"),
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
) WITH (oids = false);
ALTER TABLE ONLY "public"."reservations" ADD CONSTRAINT "reservations_rooms_id_fk" FOREIGN KEY (room_id) REFERENCES rooms(id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE;
ALTER TABLE ONLY "public"."room_restrictions" ADD CONSTRAINT "room_restrictions_reservations_id_fk" FOREIGN KEY (reservation_id) REFERENCES reservations(id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE;
ALTER TABLE ONLY "public"."room_restrictions" ADD CONSTRAINT "room_restrictions_restrictions_id_fk" FOREIGN KEY (restriction_id) REFERENCES restrictions(id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE;
ALTER TABLE ONLY "public"."room_restrictions" ADD CONSTRAINT "room_restrictions_rooms_id_fk" FOREIGN KEY (room_id) REFERENCES rooms(id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE;