diff --git a/app/DoctrineMigrations/Version20190227233244.php b/app/DoctrineMigrations/Version20190227233244.php new file mode 100644 index 0000000..f253901 --- /dev/null +++ b/app/DoctrineMigrations/Version20190227233244.php @@ -0,0 +1,28 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('CREATE UNIQUE INDEX unique_post_id_comment_number ON posts.comments (post_id, number)'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('DROP INDEX posts.unique_post_id_comment_number'); + } +} diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php index 6c114f2..2d1937a 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php @@ -9,6 +9,8 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User; /** * @ORM\Table(name="comments", schema="posts", indexes={ * @ORM\Index(name="idx_comment_created_at", columns={"created_at"}) + * }, uniqueConstraints={ + * @ORM\UniqueConstraint(name="unique_post_id_comment_number", columns={"post_id", "number"}) * }) * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\CommentRepository") */