-- sort local SQLite schema v1
-- 기준: 메타데이터는 SQLite, 실제 MP4/JPG는 _StDown/instagram/<account>/ 아래 파일로 저장한다.

PRAGMA foreign_keys = ON;

CREATE TABLE IF NOT EXISTS schema_migrations (
    version INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    applied_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS app_settings (
    setting_key TEXT PRIMARY KEY,
    setting_value TEXT NOT NULL DEFAULT '',
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS collector_profile (
    id INTEGER PRIMARY KEY CHECK (id = 1),
    server_user_id INTEGER,
    collector_code TEXT NOT NULL DEFAULT '',
    display_name TEXT NOT NULL DEFAULT '',
    status TEXT NOT NULL DEFAULT 'local_only',
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX IF NOT EXISTS uq_collector_profile_code
    ON collector_profile(collector_code) WHERE collector_code <> '';

CREATE TABLE IF NOT EXISTS device_profile (
    id INTEGER PRIMARY KEY CHECK (id = 1),
    server_device_id INTEGER,
    computer_id_hash TEXT NOT NULL DEFAULT '',
    device_name TEXT NOT NULL DEFAULT '',
    token_version INTEGER NOT NULL DEFAULT 0,
    token_expires_at TEXT,
    p2p_enabled INTEGER NOT NULL DEFAULT 0,
    last_seen_at TEXT,
    status TEXT NOT NULL DEFAULT 'local_only',
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS storage_roots (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    root_code TEXT NOT NULL,
    root_path TEXT NOT NULL,
    is_default INTEGER NOT NULL DEFAULT 0,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(root_code),
    UNIQUE(root_path)
);
CREATE UNIQUE INDEX IF NOT EXISTS uq_storage_roots_default
    ON storage_roots(is_default) WHERE is_default = 1;

CREATE TABLE IF NOT EXISTS groups_cache (
    server_group_id INTEGER PRIMARY KEY,
    group_code TEXT NOT NULL DEFAULT '',
    group_name TEXT NOT NULL,
    introduction TEXT NOT NULL DEFAULT '',
    join_policy TEXT NOT NULL DEFAULT 'approval',
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    my_role TEXT NOT NULL DEFAULT 'MEMBER',
    member_status TEXT NOT NULL DEFAULT 'ACTIVE',
    synced_at TEXT,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS group_members_cache (
    server_group_id INTEGER NOT NULL,
    server_user_id INTEGER NOT NULL,
    collector_code TEXT NOT NULL DEFAULT '',
    display_name TEXT NOT NULL DEFAULT '',
    role TEXT NOT NULL DEFAULT 'MEMBER',
    member_status TEXT NOT NULL DEFAULT 'ACTIVE',
    synced_at TEXT,
    PRIMARY KEY(server_group_id, server_user_id),
    FOREIGN KEY(server_group_id) REFERENCES groups_cache(server_group_id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS social_accounts (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_account_id INTEGER,
    platform TEXT NOT NULL DEFAULT 'instagram',
    platform_account_id TEXT NOT NULL DEFAULT '',
    username TEXT NOT NULL,
    display_name TEXT NOT NULL DEFAULT '',
    profile_url TEXT NOT NULL DEFAULT '',
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    owner_server_user_id INTEGER,
    memo TEXT NOT NULL DEFAULT '',
    active INTEGER NOT NULL DEFAULT 1,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(platform, username)
);
CREATE INDEX IF NOT EXISTS idx_social_accounts_visibility_username
    ON social_accounts(visibility, username);

CREATE TABLE IF NOT EXISTS account_group_visibility (
    account_id INTEGER NOT NULL,
    server_group_id INTEGER NOT NULL,
    granted_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY(account_id, server_group_id),
    FOREIGN KEY(account_id) REFERENCES social_accounts(id) ON DELETE CASCADE,
    FOREIGN KEY(server_group_id) REFERENCES groups_cache(server_group_id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS collection_profiles (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    profile_name TEXT NOT NULL,
    lookback_days INTEGER NOT NULL DEFAULT 7,
    sort_by TEXT NOT NULL DEFAULT 'views',
    observation_limit INTEGER NOT NULL DEFAULT 100,
    download_policy TEXT NOT NULL DEFAULT 'NONE',
    download_limit INTEGER NOT NULL DEFAULT 0,
    transcript_policy TEXT NOT NULL DEFAULT 'ON_DEMAND',
    filter_json TEXT NOT NULL DEFAULT '{}',
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(profile_name)
);

CREATE TABLE IF NOT EXISTS account_collection_rules (
    account_id INTEGER PRIMARY KEY,
    collection_profile_id INTEGER,
    enabled INTEGER NOT NULL DEFAULT 1,
    next_collect_at TEXT,
    last_collect_at TEXT,
    last_result TEXT NOT NULL DEFAULT 'UNKNOWN',
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY(account_id) REFERENCES social_accounts(id) ON DELETE CASCADE,
    FOREIGN KEY(collection_profile_id) REFERENCES collection_profiles(id) ON DELETE SET NULL
);

CREATE TABLE IF NOT EXISTS posts (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_post_id INTEGER,
    account_id INTEGER,
    platform TEXT NOT NULL DEFAULT 'instagram',
    shortcode TEXT NOT NULL,
    post_url TEXT NOT NULL,
    caption TEXT NOT NULL DEFAULT '',
    published_at TEXT,
    thumbnail_url TEXT NOT NULL DEFAULT '',
    video_url TEXT NOT NULL DEFAULT '',
    source_url_observed_at TEXT,
    media_state TEXT NOT NULL DEFAULT 'METADATA_ONLY',
    first_observed_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    last_observed_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(platform, shortcode),
    FOREIGN KEY(account_id) REFERENCES social_accounts(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS idx_posts_account_published
    ON posts(account_id, published_at DESC, id DESC);
CREATE INDEX IF NOT EXISTS idx_posts_media_state
    ON posts(media_state, id DESC);

CREATE TABLE IF NOT EXISTS post_stat_latest (
    post_id INTEGER PRIMARY KEY,
    views INTEGER NOT NULL DEFAULT 0,
    likes INTEGER NOT NULL DEFAULT 0,
    comments INTEGER NOT NULL DEFAULT 0,
    reposts INTEGER NOT NULL DEFAULT 0,
    collected_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_post_stat_latest_views
    ON post_stat_latest(views DESC, post_id DESC);
CREATE INDEX IF NOT EXISTS idx_post_stat_latest_likes
    ON post_stat_latest(likes DESC, post_id DESC);
CREATE INDEX IF NOT EXISTS idx_post_stat_latest_comments
    ON post_stat_latest(comments DESC, post_id DESC);

CREATE TABLE IF NOT EXISTS post_stat_history (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    post_id INTEGER NOT NULL,
    views INTEGER NOT NULL DEFAULT 0,
    likes INTEGER NOT NULL DEFAULT 0,
    comments INTEGER NOT NULL DEFAULT 0,
    reposts INTEGER NOT NULL DEFAULT 0,
    collected_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE,
    UNIQUE(post_id, collected_at)
);
CREATE INDEX IF NOT EXISTS idx_post_stat_history_post_time
    ON post_stat_history(post_id, collected_at DESC);

CREATE TABLE IF NOT EXISTS media_assets (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_asset_id INTEGER,
    post_id INTEGER NOT NULL,
    asset_kind TEXT NOT NULL,
    media_index INTEGER NOT NULL DEFAULT 0,
    source_url TEXT NOT NULL DEFAULT '',
    source_url_observed_at TEXT,
    storage_root_id INTEGER,
    relative_path TEXT NOT NULL DEFAULT '',
    file_name TEXT NOT NULL DEFAULT '',
    file_size INTEGER NOT NULL DEFAULT 0,
    md5 TEXT NOT NULL DEFAULT '',
    sha256 TEXT NOT NULL DEFAULT '',
    local_status TEXT NOT NULL DEFAULT 'MISSING',
    transcript_status TEXT NOT NULL DEFAULT 'NONE',
    share_status TEXT NOT NULL DEFAULT 'PRIVATE',
    verified_at TEXT,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(post_id, asset_kind, media_index),
    FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE,
    FOREIGN KEY(storage_root_id) REFERENCES storage_roots(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS idx_media_assets_hash
    ON media_assets(sha256, file_size);
CREATE INDEX IF NOT EXISTS idx_media_assets_local_status
    ON media_assets(local_status, post_id);

CREATE TABLE IF NOT EXISTS transcripts (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_transcript_id INTEGER,
    post_id INTEGER NOT NULL,
    asset_id INTEGER,
    language_code TEXT NOT NULL DEFAULT '',
    model_name TEXT NOT NULL DEFAULT '',
    model_version TEXT NOT NULL DEFAULT '',
    transcript_text TEXT NOT NULL DEFAULT '',
    segments_json TEXT NOT NULL DEFAULT '[]',
    status TEXT NOT NULL DEFAULT 'PENDING',
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    created_by_server_user_id INTEGER,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(post_id, language_code, model_name, model_version),
    FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE,
    FOREIGN KEY(asset_id) REFERENCES media_assets(id) ON DELETE SET NULL
);

CREATE TABLE IF NOT EXISTS hook_segments (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_hook_id INTEGER,
    post_id INTEGER NOT NULL,
    transcript_id INTEGER,
    start_ms INTEGER NOT NULL DEFAULT 0,
    end_ms INTEGER NOT NULL DEFAULT 3000,
    hook_text TEXT NOT NULL DEFAULT '',
    source_type TEXT NOT NULL DEFAULT 'AUTO_SUGGESTED',
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    confirmed_by_server_user_id INTEGER,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE,
    FOREIGN KEY(transcript_id) REFERENCES transcripts(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS idx_hook_segments_post
    ON hook_segments(post_id, start_ms, end_ms);

CREATE TABLE IF NOT EXISTS categories (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_category_id INTEGER,
    owner_server_user_id INTEGER,
    source_category_id INTEGER,
    parent_category_id INTEGER,
    category_name TEXT NOT NULL,
    description TEXT NOT NULL DEFAULT '',
    category_type TEXT NOT NULL DEFAULT 'GENERAL',
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY(parent_category_id) REFERENCES categories(id) ON DELETE SET NULL,
    UNIQUE(owner_server_user_id, category_name, category_type)
);
CREATE INDEX IF NOT EXISTS idx_categories_visibility_name
    ON categories(visibility, category_name);

CREATE TABLE IF NOT EXISTS post_category_assignments (
    post_id INTEGER NOT NULL,
    category_id INTEGER NOT NULL,
    assigned_by_server_user_id INTEGER,
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    assigned_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY(post_id, category_id, assigned_by_server_user_id),
    FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE,
    FOREIGN KEY(category_id) REFERENCES categories(id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS tags (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_tag_id INTEGER,
    owner_server_user_id INTEGER,
    tag_name TEXT NOT NULL,
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(owner_server_user_id, tag_name)
);
CREATE INDEX IF NOT EXISTS idx_tags_name ON tags(tag_name);

CREATE TABLE IF NOT EXISTS post_tag_assignments (
    post_id INTEGER NOT NULL,
    tag_id INTEGER NOT NULL,
    assigned_by_server_user_id INTEGER,
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    assigned_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY(post_id, tag_id, assigned_by_server_user_id),
    FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE,
    FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS post_notes (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_note_id INTEGER,
    post_id INTEGER NOT NULL,
    author_server_user_id INTEGER,
    note_type TEXT NOT NULL DEFAULT 'MEMO',
    note_text TEXT NOT NULL DEFAULT '',
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_post_notes_post_visibility
    ON post_notes(post_id, visibility, id DESC);

CREATE TABLE IF NOT EXISTS review_templates (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_template_id INTEGER,
    owner_server_user_id INTEGER,
    template_name TEXT NOT NULL,
    description TEXT NOT NULL DEFAULT '',
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS review_items (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    template_id INTEGER NOT NULL,
    item_key TEXT NOT NULL,
    item_label TEXT NOT NULL,
    min_score REAL NOT NULL DEFAULT 1,
    max_score REAL NOT NULL DEFAULT 5,
    display_order INTEGER NOT NULL DEFAULT 0,
    FOREIGN KEY(template_id) REFERENCES review_templates(id) ON DELETE CASCADE,
    UNIQUE(template_id, item_key)
);

CREATE TABLE IF NOT EXISTS post_reviews (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_review_id INTEGER,
    post_id INTEGER NOT NULL,
    template_id INTEGER,
    author_server_user_id INTEGER,
    author_display_name TEXT NOT NULL DEFAULT '',
    review_text TEXT NOT NULL DEFAULT '',
    overall_score REAL,
    prediction_score REAL,
    prediction_text TEXT NOT NULL DEFAULT '',
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE,
    FOREIGN KEY(template_id) REFERENCES review_templates(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS idx_post_reviews_post_visibility
    ON post_reviews(post_id, visibility, id DESC);

CREATE TABLE IF NOT EXISTS review_scores (
    review_id INTEGER NOT NULL,
    review_item_id INTEGER NOT NULL,
    score REAL NOT NULL,
    PRIMARY KEY(review_id, review_item_id),
    FOREIGN KEY(review_id) REFERENCES post_reviews(id) ON DELETE CASCADE,
    FOREIGN KEY(review_item_id) REFERENCES review_items(id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS post_comments (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_comment_id INTEGER,
    post_id INTEGER NOT NULL,
    author_server_user_id INTEGER,
    author_display_name TEXT NOT NULL DEFAULT '',
    comment_type TEXT NOT NULL DEFAULT 'OBSERVATION',
    comment_text TEXT NOT NULL DEFAULT '',
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    parent_comment_id INTEGER,
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE,
    FOREIGN KEY(parent_comment_id) REFERENCES post_comments(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_post_comments_post_visibility
    ON post_comments(post_id, visibility, id DESC);

CREATE TABLE IF NOT EXISTS aggregate_definitions (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    server_aggregate_id INTEGER,
    aggregate_name TEXT NOT NULL,
    output_file_name TEXT NOT NULL,
    owner_server_user_id INTEGER,
    visibility TEXT NOT NULL DEFAULT 'PRIVATE',
    server_group_id INTEGER,
    sort_by TEXT NOT NULL DEFAULT 'views',
    filter_days INTEGER NOT NULL DEFAULT 7,
    page_size INTEGER NOT NULL DEFAULT 50,
    limit_count INTEGER NOT NULL DEFAULT 0,
    filter_json TEXT NOT NULL DEFAULT '{}',
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(output_file_name)
);

CREATE TABLE IF NOT EXISTS aggregate_accounts (
    aggregate_id INTEGER NOT NULL,
    account_id INTEGER NOT NULL,
    display_order INTEGER NOT NULL DEFAULT 0,
    PRIMARY KEY(aggregate_id, account_id),
    FOREIGN KEY(aggregate_id) REFERENCES aggregate_definitions(id) ON DELETE CASCADE,
    FOREIGN KEY(account_id) REFERENCES social_accounts(id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS p2p_inventory (
    asset_id INTEGER PRIMARY KEY,
    server_device_id INTEGER,
    available INTEGER NOT NULL DEFAULT 0,
    share_scope TEXT NOT NULL DEFAULT 'PRIVATE',
    max_uploads INTEGER NOT NULL DEFAULT 1,
    last_verified_at TEXT,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY(asset_id) REFERENCES media_assets(id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS sync_queue (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    entity_type TEXT NOT NULL,
    entity_local_id INTEGER,
    operation TEXT NOT NULL DEFAULT 'UPSERT',
    payload_json TEXT NOT NULL DEFAULT '{}',
    status TEXT NOT NULL DEFAULT 'PENDING',
    attempt_count INTEGER NOT NULL DEFAULT 0,
    next_attempt_at TEXT,
    last_error TEXT NOT NULL DEFAULT '',
    created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_sync_queue_status_next
    ON sync_queue(status, next_attempt_at, id);

CREATE TABLE IF NOT EXISTS point_ledger_cache (
    server_ledger_id INTEGER PRIMARY KEY,
    user_server_id INTEGER NOT NULL,
    amount INTEGER NOT NULL,
    reason_type TEXT NOT NULL,
    reference_type TEXT NOT NULL DEFAULT '',
    reference_id INTEGER,
    balance_after INTEGER,
    created_at TEXT NOT NULL,
    synced_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);

PRAGMA user_version = 1;
