SET client_encoding = 'WIN1251';
SET default_tablespace = '';
SET default_with_oids = false;

CREATE TABLE oik.conforms (
    fullpath character(100),
    fieldname character(20),
    rusname character(20),
    refname character(50),
    permissions text
);
CREATE TABLE oik.coretable (
    recid integer,
    fullpath character(100),
    datecreate timestamp without time zone,
    date1 timestamp without time zone,
    date2 timestamp without time zone,
    object character(50),
    comment text,
    num integer,
    state integer
);
CREATE TABLE oik.equipment (
    fullpath character(100),
    fulldescription character(100),
    description character(50),
    code character(50)
);
CREATE TABLE oik.history (
    idx integer,
    recid integer,
    datecreate timestamp without time zone,
    uid integer,
    kind integer,
    comment text,
    reccontext text,
    signature text
);
CREATE TABLE oik.mags (
    fullpath character(100),
    fulldescription character(150),
    description character(20),
    exttable character(8),
    sign bytea
);
CREATE TABLE oik.userforms (
    fullpath character(100),
    rtype integer,
    seqid integer,
    formname character(100),
    formblob text
);
CREATE TABLE oik.nextnums (
    fullpath character(100),
    fieldname character(20),
    nextnum integer
);
CREATE TABLE oik.sqltokens (
    sql92 character(20),
    currentv character(20)
);
CREATE TABLE oik.mobilesigns (
    recnum integer NOT NULL,
    formid integer,
    signx integer,
    signy integer,
    signpagenum integer,
    jrecid integer,
    jid character(32)
);
CREATE SEQUENCE oik.mobilesigns_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.mobilesigns_recnum_seq OWNED BY oik.mobilesigns.recnum;

CREATE TABLE oik.oikn_formsch (
    recnum integer NOT NULL,
    groupid integer NOT NULL,
    formid integer NOT NULL,
    nameex character(128) NOT NULL
);
CREATE SEQUENCE oik.oikn_formsch_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.oikn_formsch_recnum_seq OWNED BY oik.oikn_formsch.recnum;

CREATE TABLE oik.oikn_groupsch (
    recnum integer NOT NULL,
    groupid integer NOT NULL,
    nameex character(128) NOT NULL
);
CREATE SEQUENCE oik.oikn_groupsch_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.oikn_groupsch_recnum_seq OWNED BY oik.oikn_groupsch.recnum;

CREATE TABLE oik.oikn_schems (
    recnum integer NOT NULL,
    formid integer NOT NULL,
    record text NOT NULL
);
CREATE SEQUENCE oik.oikn_schems_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.oikn_schems_recnum_seq OWNED BY oik.oikn_schems.recnum;

CREATE TABLE oik.oikn_subgrsch (
    recnum integer NOT NULL,
    subgrid integer NOT NULL,
    nameex character(128) NOT NULL,
    groupid integer NOT NULL
);
CREATE SEQUENCE oik.oikn_subgrsch_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.oikn_subgrsch_recnum_seq OWNED BY oik.oikn_subgrsch.recnum;

CREATE TABLE oik.special_actions (
    recnum integer NOT NULL,
    zoneid integer NOT NULL,
    actiontype integer NOT NULL,
    name character(32) NOT NULL,
    formid integer,
    data text
);
CREATE SEQUENCE oik.special_actions_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.special_actions_recnum_seq OWNED BY oik.special_actions.recnum;

CREATE TABLE oik.special_drawings (
    recnum integer NOT NULL,
    formid integer NOT NULL,
    recordxsde xml,
    recordjson json
);
CREATE SEQUENCE oik.special_drawings_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.special_drawings_recnum_seq OWNED BY oik.special_drawings.recnum;

CREATE TABLE oik.special_zones (
    recnum integer NOT NULL,
    formid integer NOT NULL,
    zoneid integer NOT NULL,
    name character(32)
);
CREATE SEQUENCE oik.special_zones_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.special_zones_recnum_seq OWNED BY oik.special_zones.recnum;

CREATE TABLE oik.tm_dynamtii (
    recnum integer NOT NULL,
    formid integer NOT NULL,
    tmadr integer NOT NULL
);
CREATE SEQUENCE oik.tm_dynamtii_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.tm_dynamtii_recnum_seq OWNED BY oik.tm_dynamtii.recnum;

CREATE TABLE oik.tm_dynamtit (
    recnum integer NOT NULL,
    formid integer NOT NULL,
    tmadr integer NOT NULL
);
CREATE SEQUENCE oik.tm_dynamtit_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.tm_dynamtit_recnum_seq OWNED BY oik.tm_dynamtit.recnum;

CREATE TABLE oik.tm_dynamts (
    recnum integer NOT NULL,
    formid integer NOT NULL,
    tmadr integer NOT NULL
);
CREATE SEQUENCE oik.tm_dynamts_recnum_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
ALTER SEQUENCE oik.tm_dynamts_recnum_seq OWNED BY oik.tm_dynamts.recnum;

ALTER TABLE ONLY oik.mobilesigns ALTER COLUMN recnum SET DEFAULT nextval('oik.mobilesigns_recnum_seq'::regclass);
ALTER TABLE ONLY oik.oikn_formsch ALTER COLUMN recnum SET DEFAULT nextval('oik.oikn_formsch_recnum_seq'::regclass);
ALTER TABLE ONLY oik.oikn_groupsch ALTER COLUMN recnum SET DEFAULT nextval('oik.oikn_groupsch_recnum_seq'::regclass);
ALTER TABLE ONLY oik.oikn_schems ALTER COLUMN recnum SET DEFAULT nextval('oik.oikn_schems_recnum_seq'::regclass);
ALTER TABLE ONLY oik.oikn_subgrsch ALTER COLUMN recnum SET DEFAULT nextval('oik.oikn_subgrsch_recnum_seq'::regclass);
ALTER TABLE ONLY oik.special_actions ALTER COLUMN recnum SET DEFAULT nextval('oik.special_actions_recnum_seq'::regclass);
ALTER TABLE ONLY oik.special_drawings ALTER COLUMN recnum SET DEFAULT nextval('oik.special_drawings_recnum_seq'::regclass);
ALTER TABLE ONLY oik.special_zones ALTER COLUMN recnum SET DEFAULT nextval('oik.special_zones_recnum_seq'::regclass);
ALTER TABLE ONLY oik.tm_dynamtii ALTER COLUMN recnum SET DEFAULT nextval('oik.tm_dynamtii_recnum_seq'::regclass);
ALTER TABLE ONLY oik.tm_dynamtit ALTER COLUMN recnum SET DEFAULT nextval('oik.tm_dynamtit_recnum_seq'::regclass);
ALTER TABLE ONLY oik.tm_dynamts ALTER COLUMN recnum SET DEFAULT nextval('oik.tm_dynamts_recnum_seq'::regclass);

ALTER TABLE ONLY oik.mobilesigns
    ADD CONSTRAINT mobilesigns_pkey PRIMARY KEY (recnum);

ALTER TABLE ONLY oik.oikn_formsch
    ADD CONSTRAINT oikn_formsch_pkey PRIMARY KEY (recnum);

ALTER TABLE ONLY oik.oikn_groupsch
    ADD CONSTRAINT oikn_groupsch_pkey PRIMARY KEY (recnum);

ALTER TABLE ONLY oik.oikn_schems
    ADD CONSTRAINT oikn_schems_pkey PRIMARY KEY (recnum);

ALTER TABLE ONLY oik.oikn_subgrsch
    ADD CONSTRAINT oikn_subgrsch_pkey PRIMARY KEY (recnum);

ALTER TABLE ONLY oik.special_actions
    ADD CONSTRAINT special_actions_pkey PRIMARY KEY (recnum);

ALTER TABLE ONLY oik.special_drawings
    ADD CONSTRAINT special_drawings_pkey PRIMARY KEY (recnum);

ALTER TABLE ONLY oik.special_zones
    ADD CONSTRAINT special_zones_pkey PRIMARY KEY (recnum);

ALTER TABLE ONLY oik.tm_dynamtii
    ADD CONSTRAINT tm_dynamtii_pkey PRIMARY KEY (recnum);

ALTER TABLE ONLY oik.tm_dynamtit
    ADD CONSTRAINT tm_dynamtit_pkey PRIMARY KEY (recnum);

ALTER TABLE ONLY oik.tm_dynamts
    ADD CONSTRAINT tm_dynamts_pkey PRIMARY KEY (recnum);
