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

View File

@@ -40,6 +40,11 @@ describe('downvoteSegmentArchiveJob', () => {
return; 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 () => { afterEach(async () => {
await db.prepare('run', 'DELETE FROM "sponsorTimes"'); await db.prepare('run', 'DELETE FROM "sponsorTimes"');
await db.prepare('run', 'DELETE FROM "archivedSponsorTimes"'); await db.prepare('run', 'DELETE FROM "archivedSponsorTimes"');
@@ -52,7 +57,7 @@ describe('downvoteSegmentArchiveJob', () => {
const getSegmentsInMainTable = (dayLimit: number, voteLimit: number, now: number): Promise<DBSegment[]> => { const getSegmentsInMainTable = (dayLimit: number, voteLimit: number, now: number): Promise<DBSegment[]> => {
return db.prepare( return db.prepare(
'all', 'all',
'SELECT * FROM "sponsorTimes" WHERE votes < ? AND (? - timeSubmitted) > ?', 'SELECT * FROM "sponsorTimes" WHERE "votes" < ? AND (? - "timeSubmitted") > ?',
[ [
voteLimit, voteLimit,
now, now,