CREATE TABLE IF NOT EXISTS "updates" ( "id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "updates_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1), "user" integer NOT NULL, "mood" integer DEFAULT 0, "description" varchar(2048) ); --> statement-breakpoint CREATE TABLE IF NOT EXISTS "users" ( "id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "users_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1), "name" varchar(26) NOT NULL, "pass" varchar(255) NOT NULL, "registered" timestamp NOT NULL, "bio" varchar(2048) DEFAULT '', "moderator" boolean DEFAULT false, "banned" boolean DEFAULT false, CONSTRAINT "users_name_unique" UNIQUE("name") ); --> statement-breakpoint DO $$ BEGIN ALTER TABLE "updates" ADD CONSTRAINT "updates_user_users_id_fk" FOREIGN KEY ("user") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; EXCEPTION WHEN duplicate_object THEN null; END $$; CREATE TABLE "session" ( "sid" varchar NOT NULL COLLATE "default", "sess" json NOT NULL, "expire" timestamp(6) NOT NULL ) WITH (OIDS=FALSE); ALTER TABLE "session" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE; CREATE INDEX "IDX_session_expire" ON "session" ("expire");