node-flyway icon indicating copy to clipboard operation
node-flyway copied to clipboard

Expecting only one executable Flyway CLI to be found. Instead found multiple executable files: flyway.cmd,README.txt,flyway

Open kishaningithub opened this issue 2 years ago • 5 comments

My DB migration script failed with the following error

$ bun run ./migrate.ts

50 |             throw new Error(`Unable to find an executable Flyway CLI in target directory: ${directory}`);
51 |         }
52 |         if (executableFiles.length > 1) {
53 |             const executableFilesWithCorrectName = executableFiles.filter(file => file.name.includes("flyway"));
54 |             if (executableFilesWithCorrectName.length > 1) {
55 |                 throw new Error(`Expecting only one executable Flyway CLI to be found. Instead found multiple executable files: ${executableFiles.map(ex => ex.name)}`);
                           ^
error: Expecting only one executable Flyway CLI to be found. Instead found multiple executable files: flyway.cmd,README.txt,flyway
      at ./node_modules/node-flyway/dist/cli/service/flyway-cli-service.js:55:23
error: script "db:migrate" exited with code 1

Migration file

This migration file is just a copy paste of the example

import { Flyway } from "node-flyway";

const flyway = new Flyway(
    {
        url:"jdbc:postgresql://localhost:5432/postgres",
        user:"postgres",
        password:"password",
        defaultSchema: "public",
        migrationLocations: ["migrations"]
    }
);

flyway.migrate().then(response => {
    if(!response.success) {
        throw new Error(`Unable to execute migrate command. Error: ${response.error?.errorCode}`);
    }
    console.log(`Migrations are successful ${response}`);
});

kishaningithub avatar Feb 04 '24 16:02 kishaningithub

Hey @kishaningithub. Thanks for raising this. Which OS are you using?

domdinnes avatar Feb 08 '24 07:02 domdinnes

OS: Mac OS X (Mac book pro) Chip: M1 Architecture: Arm 64

kishaningithub avatar Feb 08 '24 07:02 kishaningithub

@domdinnes I'm also seeing this, on my M1 Mac.

error: Expecting only one executable Flyway CLI to be found. Instead found multiple executable files: flyway.cmd,README.txt,flyway
pwd
/Users/scottpierce/.node-flyway/flyway-9.0.0
ls -a 
.		conf		flyway.cmd	lib
..		drivers		jars		licenses
README.txt	flyway		jre		sql

ScottPierce avatar Sep 02 '24 04:09 ScottPierce

@kishaningithub and @ScottPierce I'm also on M1 Mac and able to reproduce when I set the executable bit on files in the ~/.node-flyway/flyway-9.0.0 dir.

E.g. failing with error

Error: Expecting only one executable Flyway CLI to be found. Instead found multiple executable files: flyway,flyway.cmd

ls -al
total 24
drwxr-xr-x  12 cadam  staff   384 Jul 17  2024 .
drwxr-xr-x   3 cadam  staff    96 Jul 17  2024 ..
-rw-r--r--   1 cadam  staff   700 Jul 13  2022 README.txt
drwxr-xr-x   3 cadam  staff    96 Jul 17  2024 conf
drwxr-xr-x  25 cadam  staff   800 Jul 17  2024 drivers
-rwxr--r--   1 cadam  staff  1662 Jul 13  2022 flyway
-rwxr-xr-x   1 cadam  staff  1504 Jul 13  2022 flyway.cmd
drwxr-xr-x   3 cadam  staff    96 Jul 17  2024 jars
drwxr-xr-x   8 cadam  staff   256 Jul 17  2024 jre
drwxr-xr-x   8 cadam  staff   256 Jul 17  2024 lib
drwxr-xr-x   5 cadam  staff   160 Jul 17  2024 licenses
drwxr-xr-x   3 cadam  staff    96 Jul 17  2024 sql

Note the x in -rwxr-xr-x 1 cadam staff 1504 Jul 13 2022 flyway.cmd.

Workaround

Resetting the flags on files in this dir so that only the flyway file is executable restores function.

chmod -x flyway.cmd
ls -al
total 24
drwxr-xr-x  12 cadam  staff   384 Jul 17  2024 .
drwxr-xr-x   3 cadam  staff    96 Jan 22 09:48 ..
-rw-r--r--   1 cadam  staff   700 Jul 13  2022 README.txt
drwxr-xr-x   3 cadam  staff    96 Jul 17  2024 conf
drwxr-xr-x  25 cadam  staff   800 Jul 17  2024 drivers
-rwxr--r--   1 cadam  staff  1662 Jul 13  2022 flyway
-rw-r--r--   1 cadam  staff  1504 Jul 13  2022 flyway.cmd
drwxr-xr-x   3 cadam  staff    96 Jul 17  2024 jars
drwxr-xr-x   8 cadam  staff   256 Jul 17  2024 jre
drwxr-xr-x   8 cadam  staff   256 Jul 17  2024 lib
drwxr-xr-x   5 cadam  staff   160 Jul 17  2024 licenses
drwxr-xr-x   3 cadam  staff    96 Jul 17  2024 sql

For your cases both the flyway.cmd and README.txt files need their modes changed to make them non-executable.

chmod -x flyway.cmd README.txt

Possible longer-term solution

@domdinnes The current logic that looks for executables doesn't look any deeper than the file modes, which may not always be the most reliable indicator of which file to use for running Flyway. One option could be to add a final step that uses mmmagic to look more closely at the file contents to filter out files that may be executable, but aren't appropriate for the os.

Note that I haven't actually proven this out yet, but I'd be happy to open a PR for this if desired.

cadam11 avatar Jan 22 '25 16:01 cadam11