aboutsummaryrefslogtreecommitdiff
path: root/persistence/schema.ts
blob: 8d381d0c1be336efd1120719e9cba04c6e84e98e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 * IndexedDB schema for the user-data database. The string values follow
 * Dexie's index notation:
 *
 *   &field              primary key (unique)
 *   ++id                auto-incrementing primary key
 *   field               plain index on a scalar
 *   [a+b]               compound index
 *   *field              multi-entry index on an array field
 *
 * Frozen at module load so a runtime typo on the wrong key throws rather
 * than silently mutating the schema object. Snapshot tests lock these
 * strings; any change here requires a migration.
 */
export const USER_DATA_SCHEMA_V1 = Object.freeze({
  worlds: '&id, seed, currentPlayerCharacterId',
  people:
    '&id, tier, isPlayerCharacter, lastSimulatedAt, currentPlaceId, [currentPlaceId+tier], *relationshipIds',
  relationships:
    '&id, personAId, personBId, type, currentState, lastInteractionAt, [personAId+personBId], [type+currentState]',
  institutions: '&id, placeId, type',
  places: '&id, parentPlaceId, type',
  worldEvents: '&id, category, startedAt, endedAt',
  eventLogs: '&id, personId, time, [personId+time]',
  memoirs: '&id, personId, generatedAt',
  routines: '&id, personId',
  flowHistory: '&id, personId, time, [personId+time]',
  scheduledEvents: '&id, targetPersonId, priority',
  settings: '&key'
})

/** IndexedDB schema for the content cache — replaceable per content update. */
export const CONTENT_CACHE_SCHEMA_V1 = Object.freeze({
  content: '&chunkId, version, fetchedAt',
  manifest: '&id'
})

/** IndexedDB schema for the audio cache — blobs + a manifest row. */
export const AUDIO_CACHE_SCHEMA_V1 = Object.freeze({
  audio: '&trackId, version, fetchedAt',
  manifest: '&id'
})

/** Current persistence schema version. Bump when any schema above changes. */
export const SCHEMA_VERSION = 1 as const

export const USER_DATA_DB_NAME = 'HollowdarkUserData' as const
export const CONTENT_CACHE_DB_NAME = 'HollowdarkContentCache' as const
export const AUDIO_CACHE_DB_NAME = 'HollowdarkAudioCache' as const