Skip to content

Commit 4db82bf

Browse files
authored
Escape Prisma command when running with script on Linux (#1561)
1 parent 39620ee commit 4db82bf

File tree

1 file changed

+22
-13
lines changed
  • waspc/src/Wasp/Generator/DbGenerator

1 file changed

+22
-13
lines changed

waspc/src/Wasp/Generator/DbGenerator/Jobs.hs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,40 @@ migrateDev projectDir migrateArgs =
4646
scriptArgs =
4747
if System.Info.os == "darwin"
4848
then -- NOTE(martin): On MacOS, command that `script` should execute is treated as multiple arguments.
49-
["-Fq", "/dev/null"] ++ prismaMigrateCmd
49+
["-Fq", "/dev/null"] ++ buildPrismaMigrateCmd id
5050
else -- NOTE(martin): On Linux, command that `script` should execute is treated as one argument.
51-
["-feqc", unwords prismaMigrateCmd, "/dev/null"]
52-
53-
-- NOTE(martin): For this to work on Mac, filepath in the list below must be as it is now - not
54-
-- wrapped in any quotes.
55-
-- NOTE(martin): We do "--skip-seed" here because I just think seeding happening automatically
56-
-- in some situations is too aggressive / confusing.
57-
prismaMigrateCmd =
58-
[ absPrismaExecutableFp projectDir,
51+
["-feqc", unwords $ buildPrismaMigrateCmd quoteArg, "/dev/null"]
52+
53+
-- NOTE(miho): Since we are running the Prisma command using `script` and we are doing it
54+
-- in two different ways (MacOS and Linux), we have to take care of quoting the paths
55+
-- differently.
56+
-- * MacOS - we are passing the command as multiple arguments, so we MUST NOT quote the paths.
57+
-- * Linux - we are passing the command as one argument, so we MUST quote the paths.
58+
buildPrismaMigrateCmd :: (String -> String) -> [String]
59+
buildPrismaMigrateCmd argQuoter =
60+
[ argQuoter $ absPrismaExecutableFp projectDir,
5961
"migrate",
6062
"dev",
6163
"--schema",
62-
SP.fromAbsFile schemaFile,
64+
argQuoter $ SP.fromAbsFile schemaFile,
6365
"--skip-generate",
66+
-- NOTE(martin): We do "--skip-seed" here because I just think seeding happening automatically
67+
-- in some situations is too aggressive / confusing.
6468
"--skip-seed"
6569
]
6670
++ asPrismaCliArgs migrateArgs
6771

72+
quoteArg :: String -> String
73+
quoteArg arg = "\"" ++ arg ++ "\""
74+
6875
asPrismaCliArgs :: MigrateArgs -> [String]
6976
asPrismaCliArgs migrateArgs = do
70-
concat . concat $
71-
[ [["--create-only"] | _isCreateOnlyMigration migrateArgs],
77+
concat . concat $ [createOnlyArg, nameArg]
78+
where
79+
createOnlyArg =
80+
[["--create-only"] | _isCreateOnlyMigration migrateArgs]
81+
nameArg =
7282
[["--name", name] | Just name <- [_migrationName migrateArgs]]
73-
]
7483

7584
-- | Diffs the Prisma schema file against the db.
7685
-- Because of the --exit-code flag, it changes the exit code behavior

0 commit comments

Comments
 (0)