From 87ea18b3cb878477977f9bc468a49cfa037121a3 Mon Sep 17 00:00:00 2001 From: Michael O'Brien Date: Thu, 25 Nov 2021 14:29:50 +1100 Subject: [PATCH] FIX: tables without primary sort key --- src/Schema.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Schema.js b/src/Schema.js index e8fb246..e193bcb 100644 --- a/src/Schema.js +++ b/src/Schema.js @@ -111,7 +111,6 @@ export class Schema { let primary = indexes.primary let fields = this.schemaModelFields = { [primary.hash]: { type: 'string', required: true, value: `${SchemaKey}` }, - [primary.sort]: { type: 'string', required: true, value: `${SchemaKey}:\${name}` }, format: { type: 'string', required: true }, indexes: { type: 'array', required: true }, name: { type: 'string', required: true }, @@ -120,6 +119,9 @@ export class Schema { queries: { type: 'object', required: true }, version: { type: 'string', required: true }, } + if (primary.sort) { + fields[primary.sort] = { type: 'string', required: true, value: `${SchemaKey}:\${name}`} + } this.models[SchemaModel] = new Model(table, SchemaModel, {fields}) } @@ -128,12 +130,14 @@ export class Schema { let primary = indexes.primary let fields = this.migrationModelFields = { [primary.hash]: { type: 'string', value: `${MigrationKey}` }, - [primary.sort]: { type: 'string', value: `${MigrationKey}:\${version}` }, date: { type: 'date', required: true }, description: { type: 'string', required: true }, path: { type: 'string', required: true }, version: { type: 'string', required: true }, } + if (primary.sort) { + fields[primary.sort] = { type: 'string', value: `${MigrationKey}:\${version}` } + } this.models[MigrationModel] = new Model(this.table, MigrationModel, {fields, indexes}) }