
-- drop public.terminal_dict

DROP TABLE IF EXISTS public.terminal_dict;
DROP SEQUENCE IF EXISTS public.terminal_dict_id_seq;

-- drop public.device_dict

DROP TABLE IF EXISTS public.device_dict;
DROP SEQUENCE IF EXISTS public.device_dict_id_seq;

-- drop public.terminal_type_dict

DROP TABLE IF EXISTS public.terminal_type_dict;
DROP SEQUENCE IF EXISTS public.terminal_type_dict_id_seq;

-- drop public.device_type_dict

DROP TABLE IF EXISTS public.device_type_dict;
DROP SEQUENCE IF EXISTS public.device_type_dict_id_seq;


-- public.device_type_dict

CREATE SEQUENCE IF NOT EXISTS public.device_type_dict_id_seq;

ALTER SEQUENCE public.device_type_dict_id_seq
    OWNER TO postgres;

CREATE TABLE IF NOT EXISTS public.device_type_dict
(
    id integer NOT NULL DEFAULT nextval('device_type_dict_id_seq'::regclass),
    name character varying(64) COLLATE pg_catalog."default" NOT NULL,
    description character varying(512) COLLATE pg_catalog."default",
    ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT device_type_dict_id_PrimaryKey PRIMARY KEY (id)
)
TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.device_type_dict
    OWNER to postgres;


-- public.terminal_type_dict

CREATE SEQUENCE IF NOT EXISTS public.terminal_type_dict_id_seq;

ALTER SEQUENCE public.terminal_type_dict_id_seq
    OWNER TO postgres;

CREATE TABLE IF NOT EXISTS public.terminal_type_dict
(
    id integer NOT NULL DEFAULT nextval('terminal_type_dict_id_seq'::regclass),
    name character varying(64) COLLATE pg_catalog."default" NOT NULL,
    description character varying(512) COLLATE pg_catalog."default",
    ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT terminal_type_dict_id_PrimaryKey PRIMARY KEY (id)
)
TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.terminal_type_dict
    OWNER to postgres;



-- public.device_dict

CREATE SEQUENCE IF NOT EXISTS public.device_dict_id_seq;

ALTER SEQUENCE public.device_dict_id_seq
    OWNER TO postgres;

CREATE TABLE IF NOT EXISTS public.device_dict
(
    id integer NOT NULL DEFAULT nextval('device_dict_id_seq'::regclass),
    model character varying(32) COLLATE pg_catalog."default" NOT NULL,
    type_dict_id integer NOT NULL,
    name character varying(64) COLLATE pg_catalog."default" NOT NULL,
    description character varying(512) COLLATE pg_catalog."default",
    ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT device_dict_id_PrimaryKey PRIMARY KEY (id),
    CONSTRAINT device_dict_ForeignKey_device_type_dict_id FOREIGN KEY ("type_dict_id")
        REFERENCES public.device_type_dict (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID
)
TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.device_dict
    OWNER to postgres;

-- public.terminal_dict

CREATE SEQUENCE IF NOT EXISTS public.terminal_dict_id_seq;

ALTER SEQUENCE public.terminal_dict_id_seq
    OWNER TO postgres;

CREATE TABLE IF NOT EXISTS public.terminal_dict
(
    id integer NOT NULL DEFAULT nextval('terminal_dict_id_seq'::regclass),
    device_dict_id integer NOT NULL,
    idx integer NOT NULL,
    terminal_type_dict_id integer NOT NULL,
    name character varying(64) COLLATE pg_catalog."default" NOT NULL,
    description character varying(512) COLLATE pg_catalog."default",
    ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT terminal_dict_id_PrimaryKey PRIMARY KEY (id),
    CONSTRAINT terminal_dict_ForeignKey_device_dict_id FOREIGN KEY ("device_dict_id")
        REFERENCES public.device_dict (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID,
    CONSTRAINT terminal_dict_ForeignKey_terminal_type_dict_id FOREIGN KEY ("terminal_type_dict_id")
        REFERENCES public.terminal_type_dict (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID
)
TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.terminal_dict
    OWNER to postgres;

