はてなブログAPIでデータ取得して保存するためのDBテーブル設計。
前回まで
http://ytyaru.hatenablog.com/entry/2017/05/09/000000
http://ytyaru.hatenablog.com/entry/2017/06/07/000000
http://ytyaru.hatenablog.com/entry/2017/06/09/000000
http://ytyaru.hatenablog.com/entry/2017/06/11/000000
http://ytyaru.hatenablog.com/entry/2017/06/12/000000
http://ytyaru.hatenablog.com/entry/2017/06/23/000000
http://ytyaru.hatenablog.com/entry/2017/06/24/000000
http://ytyaru.hatenablog.com/entry/2017/06/25/000000
DB
SQLite3を使う。
| DB | 説明 |
|---|---|
| Hatena.Accounts.sqlite | パスワードなどのアカウント情報(プライベート情報) |
| Hatena.Blog.sqlite | ブログのデータ |
| Hatena.PhotoLife.sqlite | 画像ファイルパス |
DBファイルの親子関係
Hatena.Accounts.sqlite
| テーブル | 説明 |
|---|---|
| Accounts | ユーザID、パスワード、メールアドレスなどのアカウント情報 |
| OAuthApplication | ConsumerKey, ConsumerSecret, Token, TokenSecret |
テーブルの親子関係
- Accounts
- OAuthApplication
Accounts
| 列名 | 型 | Key | Unique | NotNull | Check | Default |
|---|---|---|---|---|---|---|
| Id | integer | P | - | - | - | - |
| HatenaId | text | - | o | o | - | - |
| Nickname | text | - | - | o | - | - |
| Password | text | - | - | o | - | - |
| MailAddress | text | - | o | o | - | - |
OAuthApplication
| 列名 | 型 | Key | Unique | NotNull | Check | Default |
|---|---|---|---|---|---|---|
| Id | integer | P | - | - | - | - |
| Name | text | - | - | - | - | - |
| Description | text | - | - | - | - | - |
| Url | text | - | - | - | - | - |
| Logo | BLOB | - | - | - | - | - |
| Icon | BLOB | - | - | - | - | - |
| ConsumerKey | text | - | - | o | - | - |
| ConsumerSecret | text | - | - | o | - | - |
| read_public | integer | - | - | - | val=0 or val=1 | 0 |
| write_public | integer | - | - | - | val=0 or val=1 | 0 |
| read_private | integer | - | - | - | val=0 or val=1 | 0 |
| write_private | integer | - | - | - | val=0 or val=1 | 0 |
| AccessToken | text | - | - | - | - | - |
| AccessTokenSecret | text | - | - | - | - | - |
実際使うのは以下の4つ。
- ConsumerKey
- ConsumerSecret
- AccessToken
- AccessTokenSecret
また、スコープも必要。
- read_public
- write_public
- read_private
- write_private
それ以外はオマケ。
Hatena.Blog.sqlite
- Hatena.Blog.sqlite
- Hatena.Blog.{HatenaId}.sqlite
- Hatena.Blog.{HatenaId}.{BlogId}.sqlite
- Hatena.Blog.Entries.{HatenaId}.{BlogId}.sqlite
ファイル単位でどう分離するか。
テーブル一覧
| テーブル | 説明 |
|---|---|
| Blogs | アカウントが所持しているブログ |
| Entries | ブログが所持している記事 |
Blogs
| 列名 | 型 | Key | Unique | NotNull | Check | Default |
|---|---|---|---|---|---|---|
| Id | integer | P | - | - | - | - |
| AccountId | text | F | - | - | - | - |
| BlogId | text | text | - | o | o | -|- |
| HatenaBlogId | text | - | o | o | - | - |
| Title | text | text | - | - | - | -|- |
| Description | text | - | - | - | - | - |
無料アカウントの場合、ブログは3つまで。
Entries
| 列名 | 型 | Key | Unique | NotNull | Check | Default |
|---|---|---|---|---|---|---|
| Id | integer | integer | P | - | - | -|- |
| BlogId | integer | F | - | - | - | - |
| EntryId | text | - | - | - | - | - |
| Url | text | - | - | - | - | - |
| Title | text | - | - | - | - | - |
| Updated | text | - | - | - | - | - |
| Published | text | - | - | - | - | - |
| Edited | text | - | - | - | - | - |
| Summary | text | - | - | - | - | - |
| ContentType | text | - | - | - | - | - |
| Content | text | - | - | - | - | - |
本文はContent。サニタイズされたデータを元に戻してから保存したい。
Hatena.PhotoLife.sqlite
- Hatena.PhotoLife.Images.{HatenaId}.{BlogId}.sqlite
- Hatena.PhotoLife.Movies.{HatenaId}.{BlogId}.sqlite
上記のようにファイルの種類によって別DBにすべきかもしれない。
テーブル一覧
| テーブル | 説明 |
|---|---|
| PhotoLife | フォトライフに投稿した画像または動画データ |
| Images | フォトライフに投稿した画像データ |
| Movies | フォトライフに投稿した動画データ |
ファイルの種類別に別DBにするならテーブルは一つでいい。
PhotoLife
| 列名 | 型 | Key | Unique | NotNull | Check | Default |
|---|---|---|---|---|---|---|
| Id | integer | integer | integer | P | - | -|-|- |
| PhotoLifeId | text | - | o | - | - | - |
| Title | text | text | - | - | - | -|- |
| ImageUrl | text | text | - | - | - | -|- |
| ImageUrlSmall | text | text | - | - | - | -|- |
| Syntax | text | text | - | - | - | -|- |
| AlternateUrlUrl | text | - | - | - | - | - |
| EditUrl | text | - | - | - | - | - |
| Image | BLOB | - | - | - | - | - |
重複する部分が多いかもしれない。画像データはBLOBで保存する。
はてなフォトライフAtomAPI - Hatena Developer Center
懸念
#SQLアンチパターン ファントムファイルに立ち向かう - あおうさ@日記
他
- HTML(Markdown)、画像、の外部アップロード先、またはローカルファイルパスを記録すべきか
SQLite4
SQLite4が現れた! — 鱒身(Masu_mi)のブログ
SQLite4: SQLite4
SQLite3でなく4があるらしい。
所感
ものすごく大変そうな予感。