Commits

Boris Nagaev committed e6d0253

Team: add column 'comment_base'

  • Participants
  • Parent commits 82c5617

Comments (0)

Files changed (4)

File DatabaseMigration.txt

 ALTER TABLE "thechess_team"
   ADD constraint "fk_thechess_team_init" foreign key ("init_id") references "thechess_team" ("id");
 
+ALTER TABLE "thechess_team"
+  ADD COLUMN "comment_base_id" bigint,
+  ADD constraint "fk_thechess_team_comment_base" foreign key ("comment_base_id") references "thechess_comment" ("id");
 
 3.0.8 to 3.0.9
 ==============

File postgres-create-tables.sql

   "name" text not null,
   "description" text not null,
   "init_id" bigint,
-  "created" timestamp
+  "created" timestamp,
+  "comment_base_id" bigint
 );
 CREATE TABLE "winners_competition" (
   "thechess_user_id" bigint not null,
   ADD constraint "fk_thechess_user_comment_base" foreign key ("comment_base_id") references "thechess_comment" ("id");
 ALTER TABLE "thechess_team"
   ADD constraint "fk_thechess_team_init" foreign key ("init_id") references "thechess_team" ("id");
+ALTER TABLE "thechess_team"
+  ADD constraint "fk_thechess_team_comment_base" foreign key ("comment_base_id") references "thechess_comment" ("id");
 
 CREATE INDEX "members_competitions_thechess_competition" on "members_competitions" ("thechess_competition_id");
 CREATE INDEX "members_competitions_thechess_user" on "members_competitions" ("thechess_user_id");

File src/model/Team.cpp

 Team::Team(bool)
 { }
 
+bool Team::has_comment_base() const {
+    return comment_base_;
 }
 
+const CommentPtr& Team::comment_base() {
+    if (!comment_base_) {
+        comment_base_ = session()->add(new Comment(true));
+        comment_base_.modify()->set_type(Comment::CHAT_ROOT);
+        comment_base_.flush();
+    }
+    return comment_base_;
+}
+
+}
+

File src/model/Team.hpp

         return banned_;
     }
 
+    /** \name Methods of comments */
+    /* @{ */
+
+    /** Return if there is a comment base  */
+    bool has_comment_base() const;
+
+    /** Return comment base.
+    Lazy created.
+    */
+    const CommentPtr& comment_base();
+
+    /** Get comment base (may return 0) */
+    const CommentPtr& comment_base() const {
+        return comment_base_;
+    }
+
+    /* @} */
+
 private:
     Users members_;
     Users candidates_;
     Users banned_;
+    CommentPtr comment_base_;
 };
 
 }