]> Some of my projects - localmylist.git/commitdiff
Add sql schema and default config data.
authorAPTX <marek321@gmail.com>
Sat, 2 Jun 2012 15:16:40 +0000 (17:16 +0200)
committerAPTX <marek321@gmail.com>
Sat, 2 Jun 2012 15:16:40 +0000 (17:16 +0200)
localmylist/localmylist.pro
localmylist/share/schema/default_config.sql [new file with mode: 0644]
localmylist/share/schema/schema.sql [new file with mode: 0644]

index 53c26b43c241be1da1ed2cf7e67ec4ef155cb55d..73f174b52c63bc3e192dc970e9f423f5d16c8b79 100644 (file)
@@ -49,6 +49,10 @@ CONV_HEADERS += \
        include/LocalMyList/MyListModel \
        include/LocalMyList/Settings
 
+SHARE += \
+       share/schema/schema.sql \
+       share/schema/default_config.sql
+
 LIBS += -lanidbudpclient
 
 target.path = $${PREFIX}/lib
@@ -59,4 +63,7 @@ headers.files = $$HEADERS
 conv_headers.path = $${PREFIX}/include/LocalMyList
 conv_headers.files = $$CONV_HEADERS
 
-INSTALLS += target headers conv_headers
+share.path = $${PREFIX}/share/LocalMyList
+headers.files = $$SHARE
+
+INSTALLS += target headers conv_headers share
diff --git a/localmylist/share/schema/default_config.sql b/localmylist/share/schema/default_config.sql
new file mode 100644 (file)
index 0000000..61a5124
--- /dev/null
@@ -0,0 +1,23 @@
+-- 'hostname' should be replaced with whatever is in your local config
+INSERT INTO host VALUES (DEFAULT, 'hostname', true);
+-- Relevant config options
+--  UDP API connection
+INSERT INTO config VALUES ('udpClientUser', '', true);
+INSERT INTO config VALUES ('udpClientPass', '', true);
+INSERT INTO config VALUES ('udpClientApiKey', '', true);
+INSERT INTO config VALUES ('udpClientEncryptionEnabled', '0', true);
+--  MyList state
+INSERT INTO config VALUES ('myListDefaultState', '1', true);
+INSERT INTO config VALUES ('myListDefaultViewed', '0', true);
+
+
+-- Other options
+INSERT INTO config VALUES ('udpClientHost', 'api.anidb.info', true);
+INSERT INTO config VALUES ('udpClientHostPort', '9000', true);
+INSERT INTO config VALUES ('udpClientLocalPort', '9001', true);
+INSERT INTO config VALUES ('myListDefaultOther', NULL, true);
+INSERT INTO config VALUES ('myListDefaultStorage', NULL, true);
+INSERT INTO config VALUES ('myListDefaultSource', NULL, true);
+INSERT INTO config VALUES ('renameScript', NULL, true);
+INSERT INTO config VALUES ('renameLanguage', NULL, true);
+INSERT INTO config VALUES ('enableRename', '0', true);
diff --git a/localmylist/share/schema/schema.sql b/localmylist/share/schema/schema.sql
new file mode 100644 (file)
index 0000000..b4a6ae8
--- /dev/null
@@ -0,0 +1,195 @@
+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
+);
+ALTER TABLE ONLY anime ADD CONSTRAINT aid_pk PRIMARY KEY (aid);
+CREATE INDEX rating_idx ON anime USING btree (rating);
+CREATE INDEX temp_rating_idx ON anime USING btree (temp_rating);
+CREATE INDEX my_vote_idx ON anime USING btree (my_vote);
+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
+);
+ALTER TABLE ONLY anime_title ADD CONSTRAINT unique_title UNIQUE (aid, type, language, title);
+CREATE INDEX aid_idx ON anime_title USING btree (aid);
+CREATE INDEX title_idx ON anime_title USING gin (to_tsvector('simple'::regconfig, (title)::text));
+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
+);
+ALTER TABLE ONLY episode ADD 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
+);
+ALTER TABLE ONLY file ADD 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
+);
+ALTER TABLE ONLY file_episode_rel ADD CONSTRAINT fid_eid_pk PRIMARY KEY (fid, eid);
+CREATE INDEX file_episode_rel_eid_fk ON file_episode_rel USING btree (eid);
+CREATE INDEX file_episode_rel_fid_fk ON file_episode_rel USING btree (fid);
+
+CREATE TABLE file_location (
+    fid integer NOT NULL,
+    host_id integer NOT NULL,
+    path text
+);
+
+CREATE TABLE unknown_file (
+    ed2k character(32) NOT NULL,
+    size bigint NOT NULL,
+    host_id integer,
+    path text
+);
+ALTER TABLE ONLY unknown_file ADD CONSTRAINT unknown_files_pk PRIMARY KEY (ed2k, size);
+
+CREATE TABLE pending_mylist_update (
+    fid integer NOT NULL,
+    my_watched timestamp without time zone,
+    my_state integer,
+    my_file_state integer,
+    my_storage text,
+    my_source text,
+    my_other text,
+    added timestamp without time zone DEFAULT now(),
+    start timestamp without time zone
+);
+ALTER TABLE ONLY pending_mylist_update ADD CONSTRAINT pending_mylist_update_pk PRIMARY KEY (fid);
+
+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
+);
+ALTER TABLE ONLY pending_request ADD 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_priority_idx ON pending_request USING btree (priority, added, start);
+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
+);
+
+ALTER TABLE ONLY config ADD CONSTRAINT config_pk PRIMARY KEY (key);
+
+CREATE TABLE host (
+    host_id serial NOT NULL,
+    name character varying(100),
+    is_udp_host boolean DEFAULT false
+);
+ALTER TABLE ONLY host ADD CONSTRAINT host_pk PRIMARY KEY (host_id);
+ALTER TABLE ONLY host ADD CONSTRAINT host_unique_name UNIQUE (name);
+
+CREATE TABLE log (
+    log_id serial NOT NULL,
+    type integer,
+    log text
+);
+ALTER TABLE ONLY log ADD 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)));
+
+
+CREATE RULE config_updated_rule AS ON UPDATE TO config DO NOTIFY config_changed;
+
+CREATE RULE file_episode_rel_ignore_duplicate AS ON INSERT TO file_episode_rel WHERE (EXISTS (SELECT 1 FROM file_episode_rel WHERE ((file_episode_rel.fid = new.fid) AND (file_episode_rel.eid = new.eid)))) DO INSTEAD NOTHING;
+COMMENT ON RULE file_episode_rel_ignore_duplicate ON file_episode_rel IS 'Entries to this table are duplicated in exports';
+
+CREATE RULE file_location_ignore_duplicate AS ON INSERT TO file_location WHERE (EXISTS (SELECT 1 FROM file_location WHERE (file_location.fid = new.fid))) DO INSTEAD NOTHING;
+
+CREATE RULE new_pending_request_rule AS ON INSERT TO pending_request DO NOTIFY new_pending_request;
+
+CREATE RULE pending_request_ignore_duplicate AS ON INSERT TO pending_request WHERE (EXISTS (SELECT 1 FROM pending_request WHERE (((((pending_request.aid = new.aid) AND (pending_request.eid = new.eid)) AND (pending_request.fid = new.fid)) AND (pending_request.ed2k = new.ed2k)) AND (pending_request.size = new.size)))) DO INSTEAD NOTHING;
+
+CREATE RULE unknown_file_ignore_duplicate AS ON INSERT TO unknown_file WHERE (EXISTS (SELECT 1 FROM unknown_file WHERE ((unknown_file.ed2k = new.ed2k) AND (unknown_file.size = new.size)))) DO INSTEAD NOTHING;
+COMMENT ON RULE unknown_file_ignore_duplicate ON unknown_file IS 'Adding the same file more than once can happen';
+