Skip to content

Commit

Permalink
feat: revert adding of delete field to schema (#20)
Browse files Browse the repository at this point in the history
The delete field does not actually belong in the indexer, since it does
not change indexer behaviour in any way. Fixes #19

This reverts commit e617aa0.
  • Loading branch information
gmaclennan authored Oct 26, 2023
1 parent 2a63655 commit a262d67
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 158 deletions.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import assert from 'assert'
* @property {string} versionId
* @property {string[]} links
* @property {string} updatedAt
* @property {Boolean} deleted
*/

/** @typedef {{ type: string, pk: 1 | 0, cid: number, notnull: 1 | 0, dflt_value: any, name: string }} ColumnInfo */
Expand All @@ -29,7 +28,6 @@ const docSchema = {
links: { type: 'TEXT', notnull: 1, dflt_value: null, pk: 0 },
forks: { type: 'TEXT', notnull: 1, dflt_value: null, pk: 0 },
updatedAt: { type: 'TEXT', notnull: 1, pk: 0 },
deleted: { type: 'INTEGER', notnull: 1, pk: 0 },
}

/** @type {ColumnSchema} */
Expand Down Expand Up @@ -72,7 +70,7 @@ export class DbApi {
)
const docColumns = tableInfo.map(({ name }) => name)
this.#getDocSql = db.prepare(
`SELECT docId, versionId, links, forks, updatedAt, deleted
`SELECT docId, versionId, links, forks, updatedAt
FROM ${docTableName}
WHERE docId = ?`
)
Expand Down
15 changes: 1 addition & 14 deletions test/complex-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ test('booleans, arrays and objects are transformed', async (t) => {
boolean: true,
array: [],
object: {},
deleted: false,
},
{
docId: 'B',
Expand All @@ -23,17 +22,8 @@ test('booleans, arrays and objects are transformed', async (t) => {
boolean: false,
array: ['foo'],
object: { foo: 'bar' },
deleted: false,
},
{
docId: 'C',
versionId: '1',
links: [],
updatedAt,
array: [],
object: {},
deleted: false,
},
{ docId: 'C', versionId: '1', links: [], updatedAt, array: [], object: {} },
]

const extraColumns = `
Expand All @@ -55,7 +45,6 @@ object TEXT NOT NULL`
boolean: 1,
array: '[]',
object: '{}',
deleted: 0,
},
{
docId: 'B',
Expand All @@ -66,7 +55,6 @@ object TEXT NOT NULL`
boolean: 0,
array: '["foo"]',
object: '{"foo":"bar"}',
deleted: 0,
},
{
docId: 'C',
Expand All @@ -77,7 +65,6 @@ object TEXT NOT NULL`
boolean: 0,
array: '[]',
object: '{}',
deleted: 0,
},
]

Expand Down
72 changes: 8 additions & 64 deletions test/index-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,14 @@ import test from 'tape'
import { create } from './utils.js'

const docs = [
{
docId: 'A',
seq: 1,
versionId: '1',
links: [],
updatedAt: '',
deleted: false,
},
{
docId: 'A',
seq: 2,
versionId: '2',
links: ['1'],
updatedAt: '',
deleted: false,
},
{
docId: 'A',
seq: 3,
versionId: '3',
links: ['1'],
updatedAt: '',
deleted: false,
},
{
docId: 'A',
seq: 4,
versionId: '4',
links: ['2', '3'],
updatedAt: '',
deleted: false,
},
{
docId: 'A',
seq: 5,
versionId: '5',
links: ['4'],
updatedAt: '',
deleted: false,
},
{
docId: 'A',
seq: 6,
versionId: '6',
links: ['4'],
updatedAt: '',
deleted: false,
},
{
docId: 'A',
seq: 7,
versionId: '7',
links: ['4'],
updatedAt: '',
deleted: false,
},
{
docId: 'A',
seq: 8,
versionId: '8',
links: ['5', '6'],
updatedAt: '',
deleted: false,
},
{ docId: 'A', seq: 1, versionId: '1', links: [], updatedAt: '' },
{ docId: 'A', seq: 2, versionId: '2', links: ['1'], updatedAt: '' },
{ docId: 'A', seq: 3, versionId: '3', links: ['1'], updatedAt: '' },
{ docId: 'A', seq: 4, versionId: '4', links: ['2', '3'], updatedAt: '' },
{ docId: 'A', seq: 5, versionId: '5', links: ['4'], updatedAt: '' },
{ docId: 'A', seq: 6, versionId: '6', links: ['4'], updatedAt: '' },
{ docId: 'A', seq: 7, versionId: '7', links: ['4'], updatedAt: '' },
{ docId: 'A', seq: 8, versionId: '8', links: ['5', '6'], updatedAt: '' },
]

test('onceWriteDoc called for each doc', async (t) => {
Expand Down
35 changes: 8 additions & 27 deletions test/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@ import test from 'tape'
import { create, permute } from './utils.js'

const docs = [
{ docId: 'A', versionId: '1', links: [], updatedAt: '', deleted: false },
{ docId: 'A', versionId: '2', links: ['1'], updatedAt: '', deleted: false },
{ docId: 'A', versionId: '3', links: ['1'], updatedAt: '', deleted: false },
{
docId: 'A',
versionId: '4',
links: ['2', '3'],
updatedAt: '',
deleted: false,
},
{ docId: 'A', versionId: '5', links: ['4'], updatedAt: '', deleted: false },
{ docId: 'A', versionId: '6', links: ['4'], updatedAt: '', deleted: false },
{ docId: 'A', versionId: '7', links: ['4'], updatedAt: '', deleted: true },
{
docId: 'A',
versionId: '8',
links: ['5', '6'],
updatedAt: '',
deleted: true,
},
{ docId: 'A', versionId: '1', links: [], updatedAt: '' },
{ docId: 'A', versionId: '2', links: ['1'], updatedAt: '' },
{ docId: 'A', versionId: '3', links: ['1'], updatedAt: '' },
{ docId: 'A', versionId: '4', links: ['2', '3'], updatedAt: '' },
{ docId: 'A', versionId: '5', links: ['4'], updatedAt: '' },
{ docId: 'A', versionId: '6', links: ['4'], updatedAt: '' },
{ docId: 'A', versionId: '7', links: ['4'], updatedAt: '' },
{ docId: 'A', versionId: '8', links: ['5', '6'], updatedAt: '' },
]

const scenarios = [
Expand All @@ -34,7 +22,6 @@ const scenarios = [
links: ['1'],
forks: [],
updatedAt: '',
deleted: 0,
},
},
{
Expand All @@ -45,7 +32,6 @@ const scenarios = [
links: ['1'],
forks: ['2'],
updatedAt: '',
deleted: 0,
},
},
{
Expand All @@ -56,7 +42,6 @@ const scenarios = [
links: ['2', '3'],
forks: [],
updatedAt: '',
deleted: 0,
},
},
{
Expand All @@ -67,7 +52,6 @@ const scenarios = [
links: ['4'],
forks: [],
updatedAt: '',
deleted: 0,
},
},
{
Expand All @@ -78,7 +62,6 @@ const scenarios = [
links: ['4'],
forks: ['5'],
updatedAt: '',
deleted: 0,
},
},
{
Expand All @@ -89,7 +72,6 @@ const scenarios = [
links: ['4'],
forks: ['5', '6'],
updatedAt: '',
deleted: 1,
},
},
{
Expand All @@ -100,7 +82,6 @@ const scenarios = [
links: ['5', '6'],
forks: ['7'],
updatedAt: '',
deleted: 1,
},
},
]
Expand Down
57 changes: 9 additions & 48 deletions test/timestamps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,12 @@ test('If doc has timestamp, it is used to select winner', async (t) => {
const updated2 = new Date(1999, 0, 2).toISOString()
const updated3 = new Date(1999, 0, 3).toISOString()
const docs = [
{
docId: 'A',
versionId: '1',
links: [],
updatedAt: updated3,
deleted: false,
},
{
docId: 'A',
versionId: '2',
links: ['1'],
updatedAt: updated2,
deleted: false,
},
{
docId: 'A',
versionId: '3',
links: ['1'],
updatedAt: updated1,
deleted: false,
},
{
docId: 'B',
versionId: '1',
links: [],
updatedAt: updated3,
deleted: false,
},
{
docId: 'B',
versionId: '2',
links: ['1'],
updatedAt: updated1,
deleted: false,
},
{
docId: 'B',
versionId: '3',
links: ['1'],
updatedAt: updated2,
deleted: false,
},
{ docId: 'A', versionId: '1', links: [], updatedAt: updated3 },
{ docId: 'A', versionId: '2', links: ['1'], updatedAt: updated2 },
{ docId: 'A', versionId: '3', links: ['1'], updatedAt: updated1 },
{ docId: 'B', versionId: '1', links: [], updatedAt: updated3 },
{ docId: 'B', versionId: '2', links: ['1'], updatedAt: updated1 },
{ docId: 'B', versionId: '3', links: ['1'], updatedAt: updated2 },
]

const { indexer, api, cleanup } = create({ extraColumns: 'timestamp NUMBER' })
Expand All @@ -61,7 +25,6 @@ test('If doc has timestamp, it is used to select winner', async (t) => {
versionId: '2',
links: ['1'],
forks: ['3'],
deleted: 0,
}

const head = api.getDoc(expected.docId)
Expand All @@ -77,7 +40,6 @@ test('If doc has timestamp, it is used to select winner', async (t) => {
versionId: '3',
links: ['1'],
forks: ['2'],
deleted: 0,
}

const head = api.getDoc(expected.docId)
Expand All @@ -93,9 +55,9 @@ test('If doc has timestamp, it is used to select winner', async (t) => {
test('If doc has no timestamp, version is used to select a deterministic winner', async (t) => {
const updatedAt = new Date().toISOString()
const docs = [
{ docId: 'A', versionId: '1', links: [], updatedAt, deleted: false },
{ docId: 'A', versionId: '2', links: ['1'], updatedAt, deleted: false },
{ docId: 'A', versionId: '3', links: ['1'], updatedAt, deleted: false },
{ docId: 'A', versionId: '1', links: [], updatedAt },
{ docId: 'A', versionId: '2', links: ['1'], updatedAt },
{ docId: 'A', versionId: '3', links: ['1'], updatedAt },
]

const { indexer, api, cleanup } = create()
Expand All @@ -105,7 +67,6 @@ test('If doc has no timestamp, version is used to select a deterministic winner'
versionId: '3',
links: ['1'],
forks: ['2'],
deleted: 0,
}

indexer.batch(docs)
Expand Down
3 changes: 1 addition & 2 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export function create({ extraColumns = '' } = {}) {
versionId TEXT NOT NULL,
links TEXT NOT NULL,
forks TEXT NOT NULL,
updatedAt TEXT NOT NULL,
deleted INTEGER NOT NULL
updatedAt TEXT NOT NULL
${extraColumns ? ', ' + extraColumns : ''}
)
WITHOUT ROWID`
Expand Down

0 comments on commit a262d67

Please sign in to comment.