@@ -46,31 +46,40 @@ migrateDev projectDir migrateArgs =
46
46
scriptArgs =
47
47
if System.Info. os == " darwin"
48
48
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
50
50
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,
59
61
" migrate" ,
60
62
" dev" ,
61
63
" --schema" ,
62
- SP. fromAbsFile schemaFile,
64
+ argQuoter $ SP. fromAbsFile schemaFile,
63
65
" --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.
64
68
" --skip-seed"
65
69
]
66
70
++ asPrismaCliArgs migrateArgs
67
71
72
+ quoteArg :: String -> String
73
+ quoteArg arg = " \" " ++ arg ++ " \" "
74
+
68
75
asPrismaCliArgs :: MigrateArgs -> [String ]
69
76
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 =
72
82
[[" --name" , name] | Just name <- [_migrationName migrateArgs]]
73
- ]
74
83
75
84
-- | Diffs the Prisma schema file against the db.
76
85
-- Because of the --exit-code flag, it changes the exit code behavior
0 commit comments