Skip to content

Commit 225a03b

Browse files
committed
fix: read only js files from migration directory
1 parent 96f13b5 commit 225a03b

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"mkdirp": "^0.5.1",
2626
"mz": "^2.7.0",
2727
"tildify": "^2.0.0",
28+
"tiny-glob": "^0.2.6",
2829
"v8flags": "^3.1.3"
2930
},
3031
"devDependencies": {

src/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { readFile, readdir, exists } from 'mz/fs'
1+
import { readFile, exists } from 'mz/fs'
2+
import glob from 'tiny-glob'
23

34
export async function getInsertsFromMigrations(migrationsPath) {
45
if (!(await exists(migrationsPath))) return []
5-
const migrations = await readdir(migrationsPath)
6+
const migrations = await glob('*.js', { cwd: migrationsPath })
67
return migrations.map(
78
migration =>
89
`INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('${migration}', 1, NOW());`,

test/__fixtures__/migrations/foo.sql

Whitespace-only changes.

test/utils.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('#getInsertsFromMigrations', () => {
99
expect(inserts).toEqual([])
1010
})
1111

12-
it('should read migrations from folder', async () => {
12+
it('should read migrations from folder (ignore other than js files)', async () => {
1313
const inserts = await getInsertsFromMigrations(
1414
path.join(__dirname, '__fixtures__/migrations'),
1515
)

yarn.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,6 +2736,16 @@ globals@^11.1.0, globals@^11.7.0:
27362736
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
27372737
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==
27382738

2739+
globalyzer@^0.1.0:
2740+
version "0.1.4"
2741+
resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.4.tgz#bc8e273afe1ac7c24eea8def5b802340c5cc534f"
2742+
integrity sha512-LeguVWaxgHN0MNbWC6YljNMzHkrCny9fzjmEUdnF1kQ7wATFD1RHFRqA1qxaX2tgxGENlcxjOflopBwj3YZiXA==
2743+
2744+
globrex@^0.1.1:
2745+
version "0.1.2"
2746+
resolved "https://registry.yarnpkg.com/globrex/-/globrex-0.1.2.tgz#dd5d9ec826232730cd6793a5e33a9302985e6098"
2747+
integrity sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==
2748+
27392749
got@^8.0.0:
27402750
version "8.3.2"
27412751
resolved "https://registry.yarnpkg.com/got/-/got-8.3.2.tgz#1d23f64390e97f776cac52e5b936e5f514d2e937"
@@ -5886,6 +5896,14 @@ timed-out@^4.0.1:
58865896
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"
58875897
integrity sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=
58885898

5899+
tiny-glob@^0.2.6:
5900+
version "0.2.6"
5901+
resolved "https://registry.yarnpkg.com/tiny-glob/-/tiny-glob-0.2.6.tgz#9e056e169d9788fe8a734dfa1ff02e9b92ed7eda"
5902+
integrity sha512-A7ewMqPu1B5PWwC3m7KVgAu96Ch5LA0w4SnEN/LbDREj/gAD0nPWboRbn8YoP9ISZXqeNAlMvKSKoEuhcfK3Pw==
5903+
dependencies:
5904+
globalyzer "^0.1.0"
5905+
globrex "^0.1.1"
5906+
58895907
tmp@^0.0.33:
58905908
version "0.0.33"
58915909
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"

0 commit comments

Comments
 (0)