Add a sortIndex to items.
This commit is contained in:
parent
ab6ef97d91
commit
c72959841f
|
@ -14,6 +14,23 @@ export const dataMigrations: Array<Migration<string>> = [
|
||||||
migrated[key] = item;
|
migrated[key] = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return migrated;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
version: '0.3.0',
|
||||||
|
async migrate(data: Record<string, any>) {
|
||||||
|
const migrated: Record<string, any> = {
|
||||||
|
version: '0.3.0',
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries<Queue.Item>(data)) {
|
||||||
|
if (key.startsWith('qi')) {
|
||||||
|
migrated[key] = value;
|
||||||
|
migrated[key].sortIndex = value.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return migrated;
|
return migrated;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -42,6 +42,7 @@ export class Settings {
|
||||||
const item: Queue.Item = {
|
const item: Queue.Item = {
|
||||||
added: new Date(),
|
added: new Date(),
|
||||||
id,
|
id,
|
||||||
|
sortIndex: id,
|
||||||
text,
|
text,
|
||||||
url,
|
url,
|
||||||
};
|
};
|
||||||
|
@ -51,6 +52,7 @@ export class Settings {
|
||||||
[`qi${id}`]: {
|
[`qi${id}`]: {
|
||||||
added: item.added.toISOString(),
|
added: item.added.toISOString(),
|
||||||
id,
|
id,
|
||||||
|
sortIndex: id,
|
||||||
text,
|
text,
|
||||||
url,
|
url,
|
||||||
},
|
},
|
||||||
|
|
|
@ -22,6 +22,7 @@ declare global {
|
||||||
type Item = {
|
type Item = {
|
||||||
added: Date;
|
added: Date;
|
||||||
id: number;
|
id: number;
|
||||||
|
sortIndex: number;
|
||||||
text: string;
|
text: string;
|
||||||
url: string;
|
url: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,7 @@ const queueItemSample: Queue.Item = {
|
||||||
id: 1,
|
id: 1,
|
||||||
text: 'Sample',
|
text: 'Sample',
|
||||||
url: 'https://example.org',
|
url: 'https://example.org',
|
||||||
};
|
} as unknown as Queue.Item;
|
||||||
|
|
||||||
test('dataMigrations happy path', async (t) => {
|
test('dataMigrations happy path', async (t) => {
|
||||||
let data: Record<string, any> = {
|
let data: Record<string, any> = {
|
||||||
|
|
|
@ -18,6 +18,19 @@ Generated by [AVA](https://avajs.dev).
|
||||||
version: '0.1.7',
|
version: '0.1.7',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
> Migration 0.3.0
|
||||||
|
|
||||||
|
{
|
||||||
|
qi1: {
|
||||||
|
added: Date 2022-03-02 16:00:00 UTC {},
|
||||||
|
id: 1,
|
||||||
|
sortIndex: 1,
|
||||||
|
text: 'Sample',
|
||||||
|
url: 'https://example.org',
|
||||||
|
},
|
||||||
|
version: '0.3.0',
|
||||||
|
}
|
||||||
|
|
||||||
## dataMigrations unhappy path
|
## dataMigrations unhappy path
|
||||||
|
|
||||||
> Migration 0.1.7
|
> Migration 0.1.7
|
||||||
|
@ -26,6 +39,12 @@ Generated by [AVA](https://avajs.dev).
|
||||||
version: '0.1.7',
|
version: '0.1.7',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
> Migration 0.3.0
|
||||||
|
|
||||||
|
{
|
||||||
|
version: '0.3.0',
|
||||||
|
}
|
||||||
|
|
||||||
## Serializing & Deserializing Queue
|
## Serializing & Deserializing Queue
|
||||||
|
|
||||||
> Serialized
|
> Serialized
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue