From d9a66a58949e001ae66405cb4b861dfb68e26c7a Mon Sep 17 00:00:00 2001 From: Michael C Date: Sat, 10 Jul 2021 00:26:18 -0400 Subject: [PATCH] quote & check for db version --- src/cronjob/downvoteSegmentArchiveJob.ts | 4 ++-- test/cases/downvoteSegmentArchiveJob.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cronjob/downvoteSegmentArchiveJob.ts b/src/cronjob/downvoteSegmentArchiveJob.ts index c2f8f4e..f5e8e03 100644 --- a/src/cronjob/downvoteSegmentArchiveJob.ts +++ b/src/cronjob/downvoteSegmentArchiveJob.ts @@ -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, diff --git a/test/cases/downvoteSegmentArchiveJob.ts b/test/cases/downvoteSegmentArchiveJob.ts index c750526..6700272 100644 --- a/test/cases/downvoteSegmentArchiveJob.ts +++ b/test/cases/downvoteSegmentArchiveJob.ts @@ -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 => { return db.prepare( 'all', - 'SELECT * FROM "sponsorTimes" WHERE votes < ? AND (? - timeSubmitted) > ?', + 'SELECT * FROM "sponsorTimes" WHERE "votes" < ? AND (? - "timeSubmitted") > ?', [ voteLimit, now,