Skip to content

Commit

Permalink
Change in line with getodk#1371
Browse files Browse the repository at this point in the history
alxndrsn committed Jan 16, 2025
1 parent ae64408 commit 100c424
Showing 13 changed files with 27 additions and 35 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -131,8 +131,7 @@ test-coverage: node_version

.PHONY: lint
lint: node_version
# max-warnings set to take account of legacy database migrations
npx eslint --cache --max-warnings 15 .
npx eslint --cache --max-warnings 0 .


################################################################################
11 changes: 11 additions & 0 deletions lib/model/migrations/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
extends: '../../../.eslintrc.json',
rules: {
// Prevent migrations from including application code.
//
// Mixing application code into database migrations removes assurances that
// the same migration will mutate the same postgresql data identically when
// upgrading from/to different versions of the application.
'no-restricted-modules': [ 'error', { patterns: [ '../*' ] } ],
},
};
9 changes: 0 additions & 9 deletions lib/model/migrations/.eslintrc.json

This file was deleted.

9 changes: 0 additions & 9 deletions lib/model/migrations/legacy/.eslintrc.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// except according to the terms contained in the LICENSE file.
//

const { md5sum } = require('../../../util/crypto');
const { md5sum } = require('../../../util/crypto'); // eslint-disable-line no-restricted-modules

const up = (knex) =>
knex.schema.table('blobs', (blobs) => { blobs.string('md5', 32); })
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ const up = (knex) =>

fa.index([ 'formId' ]);
}).then(() => {
const { expectedFormAttachments } = require('../../../data/schema');
const { expectedFormAttachments } = require('../../../data/schema'); // eslint-disable-line no-restricted-modules
const { uniq, pluck } = require('ramda');

// now add all expected attachments on extant forms.
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

const { shasum, sha256sum } = require('../../../util/crypto');
const { shasum, sha256sum } = require('../../../util/crypto'); // eslint-disable-line no-restricted-modules
const assert = require('assert').strict;

const check = (message, query) =>
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

const { parseClientAudits } = require('../../../data/client-audits');
const { getFormFields } = require('../../../data/schema');
const { traverseXml, findOne, root, node, text } = require('../../../util/xml');
const { parseClientAudits } = require('../../../data/client-audits'); // eslint-disable-line no-restricted-modules
const { getFormFields } = require('../../../data/schema'); // eslint-disable-line no-restricted-modules
const { traverseXml, findOne, root, node, text } = require('../../../util/xml'); // eslint-disable-line no-restricted-modules

const up = (db) => new Promise((resolve, reject) => {
const work = [];
4 changes: 2 additions & 2 deletions lib/model/migrations/legacy/20191231-02-add-schema-storage.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

const { getFormFields } = require('../../../data/schema');
const { getFormFields } = require('../../../data/schema'); // eslint-disable-line no-restricted-modules

const up = async (db) => {
await db.schema.createTable('form_fields', (fields) => {
@@ -51,7 +51,7 @@ const up = async (db) => {
// this config hardcoding would be dangerous with tests except that
// tests will never invoke this path.
const config = require('config').get('default.database');
const db2 = require('../../migrate').connect(config);
const db2 = require('../../migrate').connect(config); // eslint-disable-line no-restricted-modules
return db2.select('projectId', 'xmlFormId').from('forms').where({ currentDefId: formDefId })
.then(([{ projectId, xmlFormId }]) => {
process.stderr.write(`\n!!!!\nThe database upgrade to v0.8 has failed because the Form '${xmlFormId}' in Project ${projectId} has an invalid schema. It tries to bind multiple instance nodes at the path ${path}.\n!!!!\n\n`);
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

const { Submission } = require('../../frames');
const { Submission } = require('../../frames'); // eslint-disable-line no-restricted-modules

const up = async (db) => {
const work = [];
2 changes: 1 addition & 1 deletion lib/model/migrations/legacy/20210120-01-instance-names.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

const { Submission } = require('../../frames');
const { Submission } = require('../../frames'); // eslint-disable-line no-restricted-modules

const up = async (db) => {
await db.schema.table('submission_defs', (sds) => {
Original file line number Diff line number Diff line change
@@ -8,10 +8,10 @@
// except according to the terms contained in the LICENSE file.

const { map } = require('ramda');
const { getFormFields } = require('../../../data/schema');
const { getSelectMultipleResponses } = require('../../../data/submission');
const { Form } = require('../../frames');
const { construct } = require('../../../util/util');
const { getFormFields } = require('../../../data/schema'); // eslint-disable-line no-restricted-modules
const { getSelectMultipleResponses } = require('../../../data/submission'); // eslint-disable-line no-restricted-modules
const { Form } = require('../../frames'); // eslint-disable-line no-restricted-modules
const { construct } = require('../../../util/util'); // eslint-disable-line no-restricted-modules

const up = async (db) => {
// add select many flag, options field to fields
2 changes: 1 addition & 1 deletion lib/model/migrations/legacy/20230109-01-add-form-schema.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

const { getFormFields, compare } = require('../../../data/schema');
const { getFormFields, compare } = require('../../../data/schema'); // eslint-disable-line no-restricted-modules

/* Steps of this migration
1. remove check field collision trigger

0 comments on commit 100c424

Please sign in to comment.