From 225a03be7e1ad49507157d781f6e52316dc12894 Mon Sep 17 00:00:00 2001 From: Marius Baron Date: Tue, 3 Mar 2020 16:08:11 +0100 Subject: [PATCH] fix: read only js files from migration directory --- package.json | 1 + src/utils.js | 5 +++-- test/__fixtures__/migrations/foo.sql | 0 test/utils.test.js | 2 +- yarn.lock | 18 ++++++++++++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 test/__fixtures__/migrations/foo.sql diff --git a/package.json b/package.json index b618fe3..0ae3457 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "mkdirp": "^0.5.1", "mz": "^2.7.0", "tildify": "^2.0.0", + "tiny-glob": "^0.2.6", "v8flags": "^3.1.3" }, "devDependencies": { diff --git a/src/utils.js b/src/utils.js index 5b24503..bba5dd6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,8 +1,9 @@ -import { readFile, readdir, exists } from 'mz/fs' +import { readFile, exists } from 'mz/fs' +import glob from 'tiny-glob' export async function getInsertsFromMigrations(migrationsPath) { if (!(await exists(migrationsPath))) return [] - const migrations = await readdir(migrationsPath) + const migrations = await glob('*.js', { cwd: migrationsPath }) return migrations.map( migration => `INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('${migration}', 1, NOW());`, diff --git a/test/__fixtures__/migrations/foo.sql b/test/__fixtures__/migrations/foo.sql new file mode 100644 index 0000000..e69de29 diff --git a/test/utils.test.js b/test/utils.test.js index 622045a..c51b506 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -9,7 +9,7 @@ describe('#getInsertsFromMigrations', () => { expect(inserts).toEqual([]) }) - it('should read migrations from folder', async () => { + it('should read migrations from folder (ignore other than js files)', async () => { const inserts = await getInsertsFromMigrations( path.join(__dirname, '__fixtures__/migrations'), ) diff --git a/yarn.lock b/yarn.lock index cae648f..8ca0752 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2736,6 +2736,16 @@ globals@^11.1.0, globals@^11.7.0: resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== +globalyzer@^0.1.0: + version "0.1.4" + resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.4.tgz#bc8e273afe1ac7c24eea8def5b802340c5cc534f" + integrity sha512-LeguVWaxgHN0MNbWC6YljNMzHkrCny9fzjmEUdnF1kQ7wATFD1RHFRqA1qxaX2tgxGENlcxjOflopBwj3YZiXA== + +globrex@^0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/globrex/-/globrex-0.1.2.tgz#dd5d9ec826232730cd6793a5e33a9302985e6098" + integrity sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg== + got@^8.0.0: version "8.3.2" resolved "https://registry.yarnpkg.com/got/-/got-8.3.2.tgz#1d23f64390e97f776cac52e5b936e5f514d2e937" @@ -5886,6 +5896,14 @@ timed-out@^4.0.1: resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f" integrity sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8= +tiny-glob@^0.2.6: + version "0.2.6" + resolved "https://registry.yarnpkg.com/tiny-glob/-/tiny-glob-0.2.6.tgz#9e056e169d9788fe8a734dfa1ff02e9b92ed7eda" + integrity sha512-A7ewMqPu1B5PWwC3m7KVgAu96Ch5LA0w4SnEN/LbDREj/gAD0nPWboRbn8YoP9ISZXqeNAlMvKSKoEuhcfK3Pw== + dependencies: + globalyzer "^0.1.0" + globrex "^0.1.1" + tmp@^0.0.33: version "0.0.33" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"