
-- Table: api.b2_files

-- DROP TABLE IF EXISTS api.b2_files;

CREATE TABLE IF NOT EXISTS api.b2_files
(
    id integer NOT NULL,
    url character varying(255) COLLATE pg_catalog."default",
    key character varying(255) COLLATE pg_catalog."default",
    upload_id character varying(255) COLLATE pg_catalog."default",
    created_at timestamp(6) without time zone,
    updated_at timestamp(6) without time zone,
    created_by_id integer,
    updated_by_id integer,
    cdn_url character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT b2_files_pkey PRIMARY KEY (id)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS api.b2_files
    OWNER to postgres;
-- Index: b2_files_created_by_id_fk

-- DROP INDEX IF EXISTS api.b2_files_created_by_id_fk;

CREATE INDEX IF NOT EXISTS b2_files_created_by_id_fk
    ON api.b2_files USING btree
    (created_by_id ASC NULLS LAST)
    TABLESPACE pg_default;
-- Index: b2_files_updated_by_id_fk

-- DROP INDEX IF EXISTS api.b2_files_updated_by_id_fk;

CREATE INDEX IF NOT EXISTS b2_files_updated_by_id_fk
    ON api.b2_files USING btree
    (updated_by_id ASC NULLS LAST)
    TABLESPACE pg_default;




-- Table: api.vods_thumbnail_links

-- DROP TABLE IF EXISTS api.vods_thumbnail_links;

CREATE TABLE IF NOT EXISTS api.vods_thumbnail_links
(
    id integer NOT NULL,
    vod_id integer,
    b_2_file_id integer,
    CONSTRAINT vods_thumbnail_links_pkey PRIMARY KEY (id),
    CONSTRAINT vods_thumbnail_links_unique UNIQUE (vod_id, b_2_file_id),
    CONSTRAINT vods_thumbnail_links_fk FOREIGN KEY (vod_id)
        REFERENCES api.vods (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE CASCADE,
    CONSTRAINT vods_thumbnail_links_inv_fk FOREIGN KEY (b_2_file_id)
        REFERENCES api.b2_files (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE CASCADE
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS api.vods_thumbnail_links
    OWNER to postgres;
-- Index: vods_thumbnail_links_fk

-- DROP INDEX IF EXISTS api.vods_thumbnail_links_fk;

CREATE INDEX IF NOT EXISTS vods_thumbnail_links_fk
    ON api.vods_thumbnail_links USING btree
    (vod_id ASC NULLS LAST)
    TABLESPACE pg_default;
-- Index: vods_thumbnail_links_inv_fk

-- DROP INDEX IF EXISTS api.vods_thumbnail_links_inv_fk;

CREATE INDEX IF NOT EXISTS vods_thumbnail_links_inv_fk
    ON api.vods_thumbnail_links USING btree
    (b_2_file_id ASC NULLS LAST)
    TABLESPACE pg_default;



