ALTER TABLE "mailbox"."mail_label"
    ADD COLUMN "sort" int;

CREATE TABLE "mailbox"."mail_extension" (
    "id" varchar(40) NOT NULL,
    "mail_id" varchar(40) NOT NULL,
    "days" int2,
    "extension_reason" text,
    "create_time" datatime,
    CONSTRAINT "mail_extension_pkey" PRIMARY KEY ("id")
);

COMMENT ON COLUMN "mailbox"."mail_extension"."days" IS '延期天数';

COMMENT ON COLUMN "mailbox"."mail_extension"."extension_reason" IS '延期理由';

COMMENT ON TABLE "mailbox"."mail_extension" IS '信件延期';


INSERT INTO mail_extension ( ID, mail_id, days, extension_reason )
SELECT
    extension_request_id,
    ID,
    extension_days,
    extension_reason
FROM
    mail
WHERE
    extension_state = 'applying'