CREATE SCHEMA dbo;

ALTER SCHEMA dbo OWNER TO postgres;

CREATE SCHEMA updates;

ALTER SCHEMA updates OWNER TO postgres;

CREATE SEQUENCE dbo.actordata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE dbo.actordata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE dbo.castdata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE dbo.castdata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE dbo.countrydata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE dbo.countrydata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE dbo.crewdata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE dbo.crewdata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE updates.epdata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE updates.epdata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE dbo.epdata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE dbo.epdata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE dbo.seriesdata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE dbo.seriesdata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE dbo.tvnetworkdata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE dbo.tvnetworkdata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE dbo.tvwebchanneldata_id_seq
    AS integer    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;

ALTER SEQUENCE dbo.tvwebchanneldata_id_seq OWNER TO postgres;

CREATE SEQUENCE dbo.webchanneldata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE dbo.webchanneldata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE updates.actordata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE updates.actordata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE updates.castdata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE updates.castdata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE updates.countrydata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE updates.countrydata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE updates.crewdata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE updates.crewdata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE updates.seriesdata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE updates.seriesdata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE updates.tvnetworkdata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE updates.tvnetworkdata_row_id_seq OWNER TO postgres;

CREATE SEQUENCE updates.tvupdates_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE updates.tvupdates_row_id_seq OWNER TO postgres;

CREATE SEQUENCE updates.tvwebchanneldata_id_seq
    AS integer    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;

ALTER SEQUENCE updates.tvwebchanneldata_id_seq OWNER TO postgres;

CREATE SEQUENCE updates.webchanneldata_row_id_seq    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER SEQUENCE updates.webchanneldata_row_id_seq OWNER TO postgres;

CREATE TABLE dbo.actordata (
    row_id bigint NOT NULL DEFAULT nextval('dbo.actordata_row_id_seq'::regclass),
    actorid integer,
    actorname character varying(72),
    countryname character varying(144),
    countrytimezone character varying(72),
    birthday date,
    deathday date,
    gender character varying(6),
    mediumimage text,
    originalimage text,
    apilink text,
    url text,
    countrycode character varying(12));

ALTER TABLE dbo.actordata OWNER TO postgres;

ALTER SEQUENCE dbo.actordata_row_id_seq OWNED BY dbo.actordata.row_id;

CREATE TABLE dbo.castdata (
    row_id bigint NOT NULL DEFAULT nextval('dbo.castdata_row_id_seq'::regclass),
    seriesid integer,
    characterid integer,
    actorid integer,
    charactername integer,
    mediumimage text,
    originalimage text,
    apilink text,
    tvmazeilink text);

ALTER TABLE dbo.castdata OWNER TO postgres;

ALTER SEQUENCE dbo.castdata_row_id_seq OWNED BY dbo.castdata.row_id;

CREATE TABLE dbo.countrydata (
    row_id bigint NOT NULL DEFAULT nextval('dbo.countrydata_row_id_seq'::regclass),
    country_name character varying(255),
    country_code character varying(255),
    country_timezone character varying(255));

ALTER TABLE dbo.countrydata OWNER TO postgres;

ALTER SEQUENCE dbo.countrydata_row_id_seq OWNED BY dbo.countrydata.row_id;

CREATE TABLE dbo.crewdata (
    row_id bigint NOT NULL DEFAULT nextval('dbo.crewdata_row_id_seq'::regclass),
    crewid integer,
    crew_type character varying(128),
    name character varying(255),
    _links_self_href text,
    country_name text,
    country_code text,
    country_timezone text,
    birthday date,
    deathday date,
    gender character varying(24),
    image_medium text,
    image_original text,
    updated text,
    url text);

ALTER TABLE dbo.crewdata OWNER TO postgres;

ALTER SEQUENCE dbo.crewdata_row_id_seq OWNED BY dbo.crewdata.row_id;

CREATE TABLE dbo.epdata (
    row_id bigint NOT NULL DEFAULT nextval('dbo.epdata_row_id_seq'::regclass),
    episodeid integer,
    seriesid integer,
    season integer,
    episode_number integer,
    episode_name text,
    airdate character varying(32),
    airtime character varying(32),
    summary text,
    airstamp character varying(32),
    runtime character varying(6),
    eplink text,
    image_medium text,
    url text,
    image_original text,
    episode_type text,
    rating_average text,
    _links_self_href text,
    _links_show_href text,
    _links_show_name text);

ALTER TABLE dbo.epdata OWNER TO postgres;

ALTER SEQUENCE dbo.epdata_row_id_seq OWNED BY dbo.epdata.row_id;

CREATE TABLE dbo.seriesdata (
    row_id bigint NOT NULL DEFAULT nextval('dbo.seriesdata_row_id_seq'::regclass),
    _links_previousepisode_href text,
    _links_previousepisode_name text,
    _links_nextepisode_href text,
    _links_nextepisode_name text,
    _links_self_href text,
    averageruntime text,
    dvdcountry text,
    series_name text,
    ended date,
    externals_imdb text,
    externals_thetvdb text,
    externals_tvrage text,
    genres text,
    seriesid text,
    image_medium text,
    image_original text,
    language_name text,
    network_id text,
    network_name text,
    officialsite text,
    network_officialsite text,
    network_country_code text,
    network_country_name text,
    network_country_timezone text,
    premiered text,
    rating_average text,
    runtime text,
    schedule_days text,
    schedule_time text,
    status text,
    summary text,
    series_type text,
    updated text,
    url text,
    webchannel_id integer,
    webchannel_name text,
	webchannel_country_name text,
	webchannel_country_code text,
	webchannel_country_timezone text,
    webchannel_officialsite text,
    weight text);

ALTER TABLE dbo.seriesdata OWNER TO postgres;

ALTER SEQUENCE dbo.seriesdata_row_id_seq OWNED BY dbo.seriesdata.row_id;

CREATE TABLE dbo.tvnetworkdata (
    row_id bigint NOT NULL DEFAULT nextval('dbo.tvnetworkdata_row_id_seq'::regclass),
    networkid character varying(12),
    networkname character varying(255),
    country character varying(255),
    countrycode character varying(4),
    countrytimezone character varying(25));

ALTER TABLE dbo.tvnetworkdata OWNER TO postgres;

ALTER SEQUENCE dbo.tvnetworkdata_row_id_seq OWNED BY dbo.tvnetworkdata.row_id;

CREATE TABLE dbo.tvwebchanneldata (
    id integer NOT NULL DEFAULT nextval('dbo.tvwebchanneldata_id_seq'::regclass),
    webchannelname character varying(255),
    webchannelcountrycode character varying(4),
    webchannelcountryname character varying(255),
    webchannelcountrytimezone character varying(4));

ALTER TABLE dbo.tvwebchanneldata OWNER TO postgres;

ALTER SEQUENCE dbo.tvwebchanneldata_id_seq OWNED BY dbo.tvwebchanneldata.id;

CREATE TABLE dbo.webchanneldata (
    row_id bigint NOT NULL DEFAULT nextval('dbo.webchanneldata_row_id_seq'::regclass),
    webchannelname character varying(255),
    webchannelcountrycode character varying(4),
    webchannelcountryname character varying(255),
    webchannelcountrytimezone character varying(4));

ALTER TABLE dbo.webchanneldata OWNER TO postgres;

ALTER SEQUENCE dbo.webchanneldata_row_id_seq OWNED BY dbo.webchanneldata.row_id;

CREATE TABLE updates.actordata (
    row_id bigint NOT NULL DEFAULT nextval('updates.actordata_row_id_seq'::regclass),
    actorid integer,
    actorname character varying(72),
    countryname character varying(144),
    countrytimezone character varying(72),
    birthday date,
    deathday date,
    gender character varying(6),
    mediumimage text,
    originalimage text,
    apilink text,
    url text,
    countrycode character varying(12));

ALTER TABLE updates.actordata OWNER TO postgres;

ALTER SEQUENCE updates.actordata_row_id_seq OWNED BY updates.actordata.row_id;

CREATE TABLE updates.castdata (
    row_id bigint NOT NULL DEFAULT nextval('updates.castdata_row_id_seq'::regclass),
    seriesid integer,
    characterid integer,
    actorid integer,
    charactername integer,
    mediumimage text,
    originalimage text,
    apilink text,
    tvmazeilink text);

ALTER TABLE updates.castdata OWNER TO postgres;

ALTER SEQUENCE updates.castdata_row_id_seq OWNED BY updates.castdata.row_id;

CREATE TABLE updates.countrydata (
    row_id bigint NOT NULL DEFAULT nextval('updates.countrydata_row_id_seq'::regclass),
    country_name character varying(255),
    country_code character varying(255),
    country_timezone character varying(255));

ALTER TABLE updates.countrydata OWNER TO postgres;

ALTER SEQUENCE updates.countrydata_row_id_seq OWNED BY updates.countrydata.row_id;

CREATE TABLE updates.crewdata (
    row_id bigint NOT NULL DEFAULT nextval('updates.crewdata_row_id_seq'::regclass),
    crewid integer,
    crew_type character varying(128),
    name character varying(255),
    _links_self_href text,
    country_name text,
    country_code text,
    country_timezone text,
    birthday date,
    deathday date,
    gender character varying(24),
    image_medium text,
    image_original text,
    updated text,
    url text);

ALTER TABLE updates.crewdata OWNER TO postgres;

ALTER SEQUENCE updates.crewdata_row_id_seq OWNED BY updates.crewdata.row_id;

CREATE TABLE updates.epdata (
    row_id bigint NOT NULL DEFAULT nextval('updates.epdata_row_id_seq'::regclass),
    episodeid integer,
    seriesid integer,
    season integer,
    episode_number integer,
    episode_name text,
    airdate character varying(32),
    airtime character varying(32),
    summary text,
    airstamp character varying(32),
    runtime character varying(6),
    eplink text,
    image_medium text,
    url text,
    image_original text,
    episode_type text,
    rating_average text,
    _links_self_href text,
    _links_show_href text,
    _links_show_name text);

ALTER TABLE updates.epdata OWNER TO postgres;

ALTER SEQUENCE updates.epdata_row_id_seq OWNED BY updates.epdata.row_id;

CREATE TABLE updates.seriesdata (
    row_id bigint NOT NULL DEFAULT nextval('updates.seriesdata_row_id_seq'::regclass),
    _links_previousepisode_href text,
    _links_previousepisode_name text,
    _links_nextepisode_href text,
    _links_nextepisode_name text,
    _links_self_href text,
    averageruntime text,
    dvdcountry text,
    series_name text,
    ended date,
    externals_imdb text,
    externals_thetvdb text,
    externals_tvrage text,
    genres text,
    seriesid text,
    image_medium text,
    image_original text,
    language_name text,
    network_id text,
    network_name text,
    officialsite text,
    network_officialsite text,
    network_country_code text,
    network_country_name text,
    network_country_timezone text,
    premiered text,
    rating_average text,
    runtime text,
    schedule_days text,
    schedule_time text,
    status text,
    summary text,
    series_type text,
    updated text,
    url text,
    webchannel_id integer,
    webchannel_name text,
	webchannel_country_name text,
	webchannel_country_code text,
	webchannel_country_timezone text,
    webchannel_officialsite text,
    weight text);

ALTER TABLE updates.seriesdata OWNER TO postgres;

ALTER SEQUENCE updates.seriesdata_row_id_seq OWNED BY updates.seriesdata.row_id;

CREATE TABLE updates.tvnetworkdata (
    row_id bigint NOT NULL DEFAULT nextval('updates.tvnetworkdata_row_id_seq'::regclass),
    networkid character varying(12),
    networkname character varying(255),
    country character varying(255),
    countrycode character varying(4),
    countrytimezone character varying(25));

ALTER TABLE updates.tvnetworkdata OWNER TO postgres;

ALTER SEQUENCE updates.tvnetworkdata_row_id_seq OWNED BY updates.tvnetworkdata.row_id;

CREATE TABLE updates.tvupdates (
    row_id bigint NOT NULL DEFAULT nextval('updates.tvupdates_row_id_seq'::regclass),
    seriesid integer,
    "timestamp" character varying(15));

ALTER TABLE updates.tvupdates OWNER TO postgres;

ALTER SEQUENCE updates.tvupdates_row_id_seq OWNED BY updates.tvupdates.row_id;

CREATE TABLE updates.tvwebchanneldata (
    row_id integer NOT NULL DEFAULT nextval('updates.tvwebchanneldata_id_seq'::regclass),
    name character varying(255),
    countryid character varying(255));

ALTER TABLE updates.tvwebchanneldata OWNER TO postgres;

ALTER SEQUENCE updates.tvwebchanneldata_id_seq OWNED BY updates.tvwebchanneldata.row_id;

CREATE TABLE updates.webchanneldata (
    row_id bigint NOT NULL DEFAULT nextval('updates.webchanneldata_row_id_seq'::regclass),
    webchannel_name character varying(255),
    webchannel_country_code character varying(4),
    webchannel_country_name character varying(255),
    webchannelcountry_timezone character varying(4));

ALTER TABLE updates.webchanneldata OWNER TO postgres;

ALTER SEQUENCE updates.webchanneldata_row_id_seq OWNED BY updates.webchanneldata.row_id;

ALTER TABLE dbo.actordata ADD CONSTRAINT actordata_pkey PRIMARY KEY (row_id);

ALTER TABLE dbo.castdata ADD CONSTRAINT castdata_pkey PRIMARY KEY (row_id);

ALTER TABLE dbo.countrydata ADD CONSTRAINT countrydata_pkey PRIMARY KEY (row_id);

ALTER TABLE dbo.epdata ADD CONSTRAINT epdata_pkey PRIMARY KEY (row_id);

ALTER TABLE dbo.seriesdata ADD CONSTRAINT seriesdata_pkey PRIMARY KEY (row_id);

ALTER TABLE dbo.tvnetworkdata ADD CONSTRAINT tvnetworkdata_pkey PRIMARY KEY (row_id);

ALTER TABLE dbo.tvwebchanneldata ADD CONSTRAINT tvwebchanneldata_pkey PRIMARY KEY (id);

ALTER TABLE dbo.webchanneldata ADD CONSTRAINT webchanneldata_pkey PRIMARY KEY (row_id);

ALTER TABLE updates.actordata ADD CONSTRAINT actordata_pkey PRIMARY KEY (row_id);

ALTER TABLE updates.actordata ADD CONSTRAINT actorid UNIQUE (actorid);

ALTER TABLE updates.castdata ADD CONSTRAINT castdata_pkey PRIMARY KEY (row_id);

ALTER TABLE updates.castdata ADD CONSTRAINT series_actor_character_index UNIQUE (seriesid, characterid, actorid);

ALTER TABLE updates.countrydata ADD CONSTRAINT country_code_idx UNIQUE (country_code);

ALTER TABLE updates.countrydata ADD CONSTRAINT countrydata_pkey PRIMARY KEY (row_id);

ALTER TABLE updates.crewdata ADD CONSTRAINT crewdata_pkey PRIMARY KEY (row_id);

ALTER TABLE updates.crewdata ADD CONSTRAINT crewid_crewid_idx UNIQUE (crewid);

ALTER TABLE updates.epdata ADD CONSTRAINT epdata_pkey PRIMARY KEY (row_id);

ALTER TABLE updates.epdata ADD CONSTRAINT episodeie UNIQUE (episodeid);

ALTER TABLE updates.seriesdata ADD CONSTRAINT seriesdata_pkey PRIMARY KEY (row_id);

ALTER TABLE updates.seriesdata ADD CONSTRAINT seriesid UNIQUE (seriesid);

ALTER TABLE updates.tvnetworkdata ADD CONSTRAINT networkid UNIQUE (networkid);

ALTER TABLE updates.tvnetworkdata ADD CONSTRAINT tvnetworkdata_pkey PRIMARY KEY (row_id);

ALTER TABLE updates.tvupdates ADD CONSTRAINT tvupdates_pkey PRIMARY KEY (row_id);

ALTER TABLE updates.tvwebchanneldata ADD CONSTRAINT tvwebchanneldata_pkey PRIMARY KEY (row_id);

ALTER TABLE updates.webchanneldata ADD CONSTRAINT webchanneldata_pkey PRIMARY KEY (row_id);

ALTER SCHEMA updates OWNER TO postgres;
