-- Table: public.asyncmotor_model

-- DROP
DROP TABLE IF EXISTS public.asyncmotor_model;
DROP SEQUENCE IF EXISTS public.asyncmotor_model_id_seq;

-- CREATE
CREATE SEQUENCE IF NOT EXISTS public.asyncmotor_model_id_seq;

CREATE TABLE IF NOT EXISTS public.asyncmotor_model
(
    id integer NOT NULL DEFAULT nextval('asyncmotor_model_id_seq'::regclass),
    component_id INTEGER NOT NULL DEFAULT -1,

    version INTEGER NOT NULL DEFAULT 0,

    nl_u DOUBLE PRECISION NOT NULL DEFAULT 0, -- 空载试验 1~35000
    nl_i DOUBLE PRECISION NOT NULL DEFAULT 0, -- 空载试验 1~65535
    nl_p DOUBLE PRECISION NOT NULL DEFAULT 0, -- 空载试验 1~65535
    stall_f1 DOUBLE PRECISION NOT NULL DEFAULT 50, -- 堵转试验 0~50
    stall_f2 DOUBLE PRECISION NOT NULL DEFAULT -1, -- 堵转试验 0~50
    stall_u DOUBLE PRECISION NOT NULL DEFAULT -1, -- 堵转试验 1~35000
    stall_i DOUBLE PRECISION NOT NULL DEFAULT -1, -- 堵转试验 1~
    stall_p DOUBLE PRECISION NOT NULL DEFAULT -1, -- 堵转试验 1~
    dc_ra DOUBLE PRECISION NOT NULL DEFAULT 0, -- 直流电阻 0~
    dc_rb DOUBLE PRECISION NOT NULL DEFAULT 0, -- 直流电阻 0~
    dc_rc DOUBLE PRECISION NOT NULL DEFAULT 0, -- 直流电阻 0~
    zargs jsonb NOT NULL DEFAULT '{}', -- 阻抗参数 -- TODO: 如何存储这块数据?

    op integer NOT NULL DEFAULT '-1'::integer,
    ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT asyncmotor_model_id_PrimaryKey PRIMARY KEY (id),
    CONSTRAINT asyncmotor_model_ForeignKey_component_id FOREIGN KEY (component_id)
        REFERENCES public.component (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.asyncmotor_model
    OWNER to postgres;

COMMENT ON TABLE public.asyncmotor_model
    IS '存储异步电动机的模型参数';