-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support copying the most recent item to the counter table #21
Conversation
This does not achieve the same goals I had in mind on #20. How does this handle the case for circulars? How do you see this used for versioning? In the case of an update to a specific circular, what kind of config options would you have to pass into this to result in keeping the same circularId and bumping the version field? |
This is nasa-gcn#20 as a one-liner.
3acf00b
to
928349a
Compare
{
doc,
counterTableName: 'circulars',
counterTableKey: {circularId: 33693 /* for example */},
counterTableAttributeName: 'version',
counterTableCopyItem: true,
tableName: 'circulars_history',
tableAttributeName: 'version',
initialValue: 1,
} |
Ah, my use didn't swap the props around like this, I see how this could work now. I think this is good, but there are a couple points that I think this misses:
|
Correct.
I don't understand the question. |
How do you maintain the history when inserting new rows? test('maintains history when new items are inserted', async () => {
const initialID = 1
const firstResult = await autoincrement.put({
widgetName: 'runcible spoon',
})
expect(firstResult).toEqual(initialID)
expect(await autoincrement.getLast()).toEqual(initialID)
const secondResult = await autoincrement.put({
widgetName: 'a new widget',
})
expect(secondResult).toBe(initialID + 1)
const [widgetItems, autoincrementItems] = await Promise.all(
['widgets', 'autoincrement'].map(
async (TableName) => (await doc.scan({ TableName })).Items
)
)
expect(widgetItems).toEqual([
{ widgetID: 2, widgetName: 'a new widget' },
{ widgetID: 1, widgetName: 'runcible spoon' },
])
expect(autoincrementItems).toEqual(
counterTableCopyItem
? [
{
tableName: 'widgets',
counter: 1,
widgetName: 'runcible spoon',
},
{
tableName: 'widgets',
counter: 2,
widgetName: 'a new widget',
},
]
: [
{
tableName: 'widgets',
counter: 2,
},
]
)
}) Which fails with the following when the copy flag is true (first object missing):
|
Do you mean: how do you maintain history when inserting new GCN Circulars (entirely new Circulars that don't have a previous version)? |
Yes |
Good point. I have to think about that. |
Closing in favor of #20. |
This is #20 as a one-liner.