Skip to content

Commit

Permalink
fixes getodk#459: reduce timestamptz precision for submission tables
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja committed Dec 8, 2022
1 parent 234aa41 commit c893302
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/model/migrations/20221208-01-reduce-tz-precision.js
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 };

0 comments on commit c893302

Please sign in to comment.