-- 创建 purchase_registration 表
CREATE TABLE purchase_registration
(
    id                        BIGSERIAL PRIMARY KEY,             -- 主键ID，自动递增
    supplier_id               BIGINT         NOT NULL,           -- 供应商名称ID，不允许为空
    supplier_name             VARCHAR(255)   NOT NULL,           -- 供应商名称，不允许为空
    unit                      VARCHAR(50)    NOT NULL,           -- 单位，不允许为空
    coal_id                   BIGINT         NOT NULL,           -- 煤种类型id
    coal                      VARCHAR(255),                      -- 煤种类型
    purchase_quantity         DECIMAL(10, 2) NOT NULL,           -- 采购数量，不允许为空
    price_including_tax       DECIMAL(10, 2) NOT NULL,           -- 单价（含税），不允许为空
    total_price_including_tax DECIMAL(10, 2) NOT NULL,           -- 总价（含税），不允许为空
    tax_rate                  DECIMAL(5, 2)  NOT NULL,           -- 税率，不允许为空
    price_excluding_tax       DECIMAL(10, 2) NOT NULL,           -- 不含税单价，不允许为空
    total_price_excluding_tax DECIMAL(10, 2) NOT NULL,           -- 不含税总价，不允许为空
    registrant_id             BIGINT         NOT NULL,           -- 登记人id，不允许为空
    registration_date         DATE           NOT NULL,           -- 登记日期，不允许为空
    freight                   DECIMAL(10, 2) NOT NULL,           -- 运费

    deleted                   INT            NOT NULL DEFAULT 0, -- 软删除标志：0=未删除，1=已删除
    create_by                 VARCHAR(255),                      -- 创建人用户名
    create_time               TIMESTAMP WITHOUT TIME ZONE,       -- 创建时间，默认当前时间
    update_by                 VARCHAR(255),                      -- 最后更新人用户名
    update_time               TIMESTAMP WITHOUT TIME ZONE        -- 最后更新时间，默认当前时间
);

-- 为表添加注释
COMMENT ON TABLE purchase_registration IS '采购登记表';

-- 为字段添加注释
COMMENT ON COLUMN purchase_registration.id IS '主键ID';
COMMENT ON COLUMN purchase_registration.supplier_name IS '供应商名称';
COMMENT ON COLUMN purchase_registration.unit IS '单位';
COMMENT ON COLUMN purchase_registration.coal IS '煤种类型';
COMMENT ON COLUMN purchase_registration.purchase_quantity IS '采购数量';
COMMENT ON COLUMN purchase_registration.price_including_tax IS '单价（含税）';
COMMENT ON COLUMN purchase_registration.total_price_including_tax IS '总价（含税）';
COMMENT ON COLUMN purchase_registration.tax_rate IS '税率';
COMMENT ON COLUMN purchase_registration.price_excluding_tax IS '不含税单价';
COMMENT ON COLUMN purchase_registration.total_price_excluding_tax IS '不含税总价';
COMMENT ON COLUMN purchase_registration.registrant_id IS '登记人id';
COMMENT ON COLUMN purchase_registration.registration_date IS '登记日期';
COMMENT ON COLUMN purchase_registration.freight IS '运费';

COMMENT ON COLUMN purchase_registration.deleted IS '软删除标志，0=未删除，1=已删除';
COMMENT ON COLUMN purchase_registration.create_by IS '创建该记录的用户';
COMMENT ON COLUMN purchase_registration.create_time IS '记录创建时间';
COMMENT ON COLUMN purchase_registration.update_by IS '最后修改该记录的用户';
COMMENT ON COLUMN purchase_registration.update_time IS '记录最后更新时间';