From: APTX Date: Tue, 7 May 2013 22:56:59 +0000 (+0200) Subject: Add "OR REPLACE" to all CREATE RULE/VIEW statements in the schema. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=6a5ab6408082a9d572dbe2b6f272ab19708e4ccd;p=localmylist.git Add "OR REPLACE" to all CREATE RULE/VIEW statements in the schema. --- diff --git a/localmylist/share/schema/schema.sql b/localmylist/share/schema/schema.sql index be2f313..040a98f 100644 --- a/localmylist/share/schema/schema.sql +++ b/localmylist/share/schema/schema.sql @@ -257,7 +257,7 @@ CREATE TABLE log ( CONSTRAINT log_pk PRIMARY KEY (log_id) ); -CREATE VIEW rename_data AS +CREATE OR REPLACE 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.total_episode_count, a.highest_epno, 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, @@ -315,22 +315,22 @@ CREATE OR REPLACE RULE fix_highest_epno AS DO UPDATE anime SET highest_epno = new.epno WHERE anime.aid = new.aid; -CREATE RULE config_updated_rule AS ON UPDATE TO config DO NOTIFY config_changed; +CREATE OR REPLACE 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; +CREATE OR REPLACE 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 AND file_location.host_id = new.host_id AND file_location.path = new.path))) DO INSTEAD NOTHING; -CREATE RULE file_location_insert_rename_rule AS ON INSERT TO file_location DO NOTIFY rename_data_changed; +CREATE OR REPLACE RULE file_location_ignore_duplicate AS ON INSERT TO file_location WHERE (EXISTS (SELECT 1 FROM file_location WHERE (file_location.fid = new.fid AND file_location.host_id = new.host_id AND file_location.path = new.path))) DO INSTEAD NOTHING; +CREATE OR REPLACE RULE file_location_insert_rename_rule AS ON INSERT TO file_location DO NOTIFY rename_data_changed; -CREATE RULE new_pending_request_rule AS ON INSERT TO pending_request DO NOTIFY new_pending_request; +CREATE OR REPLACE 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 OR REPLACE 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'; +CREATE OR REPLACE 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 is normal'; -CREATE RULE new_pending_mylist_update_rule AS ON INSERT TO pending_mylist_update DO NOTIFY new_pending_mylist_update; +CREATE OR REPLACE RULE new_pending_mylist_update_rule AS ON INSERT TO pending_mylist_update DO NOTIFY new_pending_mylist_update; -- Add rules CREATE OR REPLACE RULE anime_insert_notify_rule AS