globalbibletools / gbt

https://interlinear.globalbibletools.com
15 stars 2 forks source link

Migrate gloss history data structures to support phrasal glosses #384

Closed arrocke closed 5 months ago

arrocke commented 7 months ago

Description

With multi word gloss, we need to connect gloss history to phrases rather than words. This PR addresses the data migration to make this happen.

Process

We will do this in two steps. It is simpler than #376 because nothing is reading these events yet.

  1. Add new event schema, update history writes to also write to new schema, and write migration for existing events.
  2. Update history writes to no longer write to the old schema, and remove the old schema from the database.

DB Structure

erDiagram
  GlossEvent ||--o{ GlossEventType : ""
  User }o--o{ GlossEvent : ""
  Phrase }o--o{ GlossEvent : ""

  GlossEvent {
    int id PK
    int phraseId FK
    UUID userId FK
    Date timestamp
    int eventTypeId FK
    JSON data
  }

  GlossEventType {
    int id
    string name "WordAdded | WordRemoved | GlossChanged | GlossImported | PhraseDeleted"
  }

Event Data Schema

interface WordAddedData {
  wordId: string
}

interface WordRemovedData {
  wordId: string
}

// undefined fields indicate no change
interface GlossChangedData {
  gloss?: string
  state?: GlossState
}

interface PhraseDeletedData {}

interface GlossImportedData {
  wordIds: string[]
  gloss: string
  state: GlossState
}