# comments

## Description

Comments  
Multi-line  
table  
comment

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE `comments` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `post_id` bigint NOT NULL,
  `user_id` int NOT NULL,
  `comment` text NOT NULL COMMENT 'Comment\nMulti-line\r\ncolumn\rcomment',
  `post_id_desc` bigint GENERATED ALWAYS AS ((`post_id` * -(1))) VIRTUAL,
  `created` datetime NOT NULL,
  `updated` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `post_id` (`post_id`,`user_id`),
  KEY `comments_user_id_fk` (`user_id`),
  KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),
  CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),
  CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\nMulti-line\r\ntable\rcomment'
```

</details>

## Columns

| Name | Type | Default | Nullable | Extra Definition | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | ---------------- | -------- | ------- | ------- |
| id | bigint |  | false | auto_increment | [logs](logs.md) |  |  |
| post_id | bigint |  | false |  | [comment_stars](comment_stars.md) | [posts](posts.md) |  |
| user_id | int |  | false |  | [comment_stars](comment_stars.md) | [users](users.md) |  |
| comment | text |  | false |  |  |  | Comment<br>Multi-line<br>column<br>comment |
| post_id_desc | bigint |  | true | GENERATED ALWAYS AS (\`post_id\` * -(1)) VIRTUAL |  |  |  |
| created | datetime |  | false |  |  |  |  |
| updated | datetime |  | true |  |  |  |  |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| comments_post_id_fk | FOREIGN KEY | FOREIGN KEY (post_id) REFERENCES posts (id) |
| comments_user_id_fk | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users (id) |
| post_id | UNIQUE | UNIQUE KEY post_id (post_id, user_id) |
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |

## Indexes

| Name | Definition |
| ---- | ---------- |
| comments_post_id_user_id_idx | KEY comments_post_id_user_id_idx (post_id, user_id) USING BTREE |
| comments_user_id_fk | KEY comments_user_id_fk (user_id) USING BTREE |
| PRIMARY | PRIMARY KEY (id) USING BTREE |
| post_id | UNIQUE KEY post_id (post_id, user_id) USING BTREE |

## Relations

```mermaid
erDiagram

"logs" }o--o| "comments" : "Additional Relation"
"comments" }o--|| "posts" : "FOREIGN KEY (post_id) REFERENCES posts (id)"
"comment_stars" }o--|| "comments" : "FOREIGN KEY (comment_post_id, comment_user_id) REFERENCES comments (post_id, user_id)"
"comments" }o--|| "users" : "FOREIGN KEY (user_id) REFERENCES users (id)"

"comments" {
  bigint id PK
  bigint post_id FK
  int user_id FK
  text comment
  bigint post_id_desc
  datetime created
  datetime updated
}
"logs" {
  bigint id PK
  int user_id
  bigint post_id
  bigint comment_id
  bigint comment_star_id
  text payload
  datetime created
}
"posts" {
  bigint id PK
  int user_id FK
  varchar_255_ title
  text body
  enum__public___private___draft__ post_type
  datetime created
  datetime updated
}
"comment_stars" {
  bigint id PK
  int user_id
  bigint comment_post_id FK
  int comment_user_id FK
  timestamp created
  timestamp updated
}
"users" {
  int id PK
  varchar_50_ username
  varchar_50_ password
  varchar_355_ email
  timestamp created
  timestamp updated
}
```

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
