opral / lix-sdk

1 stars 0 forks source link

Change control file metadata #72

Open samuelstroschein opened 1 week ago

samuelstroschein commented 1 week ago

Proposal

Find a way to change control file metadata [without snapshotting the file table].

metadata should be change controlled because the outcome can be stark e.g. in the csv app change the unique column from email to something-else

Context

LIXDK-152 added file metadata without capabilities to track changes in the metadata.

File metadata is necessary to establish an app <-> plugin communication. For example, the CSV app (will) leverage(s) the metadata field to set a unique column from the app by prompting the user "what's the unique column in this csv?". The csv plugin then leverages the unique column to track changes, merge, etc.

samuelstroschein commented 1 week ago

A trivial (and therefore probably correct way) is to store snapshots of the metadata field in the Change table. Apps (and lix itself) can query the Change table for metadata changes.

Saved change schema

const change = {
  "id": "uuid",
  "file_id": "file.id",
  // prefixed with lix for namespacing
  "type": "lix_file_metadata",
  "value": file.metadata
}

Querying file metadata changes

const metadataChanges = await lix.db.query("change")
  .selectAll()
  .where("file_id", "=", file.id)
  .where("type", "=", "lix_file_metadata")
  .execute()

Using the change table internally in lix is further confirmation that LIXDK-106 is the right move. Lix itself will be able to store changes.