Skip to content

[backend] migrations/geoextract: relies on postgres to enforce execution order #1445

@alxndrsn

Description

@alxndrsn

This isn't actively a bug, but seems a likely place for future surprises:

It appears that there are issues with promise handling at https://github.com/getodk/central-backend/blob/f4e501de8ae35679ee5376a864649ca60a17462f/lib/model/migrations/20250927-01-geoextracts.js#L36-L41:

const up = async (db) => {
  getSqlFiles('up').forEach(async sql => {
    // See sidecar .sql files
    await db.raw(sql);
  });
};
  1. what order should the .sql files be executed in?
  2. should the migrator wait for this migration to complete before moving onto the next migration?

In fact, ordering is guaranteed because of a combination of knex & postgres behaviour.

Improvements

If ordering of individual migrations is not required, a possible code change to communicate this could be:

const up = async (db) => {
  await Promise.all([
    getSqlFiles('up').map(async sql => {
      // See sidecar .sql files
      await db.raw(sql);
    });
  ]);
};

If ordering of individual migrations is required, a possible code change to communicate this could be:

const up = async (db) => {
  for(const sql of getSqlFiles('up')) {
    // See sidecar .sql files
    await db.raw(sql);
  }
};

Metadata

Metadata

Assignees

Labels

backendRequires a change to the API serverrefactorImproves code without altering behavior

Type

No type

Projects

Status

✅ done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions