Escape Prisma command when running with script on Linux (#1561)

This commit is contained in:
Mihovil Ilakovac 2023-11-14 13:32:15 +01:00 committed by GitHub
parent 39620ee6b1
commit 4db82bf815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,31 +46,40 @@ migrateDev projectDir migrateArgs =
scriptArgs = scriptArgs =
if System.Info.os == "darwin" if System.Info.os == "darwin"
then -- NOTE(martin): On MacOS, command that `script` should execute is treated as multiple arguments. then -- NOTE(martin): On MacOS, command that `script` should execute is treated as multiple arguments.
["-Fq", "/dev/null"] ++ prismaMigrateCmd ["-Fq", "/dev/null"] ++ buildPrismaMigrateCmd id
else -- NOTE(martin): On Linux, command that `script` should execute is treated as one argument. else -- NOTE(martin): On Linux, command that `script` should execute is treated as one argument.
["-feqc", unwords prismaMigrateCmd, "/dev/null"] ["-feqc", unwords $ buildPrismaMigrateCmd quoteArg, "/dev/null"]
-- NOTE(martin): For this to work on Mac, filepath in the list below must be as it is now - not -- NOTE(miho): Since we are running the Prisma command using `script` and we are doing it
-- wrapped in any quotes. -- in two different ways (MacOS and Linux), we have to take care of quoting the paths
-- NOTE(martin): We do "--skip-seed" here because I just think seeding happening automatically -- differently.
-- in some situations is too aggressive / confusing. -- * MacOS - we are passing the command as multiple arguments, so we MUST NOT quote the paths.
prismaMigrateCmd = -- * Linux - we are passing the command as one argument, so we MUST quote the paths.
[ absPrismaExecutableFp projectDir, buildPrismaMigrateCmd :: (String -> String) -> [String]
buildPrismaMigrateCmd argQuoter =
[ argQuoter $ absPrismaExecutableFp projectDir,
"migrate", "migrate",
"dev", "dev",
"--schema", "--schema",
SP.fromAbsFile schemaFile, argQuoter $ SP.fromAbsFile schemaFile,
"--skip-generate", "--skip-generate",
-- NOTE(martin): We do "--skip-seed" here because I just think seeding happening automatically
-- in some situations is too aggressive / confusing.
"--skip-seed" "--skip-seed"
] ]
++ asPrismaCliArgs migrateArgs ++ asPrismaCliArgs migrateArgs
quoteArg :: String -> String
quoteArg arg = "\"" ++ arg ++ "\""
asPrismaCliArgs :: MigrateArgs -> [String] asPrismaCliArgs :: MigrateArgs -> [String]
asPrismaCliArgs migrateArgs = do asPrismaCliArgs migrateArgs = do
concat . concat $ concat . concat $ [createOnlyArg, nameArg]
[ [["--create-only"] | _isCreateOnlyMigration migrateArgs], where
createOnlyArg =
[["--create-only"] | _isCreateOnlyMigration migrateArgs]
nameArg =
[["--name", name] | Just name <- [_migrationName migrateArgs]] [["--name", name] | Just name <- [_migrationName migrateArgs]]
]
-- | Diffs the Prisma schema file against the db. -- | Diffs the Prisma schema file against the db.
-- Because of the --exit-code flag, it changes the exit code behavior -- Because of the --exit-code flag, it changes the exit code behavior