CREATE TABLE IF NOT EXISTS "file"
(
    "id"           UUID    NOT NULL PRIMARY KEY DEFAULT uuid_generate_v7(),
    "filename"     VARCHAR NOT NULL,
    "content_type" VARCHAR NOT NULL,
    "url"          VARCHAR NOT NULL,
    "size"         INT8    NOT NULL
);

CREATE TABLE IF NOT EXISTS "message_attachment"
(
    "message_id"    UUID NOT NULL REFERENCES "message" ON DELETE CASCADE,
    "attachment_id" UUID NOT NULL REFERENCES "file" ON DELETE CASCADE,
    "order"         INT2 NOT NULL,
    PRIMARY KEY ("message_id", "attachment_id")
);