balena-io / pensieve

A tool for managing and viewing structured documents, backed by the power of git
7 stars 5 forks source link

Convert underlying data structure to an array #189

Closed LucianBuzzo closed 6 years ago

LucianBuzzo commented 6 years ago

Current state

At present, the underlying data structure used in Pensieve is an object. A key-value store where the title of a document entry is the key.

{
  'Entry No.1': {
    description: 'Lorem ipsum dolor sit amet'
  },
  'Entry no.2': {
    description: 'Integer facilisis vestibulum nibh ut ornare.'
  }
}

Problems

This has a number of problems:

Proposed state

What I propose is that we switch the structure to an array and add a new attribute to schema objects, title: boolean that can be used to specify which field is used as the entry title

Edit: 2017-21-11

What I propose is switching the underlying data structure of the document to an array and converting the schema to an array. The first element in the schema array is used as the title field.

The new data structure would look something like this:

[
  {
    label: 'Entry No.1',
    description: 'Lorem ipsum dolor sit amet'
  },
    label: 'Entry no.2',
    description: 'Integer facilisis vestibulum nibh ut ornare.'
  }
]

With the schema looking like this:

[
  {
    name: 'title'
    type: 'Text'
  }, {
    name: 'label'
    type: 'Text'
  }, {
    name: description,
    type: 'Text'
  }
]

Upgrading existing Pensieve installations

As there are a number of Pensieve installations in existence we should provide a simple upgrade path to the new format.

alexandrosm commented 6 years ago

@LucianBuzzo the "title:true" thing is problematic, as it can be made true for multiple fields. We need a single place where the title field is explicitly defined.

LucianBuzzo commented 6 years ago

What we settled on is converting the schema to an array of objects, and using the first element in the array as the title. The conversion process will create a schema field named title and place it at the beginning of the schema array.

I've edited my original post to reflect this ^^