{
  "title": "Hiromeru DB変更点",
  "stage": "差分確認・未適用",
  "before": {
    "commit": "7951d83",
    "path": "backend/models/"
  },
  "after": {
    "commit": "eda9f0b",
    "path": "docs/specs/DATABASE.dbml"
  },
  "tables": [
    {
      "id": "agent-sessions",
      "table": "agent_sessions",
      "logical": "会話の所有者",
      "scope": "conversation",
      "kind": "reference",
      "model": "agent.py",
      "lines": "38-52",
      "design": "387-401",
      "changes": [
        [
          "列名（bigint・必須）",
          "marketer_id",
          "user_id"
        ],
        [
          "参照先",
          "marketers.id",
          "users.id（削除時RESTRICT）"
        ],
        [
          "一意制約",
          "(id, marketer_id)",
          "(id, user_id)"
        ],
        [
          "索引",
          "(marketer_id, updated_at)",
          "(user_id, updated_at)"
        ]
      ]
    },
    {
      "id": "idempotency",
      "table": "api_idempotency_requests",
      "logical": "冪等性記録の要求者",
      "scope": "conversation",
      "kind": "reference",
      "model": "idempotency.py",
      "lines": "24-69",
      "design": "428-462",
      "changes": [
        [
          "列名（bigint・必須）",
          "marketer_id",
          "user_id"
        ],
        [
          "要求者の参照先",
          "marketers.id",
          "users.id（削除時RESTRICT）"
        ],
        [
          "会話所有者との複合外部キー",
          "(session_id, marketer_id) → agent_sessions(id, marketer_id)",
          "(session_id, user_id) → agent_sessions(id, user_id)（削除時RESTRICT）"
        ],
        [
          "冪等性の一意制約",
          "(marketer_id, operation, idempotency_key)",
          "(user_id, operation, idempotency_key)"
        ],
        [
          "要求ハッシュの索引",
          "(marketer_id, operation, request_hash)",
          "(user_id, operation, request_hash)"
        ]
      ]
    },
    {
      "id": "campaigns",
      "table": "campaigns",
      "logical": "施策の作成者",
      "scope": "business",
      "kind": "reference",
      "model": "campaign.py",
      "lines": "13-37",
      "design": "222-241",
      "changes": [
        [
          "列名（bigint・必須）",
          "created_by_marketer_id",
          "created_by_user_id"
        ],
        [
          "作成者の外部キー",
          "(created_by_marketer_id, company_id) → marketers(id, company_id)",
          "created_by_user_id → users.id（削除時RESTRICT）"
        ]
      ]
    },
    {
      "id": "posts",
      "table": "posts",
      "logical": "投稿の作成者",
      "scope": "business",
      "kind": "reference",
      "model": "post.py",
      "lines": "25-48",
      "design": "259-279",
      "changes": [
        [
          "列名（bigint・必須）",
          "created_by_marketer_id",
          "created_by_user_id"
        ],
        [
          "作成者の外部キー",
          "(created_by_marketer_id, company_id) → marketers(id, company_id)",
          "created_by_user_id → users.id（削除時RESTRICT）"
        ]
      ]
    },
    {
      "id": "marketers",
      "table": "marketers",
      "logical": "旧作成者参照用の一意制約",
      "scope": "business",
      "kind": "clean",
      "model": "identity.py",
      "lines": "59-78",
      "design": "133-147",
      "changes": [
        [
          "一意制約",
          "(id, company_id) / uq_marketers_id_company",
          "削除"
        ]
      ]
    },
    {
      "id": "snapshots",
      "table": "api_list_snapshots",
      "logical": "一覧の固定データ",
      "scope": "snapshot",
      "kind": "remove",
      "model": "snapshot.py",
      "lines": "14-30",
      "design": null,
      "changes": [
        [
          "列",
          "id, marketer_id, resource, filter_hash, summary, created_at, expires_at",
          null
        ],
        [
          "主キー",
          "id",
          null
        ],
        [
          "外部キー",
          "marketer_id → marketers.id（削除時CASCADE）",
          null
        ],
        [
          "索引",
          "(marketer_id, resource, expires_at) / expires_at",
          null
        ],
        [
          "CHECK",
          "resource IN ('posts', 'metrics')",
          null
        ]
      ]
    },
    {
      "id": "snapshot-items",
      "table": "api_list_snapshot_items",
      "logical": "一覧の固定順序と表示値",
      "scope": "snapshot",
      "kind": "remove",
      "model": "snapshot.py",
      "lines": "33-45",
      "design": null,
      "changes": [
        [
          "列",
          "snapshot_id, position, item",
          null
        ],
        [
          "主キー",
          "(snapshot_id, position)",
          null
        ],
        [
          "外部キー",
          "snapshot_id → api_list_snapshots.id（削除時CASCADE）",
          null
        ],
        [
          "CHECK",
          "position >= 0",
          null
        ]
      ]
    }
  ]
}
