Open nhanders opened 5 days ago
Good catch -- I think validation makes sense, especially that running only this migration will seem like it works, and it only breaks when combined with other statements. I'll look into it.
@nhanders Fixed in https://github.com/Nozbe/WatermelonDB/pull/1812
We were experiencing a crash on app startup on a new app release which we hadn't picked up in testing. Upon inspecting the logs, the issue was found to be a syntax error in the generated migrations SQL.
What had caused this SQL error was not terminating the SQL provided to the
unsafeExecuteSql
with a semicolon. This meant that, when the migration was generated, the SQL statement had theunsafeExecuteSql
migration step not terminated with a semicolon, causing a syntax error.Here's an example:
When running migrations from v1 -> v2 or v2-v3, there are no issues since the generate migration SQL statement are just:
This is why we never picked this up in our testing.
However, when running migrations from v1 -> v3, a syntax error is thrown since the generated SQL is missing the termination semicolon in the first statement:
(not exactly what is generated, but it's the gist)
I'm creating this issue for two reasons:
I know the method used is rightfully named
unsafeExecuteSql
, but I still think programmers could be protected from this issue. Two simple ideas come to mind:unsafeExecuteSql
to ensure it ends in a semicolon. Nice and simple.I'm happy to implement them, just looking if anyone out there has any feedback or better solutions.