-- Table: adempiere.jp_org_history

-- DROP TABLE adempiere.jp_org_history;

CREATE TABLE adempiere.jp_org_history
(
    ad_client_id numeric(10,0) NOT NULL,
    ad_org_id numeric(10,0) NOT NULL,
    c_location_id numeric(10,0) DEFAULT NULL::numeric,
    created timestamp without time zone NOT NULL DEFAULT statement_timestamp(),
    createdby numeric(10,0) NOT NULL,
    datefrom timestamp without time zone NOT NULL,
    dateto timestamp without time zone NOT NULL,
    description character varying(255) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
    isactive character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT 'Y'::bpchar,
    jp_businessunit_id numeric(10,0) DEFAULT NULL::numeric,
    jp_org_history_id numeric(10,0) NOT NULL,
    jp_org_history_uu character varying(36) COLLATE pg_catalog."default" DEFAULT NULL::character varying,
    name character varying(60) COLLATE pg_catalog."default" NOT NULL,
    supervisor_id numeric(10,0) DEFAULT NULL::numeric,
    updated timestamp without time zone NOT NULL DEFAULT statement_timestamp(),
    updatedby numeric(10,0) NOT NULL,
    CONSTRAINT jp_org_history_key PRIMARY KEY (jp_org_history_id),
    CONSTRAINT jp_org_history_uu_idx UNIQUE (jp_org_history_uu)
,
    CONSTRAINT adclient_jporghistory FOREIGN KEY (ad_client_id)
        REFERENCES adempiere.ad_client (ad_client_id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        DEFERRABLE INITIALLY DEFERRED,
    CONSTRAINT adorg_jporghistory FOREIGN KEY (ad_org_id)
        REFERENCES adempiere.ad_org (ad_org_id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        DEFERRABLE INITIALLY DEFERRED,
    CONSTRAINT clocation_jporghistory FOREIGN KEY (c_location_id)
        REFERENCES adempiere.c_location (c_location_id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        DEFERRABLE INITIALLY DEFERRED,
    CONSTRAINT jpbusinessunit_jporghistory FOREIGN KEY (jp_businessunit_id)
        REFERENCES adempiere.jp_businessunit (jp_businessunit_id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        DEFERRABLE INITIALLY DEFERRED,
    CONSTRAINT supervisor_jporghistory FOREIGN KEY (supervisor_id)
        REFERENCES adempiere.ad_user (ad_user_id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        DEFERRABLE INITIALLY DEFERRED,
    CONSTRAINT jp_org_history_isactive_check CHECK (isactive = ANY (ARRAY['Y'::bpchar, 'N'::bpchar]))
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE adempiere.jp_org_history
    OWNER to adempiere;

-- Index: jp_org_history_org_id

-- DROP INDEX adempiere.jp_org_history_org_id;

CREATE INDEX jp_org_history_org_id
    ON adempiere.jp_org_history USING btree
    (ad_org_id)
    TABLESPACE pg_default;