---
# System prepended metadata

title: Untitled

---

## DB設計をしよう

### 必要テーブル
#### ミニマム
- users
    - id
    - id_name
    - display_name
    - birthday
    - place
    - description
    - icon_url
    - email
    - firebase_token
    - tweet_num
    - followee_num
    - follower_num

- tweets
    - id
    - user_id
    - content
    - type(1: default, 2: retweet, 3: reply)
    - target_id

- tweet_media
    - id
    - sequence
    - media_url
    - tweet_id

- user_follows
    - follower_id
    - followee_id

- favorites
    - tweet_id
    - user_id


%%%%% 保留 (replies table 必要じゃね？) %%%%%
- "A: id=1"
    - "B: id=2"
        - "C: id=3"
            - "D: id=4"
        - "E: id=5"

- replies
    - id
    - parent_tweet_id
    - level ("id"のtweetから見て何番目の親か)

id, parent_tweet_id, level
1, null, null
2, 1, 1
3, 1, 2
3, 2, 1
4, 1, 3
4, 2, 2
4, 3, 1
5, 1, 2
5, 2, 1


- threads
    - id
    - root_tweet_id
    - last_tweet_id

- replies
    - id
    - thread_id
    - sequence

threads
id, root, last
1, 1, 4
2, 2, 5

replies
id, thread, sequence
1, 1, 0
2, 1, 1
3, 1, 2
4, 1, 3
1, 2, 0
2, 2, 1
5, 2, 2


%%%%% 保留 %%%%%



#### 発展
- rooms
    - id

- room_users
    - room_id
    - user_id

- messages
    - user_id
    - room_id
    - content