quote & check for db version

This commit is contained in:
Michael C 2021-07-10 00:26:18 -04:00 committed by Haidang666
parent bbb1db014c
commit d9a66a5894
2 changed files with 8 additions and 3 deletions

View file

@ -19,7 +19,7 @@ export const archiveDownvoteSegment = async (dayLimit: number, voteLimit: number
`INSERT INTO "archivedSponsorTimes"
SELECT *
FROM "sponsorTimes"
WHERE votes < ? AND (? - timeSubmitted) > ?`,
WHERE "votes" < ? AND (? - "timeSubmitted") > ?`,
[
voteLimit,
timeNow,
@ -37,7 +37,7 @@ export const archiveDownvoteSegment = async (dayLimit: number, voteLimit: number
try {
await db.prepare(
'run',
'DELETE FROM "sponsorTimes" WHERE votes < ? AND (? - timeSubmitted) > ?',
'DELETE FROM "sponsorTimes" WHERE "votes" < ? AND (? - "timeSubmitted") > ?',
[
voteLimit,
timeNow,

View file

@ -40,6 +40,11 @@ describe('downvoteSegmentArchiveJob', () => {
return;
});
it('Should update the database version when starting the application', async () => {
const version = (await db.prepare('get', 'SELECT key, value FROM config where key = ?', ['version'])).value;
assert.ok(version >= 21, "version should be greater or equal to 21");
});
afterEach(async () => {
await db.prepare('run', 'DELETE FROM "sponsorTimes"');
await db.prepare('run', 'DELETE FROM "archivedSponsorTimes"');
@ -52,7 +57,7 @@ describe('downvoteSegmentArchiveJob', () => {
const getSegmentsInMainTable = (dayLimit: number, voteLimit: number, now: number): Promise<DBSegment[]> => {
return db.prepare(
'all',
'SELECT * FROM "sponsorTimes" WHERE votes < ? AND (? - timeSubmitted) > ?',
'SELECT * FROM "sponsorTimes" WHERE "votes" < ? AND (? - "timeSubmitted") > ?',
[
voteLimit,
now,