Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/model/knex-migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const withKnex = (config) => (mutator) => {
};

// Given a database, initiates migrations on it.
const migrate = (db) => db.migrate.latest({ directory: `${__dirname}/migrations` });
const migrate = (db) => db.migrate.latest({ directory: [`${__dirname}/migrations/archive`, `${__dirname}/migrations`] });

module.exports = { knexConnect, withKnex, migrate };

6 changes: 6 additions & 0 deletions lib/model/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@ setlibpqEnv(config.get('default.database'));
module.exports = {
client: 'pg',
connection: {},
migrations: {
directory: [
'./migrations/archive',
'./migrations'
]
}
};

6 changes: 6 additions & 0 deletions lib/model/migrations/archive/.eslintrc.json
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we really need this.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../../.eslintrc.json",
"rules": {
"no-restricted-modules": [ "error", { "patterns": [ "../../*", "!../../pure-sql-migration" ] } ]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// except according to the terms contained in the LICENSE file.
//

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

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

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

// now add all expected attachments on extant forms.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'); // eslint-disable-line no-restricted-modules
const { shasum, sha256sum } = require('../../../util/crypto'); // eslint-disable-line no-restricted-modules
const assert = require('assert').strict;

const check = (message, query) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'); // 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 { 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 = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'); // eslint-disable-line no-restricted-modules
const { getFormFields } = require('../../../data/schema'); // eslint-disable-line no-restricted-modules

const up = async (db) => {
await db.schema.createTable('form_fields', (fields) => {
Expand Down Expand Up @@ -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('../knex-migrator').knexConnect(config); // eslint-disable-line no-restricted-modules
const db2 = require('../../knex-migrator').knexConnect(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`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'); // eslint-disable-line no-restricted-modules
const { Submission } = require('../../frames'); // eslint-disable-line no-restricted-modules

const up = async (db) => {
const work = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'); // eslint-disable-line no-restricted-modules
const { Submission } = require('../../frames'); // eslint-disable-line no-restricted-modules

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

const { map } = require('ramda');
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 { 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'); // eslint-disable-line no-restricted-modules
const { getFormFields, compare } = require('../../../data/schema'); // eslint-disable-line no-restricted-modules

/* Steps of this migration
1. remove check field collision trigger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

module.exports = require('../pure-sql-migration')(__filename);
module.exports = require('../../pure-sql-migration')(__filename);
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

module.exports = require('../pure-sql-migration')(__filename);
module.exports = require('../../pure-sql-migration')(__filename);
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

module.exports = require('../pure-sql-migration')(__filename);
module.exports = require('../../pure-sql-migration')(__filename);
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

module.exports = require('../pure-sql-migration')(__filename);
module.exports = require('../../pure-sql-migration')(__filename);
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.

module.exports = require('../pure-sql-migration')(__filename);
module.exports = require('../../pure-sql-migration')(__filename);
10 changes: 5 additions & 5 deletions test/db-migrations/migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { execSync } = require('node:child_process');
const migrationsDir = './lib/model/migrations';
const holdingPen = './test/db-migrations/.holding-pen';

fs.mkdirSync(holdingPen, { recursive: true });
fs.mkdirSync(`${holdingPen}/archive`, { recursive: true });

restoreMigrations(); // eslint-disable-line no-use-before-define
const allMigrations = loadMigrationsList(); // eslint-disable-line no-use-before-define
Expand Down Expand Up @@ -52,7 +52,7 @@ function runIncluding(lastMigrationToRun) {
}

function getIndex(migrationName) {
const idx = allMigrations.indexOf(migrationName);
const idx = allMigrations.findIndex(f => f.endsWith(migrationName));
log('getIndex()', migrationName, 'found at', idx);
if (idx === -1) throw new Error(`Unknown migration: ${migrationName}`);
return idx;
Expand All @@ -67,16 +67,16 @@ function moveMigrationsToHoldingPen() {
}

function moveAll(src, tgt) {
fs.readdirSync(src)
fs.readdirSync(src, { recursive: true })
.filter(f => f.endsWith('.js'))
.forEach(f => fs.renameSync(`${src}/${f}`, `${tgt}/${f}`));
}

function loadMigrationsList() {
const migrations = fs.readdirSync(migrationsDir)
const migrations = fs.readdirSync(migrationsDir, { recursive: true })
.filter(f => f.endsWith('.js'))
.map(f => f.replace(/\.js$/, ''))
.sort(); // match sorting in pg-migrator and knex's fs-migrations.js
.sort((a, b) => a.replace(/^.*\//, '').localeCompare(b.replace(/^.*\//, ''))); // match sorting in pg-migrator and knex's fs-migrations.js (by default: collect all files in all directories)
log();
log('All migrations:');
log();
Expand Down
2 changes: 1 addition & 1 deletion test/integration/other/knex-migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const populateUsers = require('../fixtures/01-users');
const { getFormFields } = require('../../../lib/data/schema');

const withTestDatabase = withKnex(config.get('test.database'));
const migrationsDir = appRoot + '/lib/model/migrations';
const migrationsDir = [appRoot + '/lib/model/migrations/archive', appRoot + '/lib/model/migrations'];
const upToMigration = (toName, inclusive = true) => withTestDatabase(async (migrator) => {
await migrator.raw('drop owned by current_user');
const migrations = await migrator.migrate.list({ directory: migrationsDir });
Expand Down
2 changes: 1 addition & 1 deletion test/integration/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const initialize = async () => {
await migrator.raw('drop owned by current_user');
// Silence logging from migrations.
console.log = noop; // eslint-disable-line no-console
await migrator.migrate.latest({ directory: appRoot + '/lib/model/migrations' });
await migrator.migrate.latest({ directory: [appRoot + '/lib/model/migrations/archive', appRoot + '/lib/model/migrations'] });
} finally {
console.log = log; // eslint-disable-line no-console
await migrator.destroy();
Expand Down