コンテンツにスキップ

ありがとうございます。
それでは、第2段階としてデータベース設計(ER設計・テーブル設計)を行います。

今回は将来的な機能追加(メンター、試験、アンケート、ライブ授業など)も考慮し、拡張性を重視した設計にします。


第2段階 DB設計

システム全体ER

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
                User
                  │
                  │
              UserRole
                  │
                  ▼
                Role
──────────────────────────────────────

Category
    │
    ▼
 Course
    │
    ▼
 Section
    ▲
    │ parent_section_id
    │
 Section
    │
    ▼
 Lesson
    │
    ▼
 Content
    │
    ├──────────────┐
    │              │
    ▼              ▼
VideoContent   TextContent
    │              │
    ├──────────────┤
    ▼              ▼
QuizContent    FileContent
    │
    ▼
QuizChoice

──────────────────────────────────────

LearningHistory

QuizAnswerHistory

ApprovalHistory

Notification

このERをベースに設計します。


テーブル一覧

マスタ

テーブル 説明
users ユーザー
roles 権限
user_roles ユーザー権限
categories カテゴリ

教材

テーブル 説明
courses コース
sections 章(無限階層)
lessons レッスン
contents コンテンツ共通

コンテンツ

テーブル 説明
video_contents 動画
text_contents テキスト
quiz_contents クイズ
quiz_choices 選択肢
file_contents ファイル

学習

テーブル 説明
learning_histories 学習履歴
quiz_answer_histories クイズ回答履歴

管理

テーブル 説明
approval_histories 承認履歴
notifications 通知

users

1
2
3
4
5
6
7
id
name
email
password
enabled
created_at
updated_at

SpringSecurityそのまま利用できます。


roles

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
id

code

ADMIN

TEACHER

MENTOR

STUDENT

name

user_roles

複数ロール対応します。

1
2
3
user_id

role_id

例えば

1
2
3
4
5
6
7
山田先生

↓

TEACHER

MENTOR

という割り当ても可能になります。


categories

教材カテゴリ

1
2
3
4
5
6
7
id

parent_id

name

display_order

こちらも無限階層です。

1
2
3
4
5
6
7
Java

Spring

SpringBoot

Security

courses

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
id

category_id

title

description

teacher_id

status

published_at

thumbnail

created_at

updated_at

teacher_idはusersを参照します。


sections

これが教材の木構造です。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
id

course_id

parent_section_id

title

description

display_order

例えば

1
2
3
4
5
6
7
8
9
Java

 第1章

   1-1

     1-1-1

        Lesson

となります。


lessons

1
2
3
4
5
6
7
8
9
id

section_id

title

description

display_order

Lessonはコンテンツをまとめる箱です。


contents

ここが一番重要です。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
id

lesson_id

content_type

title

summary

author_id

status

published_at

display_order

created_at

updated_at

全種類共通になります。


video_contents

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
content_id

video_type

video_id

video_url

thumbnail

duration

video_type

1
2
3
4
5
YOUTUBE

VIMEO

R2

text_contents

1
2
3
4
5
content_id

body

format

format

1
2
3
TEXT

MARKDOWN

Markdownなら

1
2
3
4
5
6
7
8
9
保存

↓

HTML変換

↓

Thymeleaf表示

になります。


quiz_contents

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
content_id

category

question

multiple_answer

correct_answer_count

explanation

例えば

1
2
3
6択

正解2つ

なら

1
2
3
multiple_answer=true

correct_answer_count=2

になります。


quiz_choices

1
2
3
4
5
6
7
8
9
id

quiz_content_id

choice_text

is_correct

display_order

例えば

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
A

B

C

D

E

F

全部ここです。


file_contents

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
content_id

file_type

file_name

storage_path

mime_type

file_size

download_count

Cloudflare R2でも

S3でも

ローカルでも

対応できます。


learning_histories

受講履歴

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
id

student_id

lesson_id

content_id

started_at

completed_at

progress

last_accessed_at

progress

1
0〜100

quiz_answer_histories

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
id

student_id

quiz_content_id

score

is_correct

answered_at

後で分析できます。


approval_histories

教材承認履歴

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
id

content_id

applicant_id

approver_id

status

comment

approved_at

これで

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
教師

↓

申請

↓

管理者

↓

承認

↓

公開

が追跡できます。


notifications

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
id

user_id

title

message

is_read

created_at

例えば

1
2
3
4
5
承認されました

差し戻しされました

公開されました

などになります。


インデックス設計

性能面では以下のインデックスを推奨します。

テーブル インデックス
courses (teacher_id, status)
sections (course_id, parent_section_id, display_order)
lessons (section_id, display_order)
contents (lesson_id, status, content_type, display_order)
learning_histories (student_id, lesson_id)
quiz_answer_histories (student_id, quiz_content_id)
approval_histories (content_id, approver_id)

監査カラム(全テーブル共通)

更新履歴を追跡しやすくするため、多くのテーブルで以下の共通カラムを持つことをおすすめします。

1
2
3
4
5
6
7
8
9
created_by
created_at

updated_by
updated_at

deleted
deleted_at
deleted_by

JPAの監査機能(Auditing)を利用すると、自動設定できます。


ここで見直したい設計ポイント

ここまでの設計でも十分実装可能ですが、さらに拡張性を高めるために、次の2点を第3段階で改善する予定です。

  1. コンテンツのバージョン管理

    • 公開中の教材を保持したまま編集・再申請できるようにする

    • 「下書き」と「公開版」を同時に持てる設計

  2. 教材公開の柔軟な制御

    • コース公開・レッスン公開・コンテンツ公開を分離

    • 公開開始・公開終了日時によるスケジュール公開

    • 将来的な有料/無料、対象受講者限定公開への対応

この2つは実運用では非常に重要なため、第3段階(Springプロジェクト構成設計)の前に取り込むことで、より実践的な教材管理システムになります。