Permalink
Browse files

добавление колонки БД чтобы различать избранные темы и отслеживаемые …

…(для #261)
  • Loading branch information...
maxcom committed May 11, 2012
1 parent 0de273f commit a5dc423ae6bb89e0878b70269328de93bce69e10
Showing with 54 additions and 0 deletions.
  1. +1 −0 sql/main.xml
  2. +53 −0 sql/updates/2012-05-11-memories-type.xml
View
@@ -23,5 +23,6 @@
<include file="sql/updates/2012-05-04-comdel-to-java.xml"/>
<include file="sql/updates/2012-05-06-remove-groups-stat4.xml"/>
<include file="sql/updates/2012-05-06-optimize-statupdate2.xml"/>
+ <include file="sql/updates/2012-05-11-memories-type.xml"/>
</databaseChangeLog>
@@ -0,0 +1,53 @@
+<!--
+ ~ Copyright 1998-2012 Linux.org.ru
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<databaseChangeLog
+ xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
+ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
+
+ <changeSet id="2012051101" author="Maxim Valyanskiy">
+ <addColumn tableName="memories">
+ <column name="watch" type="boolean" defaultValueBoolean="true">
+ <constraints nullable="false"/>
+ </column>
+ </addColumn>
+ <sql>
+ drop index memories_un;
+ create unique index memories_un on memories(userid,topic,watch);
+ </sql>
+ </changeSet>
+ <changeSet id="2012051102" author="Maxim Valyanskiy">
+ <sql splitStatements="false">
+CREATE OR REPLACE FUNCTION event_comment() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+DECLARE
+ parent_author int;
+BEGIN
+ IF NEW.replyto IS NOT NULL THEN
+ SELECT userid INTO parent_author FROM comments WHERE id = NEW.replyto;
+ INSERT INTO user_events (userid, type, private, message_id, comment_id) SELECT memories.userid, 'WATCH', 'f', NEW.topic, NEW.id FROM memories WHERE memories.topic = NEW.topic AND NEW.userid != memories.userid AND memories.userid != parent_author AND NOT EXISTS (SELECT ignore_list.userid FROM ignore_list WHERE ignore_list.userid=memories.userid AND ignored=NEW.userid) AND watch;
+ ELSE
+ INSERT INTO user_events (userid, type, private, message_id, comment_id) SELECT memories.userid, 'WATCH', 'f', NEW.topic, NEW.id FROM memories WHERE memories.topic = NEW.topic AND NEW.userid != memories.userid AND NOT EXISTS (SELECT ignore_list.userid FROM ignore_list WHERE ignore_list.userid=memories.userid AND ignored=NEW.userid) AND watch;
+ END IF;
+
+ RETURN NULL;
+END;
+$$;
+ </sql>
+ </changeSet>
+</databaseChangeLog>

0 comments on commit a5dc423

Please sign in to comment.