CREATE TABLE "sessions" (
    "id"               uuid PRIMARY KEY,
    "user_id"          int NOT NULL,
    "refresh_token"    varchar NOT NULL,
    "user_agent"       varchar NOT NULL,
    "client_ip"        varchar NOT NULL,
    "is_blocked"       BOOLEAN NOT NULL DEFAULT false,
    "expires_at"       TIMESTAMPTZ NOT NULL,
    "exportcompany_id" int NULL,
    "packhouse_id"     int NULL,
    "exitpoint_id"     int NULL,
    "created_at"       TIMESTAMPTZ NOT NULL DEFAULT(now())
);

ALTER TABLE "sessions" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "sessions" ADD FOREIGN KEY ("exportcompany_id") REFERENCES "exportcompanies" ("id");
ALTER TABLE "sessions" ADD FOREIGN KEY ("packhouse_id") REFERENCES "packhouses" ("id");
ALTER TABLE "sessions" ADD FOREIGN KEY ("exitpoint_id") REFERENCES "exitpoints" ("id");
