SQL

CREATE TABLE textbook_lessons  (
  id          INTEGER PRIMARY KEY AUTOINCREMENT,
  unit_id     INTEGER NOT NULL REFERENCES textbook_units(id),
  lesson_order INTEGER NOT NULL,
  -- 课序号
    title       TEXT NOT NULL,
  -- 课文标题
    lesson_type TEXT DEFAULT 'text',
  -- text/poem/vocab/dialogue/song
    page_start  INTEGER,
  -- 起始页码(对应扫描图)
    page_end    INTEGER,
  -- 结束页码
    created_at  DATETIME DEFAULT (datetime('now'))
)

+ Add column

Columns

Column Data type Allow null Primary key Actions
id INTEGER Rename | Drop
unit_id INTEGER Rename | Drop
lesson_order INTEGER Rename | Drop
title TEXT Rename | Drop
lesson_type TEXT Rename | Drop
page_start INTEGER Rename | Drop
page_end INTEGER Rename | Drop
created_at DATETIME Rename | Drop

Foreign Keys

Column Destination
unit_id textbook_units.id

+ Add index

Indexes

Name Columns Unique SQL Drop?
idx_lessons_unit unit_id SQL
CREATE INDEX idx_lessons_unit
ON textbook_lessons(unit_id)
Drop