mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #18186 from overleaf/em-migration-dependencies
Add a migration helper checking dependent migrations GitOrigin-RevId: 96aa6238b20115206554faaa4c2aefc537bbe7e8
This commit is contained in:
parent
4c49841637
commit
65f20a4d56
2 changed files with 24 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
const {
|
const {
|
||||||
db,
|
db,
|
||||||
getCollectionNames,
|
getCollectionNames,
|
||||||
|
@ -42,8 +44,25 @@ async function dropCollection(collectionName) {
|
||||||
await collection.drop()
|
await collection.drop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that a dependent migration has run. Throws an error otherwise.
|
||||||
|
*
|
||||||
|
* @param {string} migrationName
|
||||||
|
*/
|
||||||
|
async function assertDependency(migrationName) {
|
||||||
|
await waitForDb()
|
||||||
|
const migrations = await getCollectionInternal('migrations')
|
||||||
|
const migration = await migrations.findOne({ name: migrationName })
|
||||||
|
if (migration == null) {
|
||||||
|
throw new Error(
|
||||||
|
`Bad migration order: ${migrationName} should run before this migration`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addIndexesToCollection,
|
addIndexesToCollection,
|
||||||
dropIndexesFromCollection,
|
dropIndexesFromCollection,
|
||||||
dropCollection,
|
dropCollection,
|
||||||
|
assertDependency,
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,11 @@ exports.tags = ['server-ce', 'server-pro', 'saas']
|
||||||
|
|
||||||
exports.migrate = async client => {
|
exports.migrate = async client => {
|
||||||
const { db } = client
|
const { db } = client
|
||||||
|
// Are there migrations that need to run before this migration?
|
||||||
|
// Use the following helper to enforce the dependency:
|
||||||
|
//
|
||||||
|
// await Helpers.assertDependency('20200101000000_another_migration')
|
||||||
|
|
||||||
// await Helpers.addIndexesToCollection(db.wombats, [{ name: 1 }])
|
// await Helpers.addIndexesToCollection(db.wombats, [{ name: 1 }])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue