Skip to content

Commit

Permalink
fix(versions): sort migration versions by ascending order when loadin…
Browse files Browse the repository at this point in the history
…g from filesystem

Closes #70
  • Loading branch information
TimMikeladze committed Aug 31, 2022
1 parent 8209c26 commit 4d5e15b
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 1 deletion.
35 changes: 35 additions & 0 deletions __tests__/ArangoMigrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,3 +583,38 @@ describe('readme migration', () => {
expect(edge._to).toEqual('todo/1')
})
})

describe('applies more than 10 migrations in the correct oder', () => {
let tu: TestUtil

beforeAll(async () => {
tu = await createTestUtil({
...defaultConfig,
migrationsPath: './__tests__/migrations_more_than_ten'
})
await tu.context.am.initialize()
})
afterAll(async () => {
await tu.destroy()
})
it('gets migration versions from paths in ascending order', async () => {
const getVersionsFromMigrationPaths = tu.context.am.getVersionsFromMigrationPaths()
expect(getVersionsFromMigrationPaths).toEqual([
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11
])
})
it('runs migrations', async () => {
await tu.context.am.runUpMigrations()
expect(await tu.context.am.getMigrationHistory()).toHaveLength(11)
})
})
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/10_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/11_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/1_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/2_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/3_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/4_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/5_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/6_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/7_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/8_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
11 changes: 11 additions & 0 deletions __tests__/migrations_more_than_ten/9_succeeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const migration = {
async collections () {
return ['todo']
},
async up (db, step) {
await step(() => db.collection('todo').save({
title: Math.random().toString()
}))
}
}
export default migration
2 changes: 1 addition & 1 deletion src/ArangoMigrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export class ArangoMigrate {
public getVersionsFromMigrationPaths (): number[] {
return this.migrationPaths.map(migrationPath => {
return Number(path.basename(migrationPath).split('_')[0])
})
}).sort((a, b) => a - b)
}

public validateMigrationFolderNotEmpty () {
Expand Down

0 comments on commit 4d5e15b

Please sign in to comment.