forked from getodk/central-backend
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes getodk#459: reduce timestamptz precision for submission tables
- Loading branch information
1 parent
234aa41
commit c893302
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2022 ODK Central Developers | ||
// See the NOTICE file at the top-level directory of this distribution and at | ||
// https://github.com/getodk/central-backend/blob/master/NOTICE. | ||
// This file is part of ODK Central. It is subject to the license terms in | ||
// the LICENSE file found in the top-level directory of this distribution and at | ||
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central, | ||
// including this file, may be copied, modified, propagated, or distributed | ||
// except according to the terms contained in the LICENSE file. | ||
|
||
// Issue: #cb459 - `gt` filter for submissionDate is not working as expected because of tz precision | ||
// Root cause: Default timestamptz precision in postgres is microseconds and node/js has just milliseconds | ||
// Solution: Let's change precision to milliseconds in database, since there is no value in having higher precision | ||
// in the database when application can't use/handle it + typical usage of ODK Central doesn't demand higher | ||
// precision. | ||
|
||
const up = async (db) => { | ||
await db.schema.table('submissions', (submissions) => { | ||
submissions.dateTime('createdAt', { useTz: true, precision: 3 }).notNull().alter(); | ||
submissions.dateTime('updatedAt', { useTz: true, precision: 3 }).alter(); | ||
submissions.dateTime('deletedAt', { useTz: true, precision: 3 }).alter(); | ||
}); | ||
|
||
await db.schema.table('submission_defs', (sDefs) => { | ||
sDefs.dateTime('createdAt', { useTz: true, precision: 3 }).notNull().alter(); | ||
}); | ||
}; | ||
|
||
const down = async (db) => { | ||
await db.schema.table('submissions', (submissions) => { | ||
submissions.dateTime('createdAt', { useTz: true, precision: 6 }).notNull().alter(); | ||
submissions.dateTime('updatedAt', { useTz: true, precision: 6 }).alter(); | ||
submissions.dateTime('deletedAt', { useTz: true, precision: 6 }).alter(); | ||
}); | ||
|
||
await db.schema.table('submission_defs', (sDefs) => { | ||
sDefs.dateTime('createdAt', { useTz: true, precision: 6 }).notNull().alter(); | ||
}); | ||
}; | ||
|
||
module.exports = { up, down }; |