# ER図

本ドキュメントでは、Wikipedia iOSアプリケーションのデータベース構造をER図として表現します。

## Wikipediaモデル（メインデータモデル）

```mermaid
erDiagram
    WMFArticle {
        String key PK
        String variant
        String displayTitle
        String displayTitleHTMLString
        String snippet
        String wikidataDescription
        String wikidataID
        Int64 pageID
        Int16 ns
        String imageURLString
        Int32 imageWidth
        Int32 imageHeight
        String thumbnailURLString
        Date savedDate
        Date viewedDate
        Date viewedDateWithoutTime
        String viewedFragment
        Double viewedScrollPosition
        Boolean wasSignificantlyViewed
        Date lastModifiedDate
        Boolean isDownloaded
        Date downloadRetryDate
        Int16 downloadAttemptCount
        Int32 errorCodeNumber
        Boolean isExcludedFromFeed
        Boolean isConversionFromMobileViewNeeded
        Boolean isSavedMigrated
        Date newsNotificationDate
        Int32 placesSortOrder
        Double latitude
        Double longitude
        Int64 signedQuadKey
        Int64 geoDimensionNumber
        Int16 geoTypeNumber
        Transformable pageViews
    }

    ReadingList {
        String canonicalName
        String readingListDescription
        Int64 readingListID
        Int64 countOfEntries
        Date createdDate
        Date updatedDate
        Int64 sortOrder
        Boolean isDefault
        Boolean isDeletedLocally
        Boolean isUpdatedLocally
        String errorCode
        String color
        String iconName
        String imageName
    }

    ReadingListEntry {
        Int64 readingListEntryID
        String articleKey
        String displayTitle
        String variant
        Date createdDate
        Date updatedDate
        Boolean isDeletedLocally
        Boolean isUpdatedLocally
        String errorCode
    }

    WMFContentGroup {
        String key PK
        Int32 contentGroupKindInteger
        Int16 contentTypeInteger
        Date date
        Date midnightUTCDate
        Date contentDate
        Date contentMidnightUTCDate
        String siteURLString
        String articleURLString
        String featuredContentIdentifier
        Int64 countOfFullContent
        Transformable contentPreview
        Int32 dailySortPriority
        Boolean isVisible
        Boolean wasDismissed
        Int16 undoTypeInteger
        Transformable location
        Transformable placemark
        String placement
        String variant
    }

    WMFContent {
        Transformable object
    }

    WMFKeyValue {
        String key PK
        String group
        Transformable value
        Date date
    }

    ReadingList ||--o{ ReadingListEntry : "contains"
    ReadingList }o--o{ WMFArticle : "articles"
    ReadingList }o--o{ WMFArticle : "previewArticles"
    WMFContentGroup ||--o| WMFContent : "fullContent"
```

## WMFDataモデル（記事タブ・ページビュー）

```mermaid
erDiagram
    CDArticleTab {
        UUID identifier PK
        Boolean isCurrent
        Date timestamp
    }

    CDArticleTabItem {
        UUID identifier PK
        Boolean isCurrent
    }

    CDPage {
        String title
        String projectID
        Int16 namespaceID
        Date timestamp
    }

    CDPageView {
        Date timestamp
        Int64 numberOfSeconds
    }

    CDPageSavedInfo {
        Date savedDate
    }

    CDCategory {
        String title
        String projectID
    }

    CDYearInReviewReport {
        Int32 year
    }

    CDYearInReviewSlide {
        String id PK
        Int32 year
        Binary data
    }

    CDArticleTab ||--o{ CDArticleTabItem : "items"
    CDArticleTabItem }o--|| CDPage : "page"
    CDPage ||--o{ CDPageView : "pageViews"
    CDPage ||--o| CDPageSavedInfo : "savedInfo"
    CDPage }o--o{ CDCategory : "categories"
    CDPageView }o--o| CDPageView : "previousPageView"
    CDPageView ||--o{ CDPageView : "nextPageViews"
    CDYearInReviewReport ||--o{ CDYearInReviewSlide : "slides"
```

## Cacheモデル

```mermaid
erDiagram
    CacheGroup {
        String key PK
    }

    CacheItem {
        String key PK
        URI url
        String variant
        Date date
        Boolean isDownloaded
    }

    CacheGroup }o--o{ CacheItem : "cacheItems"
    CacheGroup }o--o{ CacheItem : "mustHaveCacheItems"
```

## PersistentCacheモデル

```mermaid
erDiagram
    PersistentCacheGroup {
        String key PK
    }

    PersistentCacheItem {
        String key
        URI url PK
        String variant
        Date date
        Boolean isDownloaded
    }

    PersistentCacheGroup }o--o{ PersistentCacheItem : "cacheItems"
    PersistentCacheGroup ||--o{ PersistentCacheItem : "mustHaveCacheItems"
```

## RemoteNotificationsモデル

```mermaid
erDiagram
    RemoteNotification {
        String id
        String key PK "UNIQUE"
        String wiki
        String categoryString
        String typeString
        Date date
        Boolean isRead
        String agentId
        String agentName
        String messageHeader
        String messageBody
        Transformable messageLinks
        String titleFull
        String titleText
        String titleNamespace
        Int16 titleNamespaceKey
        String section
        String revisionID
        String utcUnixString
    }

    WMFKeyValue_Notification {
        String key
        String group
        Transformable value
        Date date
    }
```

## EventPlatformEventsモデル

```mermaid
erDiagram
    WMFEPEventRecord {
        String stream
        Binary data
        Date recorded
        Boolean purgeable
    }
```

## 全体関係図（概要）

```mermaid
graph TB
    subgraph "Wikipedia Model"
        WMFArticle
        ReadingList
        ReadingListEntry
        WMFContentGroup
        WMFContent
        WMFKeyValue
    end

    subgraph "WMFData Model"
        CDArticleTab
        CDArticleTabItem
        CDPage
        CDPageView
        CDPageSavedInfo
        CDCategory
        CDYearInReviewReport
        CDYearInReviewSlide
    end

    subgraph "Cache Model"
        CacheGroup
        CacheItem
    end

    subgraph "PersistentCache Model"
        PersistentCacheGroup
        PersistentCacheItem
    end

    subgraph "RemoteNotifications Model"
        RemoteNotification
    end

    subgraph "EventPlatform Model"
        WMFEPEventRecord
    end

    ReadingList --> ReadingListEntry
    ReadingList --> WMFArticle
    WMFContentGroup --> WMFContent
    CDArticleTab --> CDArticleTabItem
    CDArticleTabItem --> CDPage
    CDPage --> CDPageView
    CDPage --> CDPageSavedInfo
    CDPage --> CDCategory
    CDYearInReviewReport --> CDYearInReviewSlide
    CacheGroup --> CacheItem
    PersistentCacheGroup --> PersistentCacheItem
```

## リレーション凡例

| 記号 | 意味 |
|------|------|
| `\|\|` | 1（必須） |
| `\|o` | 0または1（オプション） |
| `o{` | 0以上（多） |
| `\|{` | 1以上（多、必須） |
