@appgrowstack/app-contract 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/d1.js ADDED
@@ -0,0 +1,1227 @@
1
+ // appgrowstack-core の D1(appgrowstack-core)の表。表の頭は文脈(registry_・people_・inapp_・links_・support_・access_・audit_・sessions_・config_・usage_・decision_・releases_)。
2
+ // 正はこの定義で、workers/core/migrations の SQL を順に流した物がこれと同じかを test/d1.test.ts が確かめる。
3
+ // 時刻はすべて 1970 年からのミリ秒(INTEGER)。真偽は INTEGER の 0/1。JSON は TEXT(列の名前の後ろに _json)。
4
+ // 人の表(people_)は core だけがマイグレーションを書き、appgrowstack-notify は同じ D1 を読むだけ(設計 3.1)。notify が書くのは usage_ai だけ
5
+ // appgrowstack-creative の D1 の表は下の creativeTables、appgrowstack-insights の D1 の表は insightsTables
6
+ const text = { type: "TEXT", nullable: false };
7
+ const textNull = { type: "TEXT", nullable: true };
8
+ const int = { type: "INTEGER", nullable: false };
9
+ const intNull = { type: "INTEGER", nullable: true };
10
+ const real = { type: "REAL", nullable: false };
11
+ const realNull = { type: "REAL", nullable: true };
12
+ export const tables = {
13
+ // --- R1 登録 ---------------------------------------------------------------
14
+ registry_project: {
15
+ primaryKey: ["id"],
16
+ columns: {
17
+ id: text, // 'gamification-app'
18
+ name: text,
19
+ status: text, // active | paused
20
+ web_domain: text,
21
+ support_email: text,
22
+ default_time_zone: text,
23
+ feature_inapp: int,
24
+ feature_notify: int,
25
+ feature_links: int,
26
+ feature_support: int,
27
+ created_at: int,
28
+ updated_at: int,
29
+ campaign_max_shown_cap: int, // 0300。件の limits.max_shown の上限
30
+ campaign_holdout_min: real, // 0300。件の holdout の下限(review_ask は見ない)
31
+ org: text, // 0301。access_org の id(AC-5)
32
+ feature_sessions: int, // 0400。R8(K3-8)
33
+ feature_config: int, // R9(K6-2)
34
+ // 0510。R13 の判断の値(K18-6)。決めていなければ NULL
35
+ track: textNull, // new | portfolio
36
+ stage: textNull, // ProjectStage
37
+ focus: textNull, // metrics.toml の指標の名前
38
+ targets_json: textNull, // ProjectTarget[]
39
+ decide_on: textNull, // YYYY-MM-DD
40
+ store_fee_rate_json: textNull, // ProjectStoreFeeRate
41
+ owner_customers_json: textNull, // string[]
42
+ competitors_json: textNull, // ProjectCompetitor[]
43
+ keywords_json: textNull, // string[]
44
+ },
45
+ },
46
+ registry_app: {
47
+ primaryKey: ["project", "platform"],
48
+ columns: {
49
+ project: text,
50
+ platform: text, // ios | android
51
+ bundle_id: textNull, // ios
52
+ asc_app_id: textNull, // ios
53
+ package: textNull, // android
54
+ status: text, // active | retired
55
+ created_at: int,
56
+ asc_provider_token: textNull, // ios。0507。R12 の App Store のキャンペーンのリンクの pt
57
+ },
58
+ },
59
+ registry_key: {
60
+ primaryKey: ["id"],
61
+ columns: {
62
+ id: text, // key_ + 16
63
+ project: text,
64
+ kind: text, // public | server
65
+ public_key: textNull, // pk_…(public だけ)
66
+ secret_sha256: textNull, // sk_… の sha256(server だけ)
67
+ hint: textNull, // sk_…abcd(server だけ)
68
+ status: text, // active | revoked
69
+ created_at: int,
70
+ revoked_at: intNull,
71
+ scopes_json: textNull, // 0301。server だけ。ServerKeyScope[](AC-6)
72
+ expires_at: intNull, // 0301。server だけ
73
+ last_used_at: intNull, // 0301
74
+ },
75
+ },
76
+ registry_internal: {
77
+ primaryKey: ["project", "match", "value"],
78
+ // 0508: 本人とテスターのマーク(InternalMark)。match は uid・install・device(DeviceHash)。kind は owner・tester
79
+ columns: { project: text, match: text, value: text, kind: text, label: text, created_at: int },
80
+ },
81
+ registry_owner_claim: {
82
+ primaryKey: ["token_sha256"],
83
+ // 0508: 端末に本人のマークを付ける10分のリンク(people.md 6.3節)。開いた IP(ipKey)と OS を、端末に付けるまでの間だけ持つ
84
+ columns: {
85
+ token_sha256: text,
86
+ project: text,
87
+ created_by: text,
88
+ created_at: int,
89
+ expires_at: int,
90
+ opened_at: intNull,
91
+ opened_ip: textNull,
92
+ opened_platform: textNull,
93
+ device: textNull,
94
+ claimed_at: intNull,
95
+ },
96
+ },
97
+ registry_touch_budget: {
98
+ primaryKey: ["project"],
99
+ columns: {
100
+ project: text,
101
+ max_per_day: int,
102
+ max_per_week: int,
103
+ inapp_per_day: intNull,
104
+ push_per_day: intNull,
105
+ email_per_day: intNull,
106
+ updated_at: int,
107
+ },
108
+ },
109
+ // --- R2 人 -----------------------------------------------------------------
110
+ people_person: {
111
+ primaryKey: ["project", "person_id"],
112
+ columns: {
113
+ project: text,
114
+ person_id: text,
115
+ first_seen_at: int,
116
+ last_seen_at: int,
117
+ last_open_at: intNull,
118
+ last_notification_open_at: intNull,
119
+ platform: textNull,
120
+ app_version: textNull,
121
+ channel: textNull,
122
+ lang: textNull,
123
+ region: textNull,
124
+ time_zone: textNull,
125
+ sdk_version: textNull, // 端末の SDK の版(context.sdk_version)
126
+ authorization: textNull, // 最後に届いた端末の通知の許可
127
+ subscription: text, // SubscriptionState(既定 free)
128
+ subscription_changed_at: intNull,
129
+ promotional_consent: int,
130
+ updated_at: int,
131
+ audience: text, // 0508。Audience(real・owner・test・review・robot)。数は何も指定しなければ real だけ
132
+ audience_auto: text, // 0508。channel・ネットワーク・テスターのマークから決めた見分け(owner にならない)。本人のマークを外すとここへ戻る
133
+ },
134
+ },
135
+ people_device: {
136
+ primaryKey: ["project", "install_id"],
137
+ // 0508: install と端末(DeviceHash)のつなぎ。api の observeDevice が書く。asn は最後に見た AS 番号、network は一度でも Apple(review)・Google(robot)の AS から来たマーク
138
+ columns: { project: text, install_id: text, device: text, asn: intNull, as_org: textNull, network: textNull, first_at: int, last_at: int },
139
+ },
140
+ // 0514: 寄せた人の記録。insights の毎日の書き出しが merged_at の後の行だけを読む。forget と30日で消す
141
+ people_merge: {
142
+ primaryKey: ["project", "from_person"],
143
+ columns: { project: text, from_person: text, into_person: text, merged_at: int },
144
+ },
145
+ people_identity_link: {
146
+ primaryKey: ["project", "kind", "value"],
147
+ columns: { project: text, kind: text /* install | uid */, value: text, person_id: text, linked_at: int },
148
+ },
149
+ people_trait: {
150
+ primaryKey: ["project", "person_id", "name"],
151
+ columns: {
152
+ project: text,
153
+ person_id: text,
154
+ name: text,
155
+ value_json: text,
156
+ value_num: realNull, // 数(セグメントの SQL が読む)
157
+ value_text: textNull, // 文字と真偽('true'/'false')
158
+ updated_at: int,
159
+ },
160
+ },
161
+ people_activity_day: {
162
+ primaryKey: ["project", "person_id", "day"],
163
+ columns: { project: text, person_id: text, day: text, first_at: int },
164
+ },
165
+ people_open_hour: {
166
+ primaryKey: ["project", "person_id"],
167
+ // 0501: 直近28日の、開いた日ごとの最初に開いた時刻(R10 4.4節)。書くのは開いた日の最初の1回だけ
168
+ columns: { project: text, person_id: text, last_day: text, opens_json: text }, // [[その人の時間帯の日付, 時], …]
169
+ },
170
+ people_open_hour_project: {
171
+ primaryKey: ["project"],
172
+ // 0501: 製品の直近28日の開いた日を1時間ごとに数えた物(日に1回の Cron)。top_hour は開いた記録が無ければ null
173
+ columns: { project: text, top_hour: intNull, people: int, counts_json: text, computed_at: int }, // counts_json は24個の数
174
+ },
175
+ people_event: {
176
+ primaryKey: ["id"],
177
+ // 0302: 出来事ごとのアプリのバージョンと channel(K2-6・track の context から)。受け入れで絞った名前と prop だけを残し、90日で消す
178
+ // 0508: audience は受けた時のその人の見分け。人の見分けが変わったら、その人の出来事も書き換える
179
+ columns: { id: text, project: text, person_id: text, name: text, at: int, props_json: text, received_at: int, app_version: textNull, channel: textNull, audience: text },
180
+ },
181
+ people_subscription_event: {
182
+ primaryKey: ["id"],
183
+ columns: {
184
+ id: text,
185
+ project: text,
186
+ person_id: text,
187
+ type: text,
188
+ period_type: textNull,
189
+ environment: textNull,
190
+ at: int,
191
+ received_at: int,
192
+ },
193
+ },
194
+ people_touch: {
195
+ primaryKey: ["id"],
196
+ columns: {
197
+ id: text,
198
+ project: text,
199
+ person_id: text,
200
+ channel: text, // inapp | push | email
201
+ class: text, // lifecycle | promotional | transactional
202
+ context: text, // inapp | notify | support
203
+ campaign: text,
204
+ key: text,
205
+ day: text, // その人の時間帯の日付
206
+ week: text, // その週の月曜の日付
207
+ at: int,
208
+ },
209
+ },
210
+ // --- R4 画面の中 -----------------------------------------------------------
211
+ inapp_set: {
212
+ primaryKey: ["project", "version"],
213
+ // 0403: manifest_json は push のマニフェスト(explain が登録と mirror を読む)
214
+ columns: { project: text, version: int, body: text, sha256: text, published_at: int, published_by: text, manifest_json: textNull },
215
+ },
216
+ inapp_campaign: {
217
+ primaryKey: ["project", "campaign"],
218
+ columns: {
219
+ project: text,
220
+ campaign: text,
221
+ type: text, // CampaignType
222
+ frozen_sha256: text, // holdout・triggers・audience の正規の JSON の sha256(送ったことのある id の変更を落とす)
223
+ first_version: int,
224
+ last_version: int,
225
+ first_published_at: int,
226
+ },
227
+ },
228
+ inapp_state: {
229
+ primaryKey: ["project"],
230
+ columns: { project: text, paused: int, updated_at: int, updated_by: text },
231
+ },
232
+ // 0302: 合成の端末の1回(直近7日)
233
+ inapp_probe: {
234
+ primaryKey: ["id"],
235
+ columns: {
236
+ id: text,
237
+ project: text,
238
+ at: int,
239
+ ok: int,
240
+ status: int,
241
+ etag: textNull,
242
+ version: intNull,
243
+ expected_version: int,
244
+ age_seconds: intNull,
245
+ ms: int,
246
+ not_modified_ok: intNull,
247
+ problem: textNull, // ProbeResult.problem
248
+ },
249
+ },
250
+ // 0302: プロジェクトごとの health の最新(HealthProject)
251
+ inapp_health: {
252
+ primaryKey: ["project"],
253
+ columns: { project: text, computed_at: int, report_json: text },
254
+ },
255
+ // 0403: 出来事の受け入れの絞り込み(K2-6)。組を送るたびに、件のきっかけと成果の名前と where が使う prop を until(送った時から90日)まで残す。track が読む
256
+ inapp_event_filter: {
257
+ primaryKey: ["project", "name"],
258
+ columns: { project: text, name: text, props_json: text, until: int },
259
+ },
260
+ // 0403: 件ごと・人ごとの出た記録。campaign_eligible・campaign_shown を受けた時に書き、health と report が people_event を読まずに人を数える
261
+ inapp_exposure: {
262
+ primaryKey: ["project", "campaign", "person_id"],
263
+ columns: {
264
+ project: text,
265
+ campaign: text,
266
+ person_id: text,
267
+ side: textNull, // 最初の campaign_eligible の側。shown だけが先に来たら null
268
+ internal: int, // 本人とテスターの端末・channel が debug か testflight の時に1。数えから外す
269
+ first_eligible_at: intNull,
270
+ last_eligible_at: intNull,
271
+ first_shown_at: intNull,
272
+ last_shown_at: intNull,
273
+ },
274
+ },
275
+ // 0403: campaign_*・campaigns_* の1時間ごとの数(本人とテスターの端末・debug・testflight を外す)。detail は理由か側、無ければ ''
276
+ inapp_event_hour: {
277
+ primaryKey: ["project", "hour", "name", "campaign", "detail", "set_version"],
278
+ columns: { project: text, hour: int, name: text, campaign: text, detail: text, set_version: int, n: int },
279
+ },
280
+ // 0403: 人ごとの最後に読んだ組(campaigns_loaded)と、最後に古い組を使った時刻(campaigns_stale)
281
+ inapp_loaded: {
282
+ primaryKey: ["project", "person_id"],
283
+ columns: { project: text, person_id: text, set_version: int, loaded_at: int, stale_at: intNull },
284
+ },
285
+ // 0502: 件の案の配分(R10 の P5・docs/design/campaigns.md 9節)。配分を作った組のバージョンごとに1行
286
+ inapp_allocation: {
287
+ primaryKey: ["project", "campaign", "policy_version"],
288
+ columns: {
289
+ project: text,
290
+ campaign: text,
291
+ policy_version: int, // 配分を作った組の version
292
+ weights_json: text, // 件の variants の順の整数の重み(和は1000。0は止めた案)
293
+ reason: text, // push | weekly | guardrail
294
+ at: int,
295
+ summary_json: text, // 借りた事前分布・案ごとの薄めた数・止めた理由
296
+ },
297
+ },
298
+ // 0403: 件ごとの最後の simulate(eligible は 8 holdout まで残った人)。health が出した後の7日の数と比べる
299
+ inapp_simulate: {
300
+ primaryKey: ["project", "campaign"],
301
+ columns: { project: text, campaign: text, at: int, since: int, until: int, eligible: int, treatment: int, holdout: int, unknown: int },
302
+ },
303
+ // --- R9 設定 ----------------------------------------------------------------
304
+ config_set: {
305
+ primaryKey: ["project", "version"],
306
+ columns: { project: text, version: int, body: text, sha256: text, published_at: int, published_by: text },
307
+ },
308
+ config_experiment: {
309
+ primaryKey: ["project", "experiment"],
310
+ // frozen_sha256 は variants・metric・starts_at・key の sha256。experiment_json は最後に送った ConfigExperiment
311
+ columns: { project: text, experiment: text, flag_key: text, frozen_sha256: text, experiment_json: text, first_version: int, last_version: int, first_published_at: int },
312
+ },
313
+ config_exposure: {
314
+ primaryKey: ["project", "experiment", "person_id"],
315
+ // 人ごとに最初の config_exposed だけ(track が入れる)。人を寄せたら付け替え、forget で消す
316
+ columns: { project: text, experiment: text, person_id: text, variant: text, first_at: int, mixed: int /* 0407。2つ以上の案を記録した人は数えない */ },
317
+ },
318
+ // --- R6 リンク -------------------------------------------------------------
319
+ links_link: {
320
+ primaryKey: ["code"],
321
+ columns: {
322
+ code: text,
323
+ project: text,
324
+ destination_json: text, // LinkDestination
325
+ source: text,
326
+ medium: textNull,
327
+ campaign: textNull,
328
+ status: text, // active | disabled
329
+ created_by: text,
330
+ created_at: int,
331
+ expires_at: intNull,
332
+ },
333
+ },
334
+ links_click: {
335
+ primaryKey: ["id"],
336
+ columns: {
337
+ id: text,
338
+ code: text,
339
+ project: text,
340
+ at: int,
341
+ platform: text, // ios | android | other(User-Agent から。IP は残さない)
342
+ country: textNull, // cf.country
343
+ referer_host: textNull,
344
+ },
345
+ },
346
+ links_attribution: {
347
+ primaryKey: ["project", "install_id"],
348
+ columns: {
349
+ project: text,
350
+ install_id: text,
351
+ person_id: text,
352
+ matched_by: text,
353
+ code: textNull,
354
+ source: text,
355
+ medium: textNull,
356
+ campaign: textNull,
357
+ platform: text,
358
+ app_version: text,
359
+ first_open_at: int,
360
+ recorded_at: int,
361
+ ad_json: textNull, // 0302。AttributionAdDetail(apple_ads だけ)
362
+ },
363
+ },
364
+ links_invite: {
365
+ primaryKey: ["code"],
366
+ columns: {
367
+ code: text, // links_link.code(destination が invite)
368
+ project: text,
369
+ person_id: text, // 招いた人。URL・Link・出来事の引数には出さない
370
+ url: text, // 招いた先(同じ人の同じ url は同じ code を返す)
371
+ created_at: int,
372
+ },
373
+ },
374
+ // --- R7 サポート -----------------------------------------------------------
375
+ support_article: {
376
+ primaryKey: ["project", "slug", "lang"],
377
+ columns: {
378
+ project: text,
379
+ slug: text,
380
+ lang: text,
381
+ title: text,
382
+ summary: text,
383
+ url: text,
384
+ tags_json: text,
385
+ updated_at: int,
386
+ published_by: text,
387
+ },
388
+ },
389
+ support_ticket: {
390
+ primaryKey: ["id"],
391
+ columns: {
392
+ id: text, // tkt_ + 16
393
+ project: text,
394
+ person_id: text,
395
+ install_id: text,
396
+ owner_token_sha256: text,
397
+ status: text, // TicketStatus
398
+ category: text,
399
+ subject: textNull,
400
+ lang: text,
401
+ email: textNull,
402
+ context_json: text, // TicketContext
403
+ created_at: int,
404
+ updated_at: int,
405
+ resolved_at: intNull,
406
+ },
407
+ },
408
+ support_message: {
409
+ primaryKey: ["id"],
410
+ columns: {
411
+ id: text, // msg_ + 16
412
+ ticket_id: text,
413
+ author: text, // user | support
414
+ body: text,
415
+ created_at: int,
416
+ draft_id: textNull, // support の返事が下書きから来たとき
417
+ },
418
+ },
419
+ support_draft: {
420
+ primaryKey: ["id"],
421
+ columns: {
422
+ id: text, // dft_ + 16
423
+ ticket_id: text,
424
+ body: text,
425
+ model: text,
426
+ sources_json: text,
427
+ status: text, // pending | approved | edited | rejected
428
+ created_at: int,
429
+ reviewed_at: intNull,
430
+ reviewed_by: textNull,
431
+ },
432
+ },
433
+ support_attachment: {
434
+ primaryKey: ["id"],
435
+ columns: {
436
+ id: text, // att_ + 16
437
+ ticket_id: text,
438
+ content_type: text, // AttachmentContentType
439
+ bytes: int,
440
+ r2_key: text, // appgrowstack-core-attachments の鍵(<project>/<ticket_id>/<id>)
441
+ created_at: int,
442
+ },
443
+ },
444
+ // ストアのレビュー(K11-1・0101)。(project, store, store_review_id) は1行(support_store_review_store_id)
445
+ support_store_review: {
446
+ primaryKey: ["id"],
447
+ columns: {
448
+ id: text, // rvw_ + 16
449
+ project: text,
450
+ store: text, // ReviewStore
451
+ store_review_id: text,
452
+ rating: int,
453
+ title: textNull,
454
+ body: text,
455
+ territory: textNull,
456
+ lang: textNull,
457
+ app_version: textNull,
458
+ created_at: int, // ストアの時刻(Google Play は書き直すと進む)
459
+ fetched_at: int, // 最後に取った時刻
460
+ status: text, // StoreReviewStatus
461
+ response_body: textNull,
462
+ response_state: textNull, // published | pending_publish
463
+ response_at: intNull,
464
+ response_by: textNull, // usr_・agt_・store
465
+ },
466
+ },
467
+ support_review_draft: {
468
+ primaryKey: ["id"],
469
+ columns: {
470
+ id: text, // rdf_ + 16
471
+ review_id: text,
472
+ body: text,
473
+ model: text,
474
+ sources_json: text,
475
+ status: text, // pending | sending | approved | edited | rejected(sending は送っている間だけ。外には pending で見せる)
476
+ created_at: int,
477
+ reviewed_at: intNull,
478
+ reviewed_by: textNull,
479
+ },
480
+ },
481
+ support_feedback: {
482
+ primaryKey: ["id"],
483
+ columns: {
484
+ id: text, // fbk_ + 16
485
+ project: text,
486
+ person_id: text,
487
+ install_id: text,
488
+ campaign: textNull, // アンケートの件の id。設定から送った声は NULL
489
+ choice: textNull, // SurveyChoice
490
+ lang: text,
491
+ body: text, // 利用者が書いた文
492
+ context_json: text, // TicketContext
493
+ topic: textNull, // FeedbackTopic。AI が付けるまで NULL
494
+ topic_model: textNull,
495
+ classified_at: intNull,
496
+ created_at: int,
497
+ },
498
+ },
499
+ // --- 権限(0301・docs/access-control.md) ---------------------------------
500
+ access_org: {
501
+ primaryKey: ["id"],
502
+ columns: { id: text, slug: text, name: text, created_at: int },
503
+ },
504
+ access_principal: {
505
+ primaryKey: ["id"],
506
+ columns: {
507
+ id: text, // usr_ + 16・agt_ + 16
508
+ org: text,
509
+ kind: text, // user | agent
510
+ name: text,
511
+ email: textNull, // user だけ
512
+ owner_user: textNull, // agent だけ
513
+ location: textNull, // agent だけ。local | managed
514
+ status: text, // active | disabled
515
+ created_at: int,
516
+ },
517
+ },
518
+ access_membership: {
519
+ primaryKey: ["org", "principal_id", "role", "project"],
520
+ columns: { org: text, principal_id: text, project: text /* '*' は組織の全部 */, role: text, created_at: int, created_by: text },
521
+ },
522
+ access_token: {
523
+ primaryKey: ["id"],
524
+ columns: {
525
+ id: text, // tok_ + 16
526
+ principal_id: text,
527
+ kind: text, // user(ut_)| agent(at_)
528
+ secret_sha256: text,
529
+ hint: text,
530
+ scopes_json: textNull, // Permission[]。null は主体の今の役割に従う(0509)
531
+ projects_json: textNull, // null は絞らない
532
+ created_at: int,
533
+ expires_at: int,
534
+ last_used_at: intNull,
535
+ revoked_at: intNull,
536
+ created_by: text,
537
+ level3_scopes_json: textNull, // 0515。Level3Permission[]。scopes_json が NULL のトークンに足す段階3の操作。null は段階3を使わない
538
+ },
539
+ },
540
+ access_approval: {
541
+ primaryKey: ["id"],
542
+ columns: {
543
+ id: text, // apr_ + 16
544
+ org: text,
545
+ project: textNull,
546
+ action: text, // Permission
547
+ requested_by: text,
548
+ requested_via: text,
549
+ method: text,
550
+ path: text,
551
+ body: textNull,
552
+ body_sha256: text,
553
+ summary_json: text,
554
+ status: text, // pending | approved | rejected | expired | failed | executed
555
+ created_at: int,
556
+ expires_at: int,
557
+ decided_by: textNull,
558
+ decided_at: intNull,
559
+ self_approved: int,
560
+ note: textNull,
561
+ result_status: intNull,
562
+ result_body: textNull, // 実行の答えの id と誤りの code だけ(本文・秘密の値は残さない)
563
+ executed_at: intNull,
564
+ requested_token: textNull, // 依頼に使ったトークン(tok_)。Access の email なら null(0304)
565
+ },
566
+ },
567
+ access_policy: {
568
+ primaryKey: ["org", "project"],
569
+ columns: {
570
+ org: text,
571
+ project: text, // '*' は組織の既定
572
+ outward: text, // approval | auto_small
573
+ auto_max_reach: int,
574
+ auto_channels_json: text,
575
+ large_reach: int,
576
+ updated_at: int,
577
+ updated_by: text,
578
+ },
579
+ },
580
+ /** 書き足すだけ(UPDATE・DELETE は D1 のトリガーで止める) */
581
+ audit_event: {
582
+ primaryKey: ["id"],
583
+ columns: {
584
+ id: text, // aud_ + 16
585
+ at: int,
586
+ org: text,
587
+ project: textNull,
588
+ principal_kind: text,
589
+ principal_id: text,
590
+ on_behalf_of: textNull,
591
+ via: text, // AUDIT_VIA
592
+ token_id: textNull,
593
+ action: text, // Permission
594
+ target_json: textNull,
595
+ result: text, // ok | denied | pending_approval | failed
596
+ approval_id: textNull,
597
+ approved_by: textNull,
598
+ self_approved: int,
599
+ request_sha256: textNull,
600
+ data_level: intNull, // 2 | 3
601
+ request_id: textNull,
602
+ note: textNull,
603
+ },
604
+ },
605
+ // --- R8 行動の記録(0400・docs/sessions.md 6.2節) -------------------------
606
+ sessions_session: {
607
+ primaryKey: ["id"],
608
+ columns: {
609
+ id: text, // ses_ + 20
610
+ project: text,
611
+ person_id: text,
612
+ install_id: text,
613
+ platform: text,
614
+ app_version: text,
615
+ channel: text,
616
+ internal: int,
617
+ started_at: int,
618
+ last_at: int,
619
+ ended_at: intNull,
620
+ end_reason: textNull, // SessionEndReason
621
+ duration_ms: intNull,
622
+ screens: int,
623
+ taps: int,
624
+ rage: int,
625
+ dead: int,
626
+ quick_backs: int,
627
+ backs: int,
628
+ entry_screen: textNull,
629
+ exit_screen: textNull,
630
+ replay: text, // none | buffer | record | priority
631
+ replay_bytes: int,
632
+ keep_until: intNull,
633
+ summary_status: text, // none | queued | done | failed
634
+ replay_segments: int, // 0402。受けた録画の塊の数
635
+ },
636
+ },
637
+ sessions_mark: {
638
+ primaryKey: ["session_id", "kind", "ref", "at"],
639
+ columns: { session_id: text, project: text, kind: text, ref: text, at: int, side: textNull /* 0402。campaign_* の側 */ },
640
+ },
641
+ sessions_screen_day: {
642
+ primaryKey: ["project", "day", "platform", "screen"],
643
+ columns: {
644
+ project: text,
645
+ day: text,
646
+ platform: text,
647
+ screen: text,
648
+ views: int,
649
+ people: int,
650
+ exits: int,
651
+ end_reasons_json: text,
652
+ quick_backs: int,
653
+ backs: int,
654
+ rage: int,
655
+ dead: int,
656
+ taps: int,
657
+ ms_p50: intNull,
658
+ ms_p90: intNull,
659
+ scroll_hist_json: text,
660
+ dwell_hist_json: text, // 0402。画面にいた時間の分布(ms_p50・ms_p90 の元)
661
+ },
662
+ },
663
+ sessions_tap_cell: {
664
+ primaryKey: ["project", "day", "platform", "screen", "orientation", "cell"],
665
+ columns: { project: text, day: text, platform: text, screen: text, orientation: text, cell: int, taps: int, rage: int, dead: int },
666
+ },
667
+ sessions_path_day: {
668
+ primaryKey: ["project", "day", "platform", "from_screen", "to_screen"],
669
+ columns: { project: text, day: text, platform: text, from_screen: text, to_screen: text, count: int, people: int },
670
+ },
671
+ sessions_path_top: {
672
+ primaryKey: ["project", "day", "path"],
673
+ columns: { project: text, day: text, path: text, count: int, ended_here: int },
674
+ },
675
+ sessions_screen_ref: {
676
+ primaryKey: ["project", "screen", "platform", "app_version"],
677
+ columns: { project: text, screen: text, platform: text, app_version: text, r2_key: text, w: int, h: int, chosen_at: int, session_id: textNull, internal: int },
678
+ },
679
+ sessions_summary: {
680
+ primaryKey: ["session_id"],
681
+ columns: { session_id: text, project: text, model: text, json: text, created_at: int },
682
+ },
683
+ sessions_digest: {
684
+ primaryKey: ["project", "week"],
685
+ columns: { project: text, week: text, json: text, created_at: int },
686
+ },
687
+ sessions_live_watch: {
688
+ primaryKey: ["project", "install_id"],
689
+ columns: { project: text, install_id: text, requested_by: text, until: int, created_at: int },
690
+ },
691
+ sessions_policy: {
692
+ primaryKey: ["project"],
693
+ columns: { project: text, version: int, manifest_json: text, updated_at: int, updated_by: text },
694
+ },
695
+ sessions_daily: {
696
+ primaryKey: ["project", "day"],
697
+ columns: { project: text, day: text, sessions: int, recorded: int, priority: int, bytes: int, summaries: int /* 0404。自動の要約を頼んだ数 */ },
698
+ },
699
+ sessions_summary_job: {
700
+ primaryKey: ["session_id"],
701
+ columns: { session_id: text, project: text, batch_id: textNull, created_at: int }, // 0404
702
+ },
703
+ sessions_person_day: {
704
+ primaryKey: ["project", "day", "person_id"],
705
+ columns: { project: text, day: text, person_id: text, screens_json: text, paths_json: text }, // 0402
706
+ },
707
+ // 0405。AI を呼ぶたびの1行(core と notify の両方が書く・packages/contract/src/prices.ts)。月の合計を AI_MONTHLY_BUDGET_USD と比べる
708
+ usage_ai: {
709
+ primaryKey: ["id"],
710
+ columns: {
711
+ id: text,
712
+ month: text,
713
+ at: int,
714
+ feature: text,
715
+ project: textNull,
716
+ model: text,
717
+ batch: int,
718
+ input_tokens: int,
719
+ output_tokens: int,
720
+ cache_read_tokens: int,
721
+ cache_write_tokens: int,
722
+ usd_micros: int,
723
+ },
724
+ },
725
+ // --- R10 人ごとの出し分け(docs/design/personalization.md 4.1節) ------------------
726
+ // 0500。画面の中の件(campaign_eligible)と R9 の実験(config_exposed)で、端末が選んだ判断。通知の判断は notify の deliveries が持つ。
727
+ // 同じ人・面・単位・配分のバージョンでは選び方が同じなので、最初の1回だけ(INSERT OR IGNORE)。400日で消し、forget で人の id を外す
728
+ decision_log: {
729
+ primaryKey: ["decision_id"],
730
+ columns: {
731
+ decision_id: text, // 出来事の id
732
+ project: text,
733
+ person_id: text, // forget の後は forgotten:<1回限りの id>
734
+ surface: text, // inapp | config
735
+ unit: text, // 件の id・実験の id
736
+ arm: text, // treatment | holdout | 案の名前
737
+ propensity: realNull, // その側・案を選んだ確率。送らない古い端末は null
738
+ policy_version: int, // 組の version
739
+ context_json: text, // 段階・時間帯・言語・OS・app_version(R11)。人を指す値は入れない
740
+ at: int,
741
+ },
742
+ },
743
+ // --- R11 リリース(docs/design/releases.md 2節) -----------------------------
744
+ // 0505。プロジェクト × OS × バージョンの1行。ストアの状態と公開の時刻は core の Cron が同期する。人は書かない
745
+ releases_version: {
746
+ primaryKey: ["project", "platform", "version"],
747
+ columns: {
748
+ project: text,
749
+ platform: text, // ios | android
750
+ version: text, // 3.2.2
751
+ build: textNull, // ストアのビルド番号。Google Play は versionCode
752
+ store_state: text, // StoreState
753
+ rollout_fraction: realNull, // 段階公開の割合。段階公開でなければ null
754
+ submitted_at: intNull,
755
+ released_at: intNull,
756
+ released_at_source: textNull, // lookup | observed | imported
757
+ first_seen_at: intNull, // このバージョンの出来事が最初に届いた時刻
758
+ contents: text, // known | unknown
759
+ synced_at: intNull, // 移行で作った行は null
760
+ sync_error: textNull, // 最後の同期の誤りの code
761
+ },
762
+ },
763
+ // 0506。アプリごとのストアの同期の状態。ストアが401・403を返すとリリースの行が無いことがあるので、誤りはここに残す
764
+ releases_sync: {
765
+ primaryKey: ["project", "platform"],
766
+ columns: {
767
+ project: text,
768
+ platform: text, // ios | android
769
+ attempted_at: int, // 最後に読みに行った時刻
770
+ synced_at: intNull, // 最後にストアから読めた時刻
771
+ error: textNull, // 同期の誤りの code(key_forbidden・store_unavailable・store_error・no_key・no_store_id・unknown_version_code)
772
+ error_detail: textNull, // ストアの答えの短い説明。キーもトークンも入れない
773
+ error_since: intNull, // 読めない状態が始まった時刻。読めたら null
774
+ },
775
+ },
776
+ // 状態か割合が変わった時刻。書き換えない
777
+ releases_state_change: {
778
+ primaryKey: ["id"],
779
+ columns: { id: text, project: text, platform: text, version: text, store_state: text, rollout_fraction: realNull, at: int },
780
+ },
781
+ // ストアの、言語ごとの「このバージョンの新機能」の文
782
+ releases_note: {
783
+ primaryKey: ["project", "platform", "version", "locale"],
784
+ columns: { project: text, platform: text, version: text, locale: text, text: text, synced_at: int },
785
+ },
786
+ // ビルドのマニフェスト(schema/releases/manifest.schema.json)。locked_at が入ったら本文を変えない。commit は SQL の語なので commit_sha
787
+ releases_manifest: {
788
+ primaryKey: ["project", "platform", "version"],
789
+ columns: { project: text, platform: text, version: text, build: text, commit_sha: text, body_json: text, sha256: text, pushed_at: int, pushed_by: text, locked_at: intNull },
790
+ },
791
+ // マニフェストの中身を1つずつ開いた行(feature:<key>・event:<name> など)。requires の解決はこの表だけを読む
792
+ releases_capability: {
793
+ primaryKey: ["project", "platform", "version", "capability"],
794
+ columns: { project: text, platform: text, version: text, capability: text },
795
+ },
796
+ // 変更の1件(schema/releases/change.schema.json)
797
+ releases_change: {
798
+ primaryKey: ["project", "id"],
799
+ columns: {
800
+ project: text,
801
+ id: text,
802
+ title: text,
803
+ kind: text, // ChangeKind
804
+ area: text,
805
+ refs_json: text, // string[]
806
+ status: text, // ChangeStatus
807
+ note: text,
808
+ campaign: textNull, // kind が campaign の件の id
809
+ at: intNull, // kind が store の、掲載を変えた時刻
810
+ metric_json: textNull, // ChangeMetric
811
+ check_json: textNull, // ChangeCheck
812
+ created_at: int,
813
+ updated_at: int,
814
+ updated_by: text,
815
+ },
816
+ },
817
+ // 変更が入った OS ごとのバージョン
818
+ releases_change_version: {
819
+ primaryKey: ["project", "change", "platform"],
820
+ columns: { project: text, change: text, platform: text, version: text },
821
+ },
822
+ // 変更につながる機能のキー
823
+ releases_change_feature: {
824
+ primaryKey: ["project", "change", "feature"],
825
+ columns: { project: text, change: text, feature: text },
826
+ },
827
+ // その日(UTC)に開いた人を、その日の終わりのバージョンで集計した数。本人の端末を除く。日に1回の Cron が書く
828
+ releases_adoption_day: {
829
+ primaryKey: ["project", "platform", "app_version", "day"],
830
+ columns: { project: text, platform: text, app_version: text, day: text, people: int },
831
+ },
832
+ // 成果の出来事のある変更の、新しいバージョンの人と古いバージョンの人の人数。公開から56日まで。people_event が90日で消えるので日ごとに残す
833
+ releases_metric_day: {
834
+ primaryKey: ["project", "change", "platform", "day"],
835
+ columns: { project: text, change: text, platform: text, day: text, new_people: int, new_hit: int, old_people: int, old_hit: int },
836
+ },
837
+ };
838
+ // --- appgrowstack-creative の D1(appgrowstack-creative)-------------------------
839
+ // R12 ストアの素材(docs/design/creatives.md)。正はこの定義で、workers/creative/migrations の SQL を順に流した物がこれと同じかを test/d1.test.ts が確かめる。
840
+ // 表の頭は creative_ だけ。creative は core の D1 を CORE_DB で読むだけで、core の表を書かない(ADR 0027)。
841
+ // 主キーの列は NULL にしない。分からない案(creative_metric_day.variant)と全部の製品の効果(creative_effect.scope_key)は空の文字で持つ
842
+ export const creativeTables = {
843
+ // 撮影の組。書き換えない(status だけが uploading → ready・failed に進む)
844
+ creative_capture_set: {
845
+ primaryKey: ["id"],
846
+ columns: {
847
+ id: text, // cs_…
848
+ project: text,
849
+ platform: text, // ios | android
850
+ version: text,
851
+ build: text,
852
+ commit_sha: text,
853
+ captured_at: int,
854
+ status: text, // uploading | ready | failed
855
+ created_at: int,
856
+ created_by: text,
857
+ },
858
+ },
859
+ // 組の中の1つのファイル。set は SQL の語なので capture_set
860
+ creative_capture: {
861
+ primaryKey: ["capture_set", "locale", "device", "screen", "kind"],
862
+ columns: { capture_set: text, locale: text, device: text, screen: text, kind: text, state: text, r2_key: text, sha256: text, width: int, height: int, duration_ms: intNull },
863
+ },
864
+ // デザイントークンと声の決まり。送るたびに rev が1つ上がる
865
+ creative_brand: {
866
+ primaryKey: ["project", "rev"],
867
+ columns: { project: text, rev: int, body_json: text, sha256: text, pushed_at: int, pushed_by: text },
868
+ },
869
+ // フォント・端末の枠・背景の素材
870
+ creative_asset: {
871
+ primaryKey: ["id"],
872
+ columns: { id: text, project: text, kind: text, r2_key: text, sha256: text, meta_json: text, created_at: int }, // kind: font | frame | art
873
+ },
874
+ // ストアのページ(default・CPP・Play のカスタムの掲載・PPO の treatment)。store_name は CPP の名前で、App Store の分析の報告の Page Title と照らす(IN16)
875
+ creative_page: {
876
+ primaryKey: ["project", "platform", "key"],
877
+ columns: { project: text, platform: text, key: text, kind: text, store_id: textNull, state: text, deep_link: textNull, created_at: int, store_name: textNull },
878
+ },
879
+ // ストアの文字の1行。値を変える時は新しい行を足す
880
+ creative_text: {
881
+ primaryKey: ["id"],
882
+ columns: {
883
+ id: text, // ct_…
884
+ project: text,
885
+ platform: text,
886
+ page: text,
887
+ locale: text,
888
+ field: text, // StoreTextField
889
+ value: text,
890
+ status: text, // proposed | approved | live | retired | rejected
891
+ source: text, // ai | human | store | imported
892
+ hypothesis: textNull,
893
+ created_at: int,
894
+ created_by: text,
895
+ approved_at: intNull,
896
+ approved_by: textNull,
897
+ live_from: intNull,
898
+ live_until: intNull,
899
+ },
900
+ },
901
+ // 素材の案。中身は変える所の一覧(changes_json・CreativeChangeList)で、画像は持たない(ADR 0035)
902
+ creative_variant: {
903
+ primaryKey: ["id"],
904
+ columns: {
905
+ id: text, // cv_…
906
+ project: text,
907
+ platform: text,
908
+ page: text,
909
+ surface: text, // CreativeSurface
910
+ hypothesis: text,
911
+ status: text, // CreativeVariantStatus
912
+ changes_json: textNull, // generating と failed の間は null
913
+ model: textNull,
914
+ cost_usd: real,
915
+ created_at: int,
916
+ created_by: text,
917
+ decided_at: intNull,
918
+ decided_by: textNull,
919
+ decision_note: textNull,
920
+ },
921
+ },
922
+ // 公開の1回。同じ sha256 の物は2回上げない
923
+ creative_publish: {
924
+ primaryKey: ["id"],
925
+ columns: {
926
+ id: text,
927
+ project: text,
928
+ target: text, // app_store | play
929
+ object: text,
930
+ variant: textNull,
931
+ text_revision: textNull,
932
+ store_id: textNull,
933
+ sha256: textNull,
934
+ status: text, // queued | waiting_version | done | failed
935
+ error: textNull,
936
+ attempts: int,
937
+ at: int,
938
+ },
939
+ },
940
+ // Apple Ads の広告と CPP の対応。広告ごとの報告を案に結ぶ
941
+ creative_ad: {
942
+ primaryKey: ["project", "ad_id"],
943
+ columns: { project: text, ad_id: text, campaign_id: text, ad_group_id: text, product_page_id: textNull, page: textNull, updated_at: int },
944
+ },
945
+ // 素材の実験。metric_order_json は成果の候補の順(schema の metric_order)
946
+ creative_test: {
947
+ primaryKey: ["id"],
948
+ columns: {
949
+ id: text,
950
+ project: text,
951
+ hypothesis: text, // hyp_…。実験で確かめる仮説
952
+ kind: text, // ads_cpp | ppo | play_experiment
953
+ arms_json: text,
954
+ primary_metric: text,
955
+ metric_order_json: text,
956
+ max_days: int,
957
+ checkpoints_json: text,
958
+ loss_threshold: real,
959
+ ad_group_id: textNull,
960
+ store_id: textNull,
961
+ status: text, // registered | running | stopped | decided
962
+ started_at: intNull,
963
+ ended_at: intNull,
964
+ winner: textNull,
965
+ uplift_mean: realNull,
966
+ uplift_sd: realNull,
967
+ registered_by: text,
968
+ registered_at: int,
969
+ },
970
+ },
971
+ // ads_cpp の日ごとの配分と選んだ確率
972
+ creative_allocation: {
973
+ primaryKey: ["test", "day"],
974
+ columns: { test: text, day: text, arm: text, propensity: real, policy_version: int },
975
+ },
976
+ // 取り込んだ数。元に無い数は null
977
+ creative_metric_day: {
978
+ primaryKey: ["project", "platform", "page", "variant", "country", "source", "day", "origin"],
979
+ columns: {
980
+ project: text,
981
+ platform: text,
982
+ page: text,
983
+ variant: text, // 分からなければ ''
984
+ country: text,
985
+ source: text,
986
+ day: text,
987
+ origin: text, // apple_ads | asc_analytics | play_csv | appgrowstack
988
+ impressions: intNull,
989
+ page_views: intNull,
990
+ taps: intNull,
991
+ installs: intNull,
992
+ redownloads: intNull,
993
+ activations: intNull,
994
+ trials: intNull,
995
+ purchases: intNull,
996
+ },
997
+ },
998
+ // タグの効果の1回分
999
+ creative_snapshot: {
1000
+ primaryKey: ["id"],
1001
+ columns: { id: text, computed_at: int, model_version: text, summary_json: text },
1002
+ },
1003
+ creative_effect: {
1004
+ primaryKey: ["snapshot", "tag", "value", "scope", "scope_key"],
1005
+ columns: { snapshot: text, tag: text, value: text, scope: text, scope_key: text, mean: real, sd: real, n: int }, // scope_key: all は ''
1006
+ },
1007
+ // キーワードの人気度
1008
+ creative_keyword: {
1009
+ primaryKey: ["project", "country", "term", "week"],
1010
+ columns: { project: text, country: text, term: text, week: text, popularity: intNull, rank: intNull, source: text },
1011
+ },
1012
+ // 手で行う手順
1013
+ creative_step: {
1014
+ primaryKey: ["id"],
1015
+ columns: { id: text, project: text, kind: text, body_json: text, status: text, result_json: textNull, created_at: int, done_at: intNull, done_by: textNull },
1016
+ },
1017
+ // 週の流れ・手で依頼した生成・取り込みの1回
1018
+ creative_run: {
1019
+ primaryKey: ["id"],
1020
+ columns: { id: text, kind: text, project: textNull, workflow_id: textNull, status: text, cost_usd: real, summary_json: textNull, started_at: int, finished_at: intNull },
1021
+ },
1022
+ // AI の止める状態など
1023
+ creative_setting: {
1024
+ primaryKey: ["key"],
1025
+ columns: { key: text, value: text, updated_at: int },
1026
+ },
1027
+ // 参考の素材(docs/design/creatives.md 15節)。分類の決まった一覧は持たない。決まった値は source だけ
1028
+ creative_reference: {
1029
+ primaryKey: ["id"],
1030
+ columns: {
1031
+ id: text, // ref_…
1032
+ source: text, // CreativeReferenceSource
1033
+ source_url: textNull,
1034
+ subject: textNull,
1035
+ store: textNull, // app_store | play
1036
+ store_app_id: textNull,
1037
+ country: textNull,
1038
+ captured_on: text, // YYYY-MM-DD
1039
+ note: text,
1040
+ tags_json: text,
1041
+ project: textNull,
1042
+ origin: text, // manual | watch
1043
+ meta_json: text,
1044
+ status: text, // uploading | ready
1045
+ created_at: int,
1046
+ created_by: text,
1047
+ },
1048
+ },
1049
+ // 参考の素材の1つのファイル。同じ sha256 の物は R2 に1回だけ置く(refs/<sha256>)
1050
+ creative_reference_file: {
1051
+ primaryKey: ["reference", "position"],
1052
+ columns: { reference: text, position: int, sha256: text, r2_key: text, content_type: text, bytes: int, width: intNull, height: intNull, duration_ms: intNull },
1053
+ },
1054
+ // AI を呼ぶたびの1行。列は notify の ai_usage と同じ。core が CREATIVE_ADMIN.aiUsage で月の合計を読む
1055
+ creative_ai_usage: {
1056
+ primaryKey: ["id"],
1057
+ columns: { id: text, month: text, at: int, project: text, model: text, input_tokens: int, output_tokens: int, cache_read_tokens: int, cache_write_tokens: int, usd_micros: int },
1058
+ },
1059
+ };
1060
+ /** creative の D1 の表の頭 */
1061
+ export const CREATIVE_TABLE_PREFIXES = ["creative_"];
1062
+ // --- appgrowstack-insights の D1(appgrowstack-insights-production)-------------
1063
+ // R13 分析(docs/design/insights.md 4.3節)。正はこの定義で、workers/insights/migrations の SQL を順に流した物がこれと同じかを test/d1.test.ts が確かめる。
1064
+ // 表の頭は insights_ と仮説の記録の ledger_。insights は core と notify の D1 を CORE_DB・NOTIFY_DB で読むだけで、書かない。
1065
+ // 主キーの列は NULL にしない。insights_observation の内訳の無い行は dims_json を '{}'、全部の製品の行は project を空の文字で持つ。
1066
+ // check は SQL の語なので check_json、rows は窓関数の語なので row_count にする
1067
+ export const insightsTables = {
1068
+ // 製品・指標・日・内訳・見分けの数。外の取り込みと、データレイクと core の D1 から計算した数の両方。ずっと残す
1069
+ insights_observation: {
1070
+ primaryKey: ["project", "metric", "day", "dims_json", "audience"],
1071
+ columns: {
1072
+ project: text,
1073
+ metric: text, // metrics.toml の名前
1074
+ day: text, // YYYY-MM-DD(プロジェクトの default_time_zone)
1075
+ dims_json: text, // 内訳の軸と値。キーの順に並べた JSON。無ければ '{}'
1076
+ audience: text, // real | owner | test | review | robot | all(外の数は人で分けられないので all)
1077
+ value: realNull,
1078
+ den: intNull, // 割合の分母
1079
+ source: text, // lake | core | notify | 取り込み元の名前 | legacy
1080
+ collection: textNull, // 外の取り込みの insights_collection.id
1081
+ computed_at: int,
1082
+ },
1083
+ },
1084
+ // 取り込みの step ごとの結果。400日
1085
+ insights_collection: {
1086
+ primaryKey: ["id"],
1087
+ columns: { id: text, run: text, source: text, project: textNull, day: text, status: text, reason: textNull, raw_key: textNull, row_count: int, started_at: int, finished_at: intNull }, // status: ok | fresh | partial | error
1088
+ },
1089
+ // 検知の1件(8.2節)。400日
1090
+ insights_signal: {
1091
+ primaryKey: ["id"],
1092
+ columns: { id: text, project: text, day: text, kind: text, metric: textNull, weight: real, detail_json: text, hypothesis: textNull, finding: textNull, created_at: int },
1093
+ },
1094
+ // 指摘の1件と検算の結果(8.3〜8.5節)。ずっと残す
1095
+ insights_finding: {
1096
+ primaryKey: ["id"],
1097
+ columns: {
1098
+ id: text,
1099
+ project: text,
1100
+ signal: textNull,
1101
+ day: text,
1102
+ status: text, // proposed | accepted | rejected | later | discarded
1103
+ what: text,
1104
+ evidence_json: text,
1105
+ hypotheses_json: text,
1106
+ action_json: text,
1107
+ expected_json: text,
1108
+ check_json: text,
1109
+ verification_json: textNull,
1110
+ needs_review: int,
1111
+ hypothesis: textNull, // 採った時に作った ledger_hypothesis.id
1112
+ model: textNull,
1113
+ decided_by: textNull,
1114
+ decided_at: intNull,
1115
+ decision_note: textNull,
1116
+ created_at: int,
1117
+ surface: textNull, // 採った時に作る仮説の対象(0002・IN13)
1118
+ decides: textNull, // 採った時に作る仮説の「結果で何を決めるか」(0002・IN13)
1119
+ usd_micros: intNull, // 説明にかかった Claude の費用(0005・IN17)。前からある行は null
1120
+ tool_calls: intNull, // 説明のツールの呼び出しの回数(0005・IN17)
1121
+ },
1122
+ },
1123
+ // ツールの呼び出しの1回(9節)。400日。result_json は集計の行だけを200行まで
1124
+ insights_query: {
1125
+ primaryKey: ["id"],
1126
+ columns: { id: text, project: textNull, actor: text, job: textNull, tool: text, query: text, status: text, reason: textNull, scanned_bytes: intNull, row_count: intNull, ms: intNull, result_json: textNull, created_at: int },
1127
+ },
1128
+ // 人と person_key の対応(4.2節)。forget で行を消す
1129
+ insights_person_key: {
1130
+ primaryKey: ["project", "person_id"],
1131
+ columns: { project: text, person_id: text, person_key: text, created_at: int, state: textNull /* 0002。最後に people_changes に書いた値の sha256 */ },
1132
+ },
1133
+ // 0006: データレイクの書き出しの読み終えた位置。stream people_merge は core の people_merge の (merged_at, from_person) の最後
1134
+ insights_lake_cursor: {
1135
+ primaryKey: ["project", "stream"],
1136
+ columns: { project: text, stream: text, at: int, after: text, updated_at: int },
1137
+ },
1138
+ // 0007: 説明の step の進み。同じ回の回し直しで費用をもう1度かけない(8.3節)。400日
1139
+ insights_explain_run: {
1140
+ primaryKey: ["signal", "job"],
1141
+ columns: { signal: text, job: text, usd_micros: int, tool_calls: int, result_json: textNull, updated_at: int },
1142
+ },
1143
+ // Anthropic を呼んだ1回の費用。列は creative_ai_usage と同じ。core が INSIGHTS_ADMIN.aiUsage で月の合計を読む。400日
1144
+ insights_ai_usage: {
1145
+ primaryKey: ["id"],
1146
+ columns: { id: text, month: text, at: int, project: text, job: textNull, model: text, input_tokens: int, output_tokens: int, cache_read_tokens: int, cache_write_tokens: int, usd_micros: int },
1147
+ },
1148
+ // アプリをまたいだ週の表(11節)。毎週月曜の流れが書く。ずっと残す。week は表を作った週の月曜(Asia/Tokyo)
1149
+ insights_portfolio_week: {
1150
+ primaryKey: ["week"],
1151
+ columns: {
1152
+ week: text,
1153
+ generated_at: int,
1154
+ run: text, // 毎日の Workflow の回の id
1155
+ ads_budget_json: textNull, // AdsBudgetProposal。毎月1日の後の最初の表だけ
1156
+ spread_json: text, // SpreadCandidate[]
1157
+ missing_json: text, // PortfolioMissing[](数の元が無い製品)
1158
+ usd_jpy: real, // 円をドルにした率
1159
+ },
1160
+ },
1161
+ // 週の表の1行(製品 × インストールの月)。行の中身は PortfolioRow の JSON
1162
+ insights_portfolio_row: {
1163
+ primaryKey: ["week", "project", "cohort"],
1164
+ columns: { week: text, project: text, cohort: text, row_json: text },
1165
+ },
1166
+ // 競合のレビュー(competitor-reviews の取り込みが書く・console の競合の画面が読む)。公開された文で、書いた人の名前と URL は入れない
1167
+ insights_competitor_review: {
1168
+ primaryKey: ["project", "app_id", "review_id"],
1169
+ columns: { project: text, app_id: text, review_id: text, stars: int, title: text, body: text, version: textNull, published_at: text, collected_at: int },
1170
+ },
1171
+ // 競合と自分のアプリの評価・評価の数・今のバージョン(iTunes の lookup)。is_self は自分のアプリ
1172
+ insights_competitor_app: {
1173
+ primaryKey: ["project", "app_id"],
1174
+ columns: { project: text, app_id: text, is_self: int, name: text, seller: textNull, rating: realNull, rating_count: intNull, version: textNull, version_at: textNull, price: textNull, genre: textNull, collected_at: int },
1175
+ },
1176
+ // 仮説の記録の仮説(10.1節)。ずっと残す
1177
+ ledger_hypothesis: {
1178
+ primaryKey: ["id"],
1179
+ columns: {
1180
+ id: text, // hyp_…
1181
+ project: textNull, // 全部の製品に当てる仮説は null
1182
+ surface: text,
1183
+ appeal: textNull,
1184
+ expectation: text,
1185
+ decides: text,
1186
+ action_kind: text,
1187
+ action_detail: text,
1188
+ metric: textNull,
1189
+ check_at: textNull, // YYYY-MM-DD
1190
+ method: textNull, // experiment | before_after
1191
+ parent: textNull,
1192
+ source: text, // finding | agent | owner | import
1193
+ status: text, // proposed | open | testing | concluded | rejected_proposal | abandoned
1194
+ outcome: textNull, // supported | rejected | inconclusive | unmeasured
1195
+ effect: realNull,
1196
+ result_json: textNull,
1197
+ conclusion: textNull,
1198
+ next: textNull,
1199
+ applied_at: intNull,
1200
+ created_by: text,
1201
+ created_at: int,
1202
+ updated_at: int,
1203
+ concluded_at: intNull,
1204
+ check_note_json: textNull, // 答え合わせを待っている理由 { day, reason }(0004・IN14)。結論を書いたら null
1205
+ },
1206
+ },
1207
+ // 仮説とつながる物の1行
1208
+ ledger_link: {
1209
+ primaryKey: ["hypothesis", "kind", "ref"],
1210
+ columns: { hypothesis: text, kind: text, ref: text, created_by: text, created_at: int },
1211
+ },
1212
+ // 学んだことの1行。追記だけ
1213
+ ledger_learning: {
1214
+ primaryKey: ["id"],
1215
+ columns: { id: text, project: textNull, hypothesis: textNull, surface: textNull, text: text, source: text, created_by: text, created_at: int },
1216
+ },
1217
+ // ナレッジの検索(FTS5・trigram)。kind: hypothesis | learning | reference。reference は R12 の参考の素材のメモとタグ
1218
+ ledger_search: {
1219
+ primaryKey: [],
1220
+ virtual: "fts5",
1221
+ columns: { kind: textNull, ref: textNull, project: textNull, body: textNull },
1222
+ },
1223
+ };
1224
+ /** insights の D1 の表の頭 */
1225
+ export const INSIGHTS_TABLE_PREFIXES = ["insights_", "ledger_"];
1226
+ /** 表の頭(文脈)。新しい表はこのどれかで始める */
1227
+ export const TABLE_PREFIXES = ["registry_", "people_", "inapp_", "links_", "support_", "access_", "audit_", "sessions_", "config_", "usage_", "decision_", "releases_"];