
CREATE TABLE IF NOT EXISTS api.tag_vod_relations_vod_links
(
    id integer NOT NULL,
    tag_vod_relation_id integer,
    vod_id integer,
    tag_vod_relation_order double precision,
    CONSTRAINT tag_vod_relations_vod_links_pkey PRIMARY KEY (id),
    CONSTRAINT tag_vod_relations_vod_links_unique UNIQUE (tag_vod_relation_id, vod_id),
    CONSTRAINT tag_vod_relations_vod_links_fk FOREIGN KEY (tag_vod_relation_id)
        REFERENCES api.tag_vod_relations (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE CASCADE,
    CONSTRAINT tag_vod_relations_vod_links_inv_fk FOREIGN KEY (vod_id)
        REFERENCES api.vods (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE CASCADE
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS api.tag_vod_relations_vod_links
    OWNER to postgres;
-- Index: tag_vod_relations_vod_links_fk

-- DROP INDEX IF EXISTS api.tag_vod_relations_vod_links_fk;

CREATE INDEX IF NOT EXISTS tag_vod_relations_vod_links_fk
    ON api.tag_vod_relations_vod_links USING btree
    (tag_vod_relation_id ASC NULLS LAST)
    TABLESPACE pg_default;
-- Index: tag_vod_relations_vod_links_inv_fk

-- DROP INDEX IF EXISTS api.tag_vod_relations_vod_links_inv_fk;

CREATE INDEX IF NOT EXISTS tag_vod_relations_vod_links_inv_fk
    ON api.tag_vod_relations_vod_links USING btree
    (vod_id ASC NULLS LAST)
    TABLESPACE pg_default;
-- Index: tag_vod_relations_vod_links_order_inv_fk

-- DROP INDEX IF EXISTS api.tag_vod_relations_vod_links_order_inv_fk;

CREATE INDEX IF NOT EXISTS tag_vod_relations_vod_links_order_inv_fk
    ON api.tag_vod_relations_vod_links USING btree
    (tag_vod_relation_order ASC NULLS LAST)
    TABLESPACE pg_default;