CREATE TABLE anime (
- aid integer NOT NULL,
- anidb_update timestamp without time zone,
- entry_update timestamp without time zone,
- my_update timestamp without time zone,
- title_english text,
- title_romaji text,
- title_kanji text,
- description text,
- year character(10),
- start_date timestamp without time zone,
- end_date timestamp without time zone,
- type character varying(50),
- rating numeric(4,2),
- votes integer,
- temp_rating numeric(4,2),
- temp_votes integer,
- my_vote numeric(4,2),
- my_vote_date timestamp without time zone,
- my_temp_vote numeric(4,2),
- my_temp_vote_date timestamp without time zone,
+ aid integer NOT NULL,
+ anidb_update timestamp without time zone,
+ entry_update timestamp without time zone,
+ my_update timestamp without time zone,
+ title_english text,
+ title_romaji text,
+ title_kanji text,
+ description text,
+ year character(10),
+ start_date timestamp without time zone,
+ end_date timestamp without time zone,
+ type character varying(50),
+ rating numeric(4,2),
+ votes integer,
+ temp_rating numeric(4,2),
+ temp_votes integer,
+ my_vote numeric(4,2),
+ my_vote_date timestamp without time zone,
+ my_temp_vote numeric(4,2),
+ my_temp_vote_date timestamp without time zone,
CONSTRAINT aid_pk PRIMARY KEY (aid)
);
CREATE INDEX rating_idx ON anime USING btree (rating);
CREATE INDEX my_temp_vote_idx ON anime USING btree (my_temp_vote);
CREATE TABLE anime_title (
- aid integer NOT NULL,
- type integer DEFAULT 1,
- language character(8) DEFAULT ''::bpchar,
- title character varying(500) NOT NULL,
+ aid integer NOT NULL,
+ type integer DEFAULT 1,
+ language character(8) DEFAULT ''::bpchar,
+ title character varying(500) NOT NULL,
CONSTRAINT unique_title UNIQUE (aid, type, language, title)
);
CREATE INDEX aid_idx ON anime_title USING btree (aid);
CREATE INDEX language_idx ON anime_title USING hash (language);
CREATE TABLE episode (
- eid integer NOT NULL,
- aid integer,
- anidb_update timestamp without time zone,
- entry_update timestamp without time zone,
- my_update timestamp without time zone,
- epno integer,
- title_english text,
- title_romaji text,
- title_kanji text,
- length integer,
- airdate timestamp without time zone,
- state integer,
- special boolean,
- recap boolean,
- opening boolean,
- ending boolean,
- rating numeric(4,2),
- votes integer,
- my_vote numeric(4,2),
- my_vote_date timestamp without time zone,
+ eid integer NOT NULL,
+ aid integer,
+ anidb_update timestamp without time zone,
+ entry_update timestamp without time zone,
+ my_update timestamp without time zone,
+ epno integer,
+ title_english text,
+ title_romaji text,
+ title_kanji text,
+ length integer,
+ airdate timestamp without time zone,
+ state integer,
+ special boolean,
+ recap boolean,
+ opening boolean,
+ ending boolean,
+ rating numeric(4,2),
+ votes integer,
+ my_vote numeric(4,2),
+ my_vote_date timestamp without time zone,
CONSTRAINT eid_pk PRIMARY KEY (eid)
);
CREATE INDEX episode_aid_fk ON episode USING btree (aid);
CREATE TABLE file (
- fid integer NOT NULL,
- eid integer,
- aid integer,
- gid integer,
- anidb_update timestamp without time zone,
- entry_update timestamp without time zone,
- my_update timestamp without time zone,
- ed2k character(32),
- size bigint,
- length integer,
- extension character varying(50),
- group_name text,
- group_name_short text,
- crc character(8),
- release_date timestamp without time zone,
- version integer,
- censored boolean,
- type character varying(50),
- quality_id integer,
- quality character varying(50),
- resolution character varying(50),
- video_codec character varying(50),
- audio_codec character varying(50),
- audio_language character varying(50),
- subtitle_language character varying(50),
- aspect_ratio character varying(50),
- my_watched timestamp without time zone,
- my_state integer,
- my_file_state integer,
- my_storage text,
- my_source text,
- my_other text,
+ fid integer NOT NULL,
+ eid integer,
+ aid integer,
+ gid integer,
+ anidb_update timestamp without time zone,
+ entry_update timestamp without time zone,
+ my_update timestamp without time zone,
+ ed2k character(32),
+ size bigint,
+ length integer,
+ extension character varying(50),
+ group_name text,
+ group_name_short text,
+ crc character(8),
+ release_date timestamp without time zone,
+ version integer,
+ censored boolean,
+ type character varying(50),
+ quality_id integer,
+ quality character varying(50),
+ resolution character varying(50),
+ video_codec character varying(50),
+ audio_codec character varying(50),
+ audio_language character varying(50),
+ subtitle_language character varying(50),
+ aspect_ratio character varying(50),
+ my_watched timestamp without time zone,
+ my_state integer,
+ my_file_state integer,
+ my_storage text,
+ my_source text,
+ my_other text,
CONSTRAINT fid_pk PRIMARY KEY (fid)
);
CREATE INDEX file_aid_fk ON file USING btree (aid);
CREATE INDEX file_eid_fk ON file USING btree (eid);
CREATE TABLE file_episode_rel (
- fid integer NOT NULL,
- eid integer NOT NULL,
- start_percent integer,
- end_percent integer,
+ fid integer NOT NULL,
+ eid integer NOT NULL,
+ start_percent integer,
+ end_percent integer,
CONSTRAINT fid_eid_pk PRIMARY KEY (fid, eid)
);
CREATE INDEX file_episode_rel_eid_fk ON file_episode_rel USING btree (eid);
);
CREATE TABLE unknown_file (
- ed2k character(32) NOT NULL,
- size bigint NOT NULL,
- host_id integer,
- path text,
+ ed2k character(32) NOT NULL,
+ size bigint NOT NULL,
+ host_id integer,
+ path text,
CONSTRAINT unknown_files_pk PRIMARY KEY (ed2k, size)
);
CREATE TABLE pending_mylist_update
(
- update_id bigserial NOT NULL,
- fid integer NOT NULL,
- set_my_watched boolean NOT NULL DEFAULT false,
- my_watched timestamp without time zone,
- set_my_state boolean NOT NULL DEFAULT false,
- my_state integer,
- set_my_file_state boolean NOT NULL DEFAULT false,
- my_file_state integer,
- set_my_storage boolean NOT NULL DEFAULT false,
- my_storage text,
- set_my_source boolean NOT NULL DEFAULT false,
- my_source text,
- set_my_other boolean NOT NULL DEFAULT false,
- my_other text,
- added timestamp without time zone DEFAULT now(),
- started timestamp without time zone,
- finished timestamp without time zone,
- CONSTRAINT pending_mylist_update_pk PRIMARY KEY (update_id )
+ update_id bigserial NOT NULL,
+ fid integer NOT NULL,
+ set_my_watched boolean NOT NULL DEFAULT false,
+ my_watched timestamp without time zone,
+ set_my_state boolean NOT NULL DEFAULT false,
+ my_state integer,
+ set_my_file_state boolean NOT NULL DEFAULT false,
+ my_file_state integer,
+ set_my_storage boolean NOT NULL DEFAULT false,
+ my_storage text,
+ set_my_source boolean NOT NULL DEFAULT false,
+ my_source text,
+ set_my_other boolean NOT NULL DEFAULT false,
+ my_other text,
+ added timestamp without time zone DEFAULT now(),
+ started timestamp without time zone,
+ finished timestamp without time zone,
+ CONSTRAINT pending_mylist_update_pk PRIMARY KEY (update_id )
);
CREATE TABLE pending_request (
- aid integer DEFAULT 0 NOT NULL,
- eid integer DEFAULT 0 NOT NULL,
- fid integer DEFAULT 0 NOT NULL,
- ed2k character(32) DEFAULT ''::bpchar NOT NULL,
- size bigint DEFAULT 0 NOT NULL,
- priority integer DEFAULT 1 NOT NULL,
- added timestamp without time zone DEFAULT now(),
- start timestamp without time zone,
+ aid integer DEFAULT 0 NOT NULL,
+ eid integer DEFAULT 0 NOT NULL,
+ fid integer DEFAULT 0 NOT NULL,
+ ed2k character(32) DEFAULT ''::bpchar NOT NULL,
+ size bigint DEFAULT 0 NOT NULL,
+ priority integer DEFAULT 1 NOT NULL,
+ added timestamp without time zone DEFAULT now(),
+ start timestamp without time zone,
CONSTRAINT pending_request_pk PRIMARY KEY (aid, eid, fid, ed2k, size)
);
CREATE INDEX pending_request_added_idx ON pending_request USING btree (added);
CREATE INDEX pending_request_start_idx ON pending_request USING btree (start);
CREATE TABLE config (
- key character varying(250) NOT NULL,
- value text,
- is_user_facing boolean DEFAULT false NOT NULL,
+ key character varying(250) NOT NULL,
+ value text,
+ is_user_facing boolean DEFAULT false NOT NULL,
CONSTRAINT config_pk PRIMARY KEY (key)
);
CREATE TABLE host (
- host_id serial NOT NULL,
- name character varying(100),
- is_udp_host boolean DEFAULT false,
+ host_id serial NOT NULL,
+ name character varying(100),
+ is_udp_host boolean DEFAULT false,
CONSTRAINT host_pk PRIMARY KEY (host_id),
CONSTRAINT host_unique_name UNIQUE (name)
);
CREATE TABLE log (
- log_id serial NOT NULL,
- type integer,
- log text,
+ log_id serial NOT NULL,
+ type integer,
+ log text,
log_time timestamp without time zone NOT NULL DEFAULT now(),
CONSTRAINT log_pk PRIMARY KEY (log_id)
);
CREATE VIEW file_data AS
- SELECT f.fid, f.eid, f.aid, f.gid, f.anidb_update, f.entry_update, f.my_update, f.ed2k, f.size, f.length, f.extension, f.group_name, f.group_name_short, f.crc, f.release_date, f.version, f.censored, f.type, f.quality_id, f.quality, f.resolution, f.video_codec, f.audio_codec, f.audio_language, f.subtitle_language, f.aspect_ratio, f.my_watched, f.my_state, f.my_file_state, f.my_storage, f.my_source, f.my_other, a.title_romaji AS atitle, e.title_english AS eptitle FROM ((file f LEFT JOIN anime a ON ((f.aid = a.aid))) LEFT JOIN episode e ON ((f.eid = e.eid)));
+ SELECT f.fid, f.eid, f.aid, f.gid, f.anidb_update, f.entry_update, f.my_update, f.ed2k, f.size, f.length, f.extension, f.group_name, f.group_name_short, f.crc, f.release_date, f.version, f.censored, f.type, f.quality_id, f.quality, f.resolution, f.video_codec, f.audio_codec, f.audio_language, f.subtitle_language, f.aspect_ratio, f.my_watched, f.my_state, f.my_file_state, f.my_storage, f.my_source, f.my_other, a.title_romaji AS atitle, e.title_english AS eptitle FROM ((file f LEFT JOIN anime a ON ((f.aid = a.aid))) LEFT JOIN episode e ON ((f.eid = e.eid)));
CREATE VIEW rename_data AS
- SELECT f.fid, f.eid, f.aid, f.gid, a.anidb_update AS anime_anidb_update, a.entry_update AS anime_entry_update, a.my_update AS anime_my_update, a.title_english AS anime_title_english, a.title_romaji AS anime_title_romaji, a.title_kanji AS anime_title_kanji, a.description, a.year, a.start_date, a.end_date, a.type AS anime_type, a.rating AS anime_rating, a.votes AS anime_votes, a.temp_rating, a.temp_votes, a.my_vote AS anime_my_vote, a.my_vote_date AS anime_my_vote_date, a.my_temp_vote, a.my_temp_vote_date, ( SELECT count(episode.eid) AS count FROM episode WHERE episode.aid = f.aid) AS episode_count, e.anidb_update AS episode_anidb_update, e.entry_update AS episode_entry_update, e.my_update AS episode_my_update, e.epno, e.title_english AS episode_title_english, e.title_romaji AS episode_title_romaji, e.title_kanji AS episode_title_kanji, e.length AS episode_length, e.airdate, e.state, e.special, e.recap, e.opening, e.ending, e.rating, e.votes, e.my_vote, e.my_vote_date, f.anidb_update, f.entry_update, f.my_update, f.ed2k, f.size, f.length, f.extension, f.group_name, f.group_name_short, f.crc, f.release_date, f.version, f.censored, f.type, f.quality_id, f.quality, f.resolution, f.video_codec, f.audio_codec, f.audio_language, f.subtitle_language, f.aspect_ratio, f.my_watched, f.my_state, f.my_file_state, f.my_storage, f.my_source, f.my_other, fl.host_id, fl.path, fl.renamed, fl.failed_rename
- FROM file f
- JOIN anime a ON a.aid = f.aid
- JOIN episode e ON e.eid = f.eid
- JOIN file_location fl ON fl.fid = f.fid
- WHERE fl.renamed IS NULL AND fl.failed_rename = false;
+ SELECT f.fid, f.eid, f.aid, f.gid, a.anidb_update AS anime_anidb_update, a.entry_update AS anime_entry_update, a.my_update AS anime_my_update, a.title_english AS anime_title_english, a.title_romaji AS anime_title_romaji, a.title_kanji AS anime_title_kanji, a.description, a.year, a.start_date, a.end_date, a.type AS anime_type, a.rating AS anime_rating, a.votes AS anime_votes, a.temp_rating, a.temp_votes, a.my_vote AS anime_my_vote, a.my_vote_date AS anime_my_vote_date, a.my_temp_vote, a.my_temp_vote_date, ( SELECT count(episode.eid) AS count FROM episode WHERE episode.aid = f.aid) AS episode_count, e.anidb_update AS episode_anidb_update, e.entry_update AS episode_entry_update, e.my_update AS episode_my_update, e.epno, e.title_english AS episode_title_english, e.title_romaji AS episode_title_romaji, e.title_kanji AS episode_title_kanji, e.length AS episode_length, e.airdate, e.state, e.special, e.recap, e.opening, e.ending, e.rating, e.votes, e.my_vote, e.my_vote_date, f.anidb_update, f.entry_update, f.my_update, f.ed2k, f.size, f.length, f.extension, f.group_name, f.group_name_short, f.crc, f.release_date, f.version, f.censored, f.type, f.quality_id, f.quality, f.resolution, f.video_codec, f.audio_codec, f.audio_language, f.subtitle_language, f.aspect_ratio, f.my_watched, f.my_state, f.my_file_state, f.my_storage, f.my_source, f.my_other, fl.host_id, fl.path, fl.renamed, fl.failed_rename
+ FROM file f
+ JOIN anime a ON a.aid = f.aid
+ JOIN episode e ON e.eid = f.eid
+ JOIN file_location fl ON fl.fid = f.fid
+ WHERE fl.renamed IS NULL AND fl.failed_rename = false;
CREATE RULE config_updated_rule AS ON UPDATE TO config DO NOTIFY config_changed;