Open straight-shoota opened 4 months ago
Hello @straight-shoota, thanks for reporting this.
Since I'm not relying on user-defined functions/procedures (like PostgreSQL), I haven't invested any thought on this beyond the "this could happen" scenario 😅
A quick workaround I thought about this was to use a marker to indicate that the migration contains commas and needs to avoid splitting them at that marker.
I will keep this open for the time being, but not sure how I will tackle it, so open to suggestions.
Cheers.
Migration.from_io
detects a trailing semicolon as the end of an SQL statement.This can cause problems with queries with a trailing semicolon inside. This can be perfectly valid in multiple situations, such as inside a string literal.
For example, the following migration leads to an error.
Unfortunately, I don't think there's a simple solution to fix this. You would either need to parse the SQL syntax to understand where there's truely a statement end. Or, even better, we should be able to run all statements at once. This is currently only implemented as a custom extension in the postgres driver AFAIK. There's a tracking issue for
crystal-db
: https://github.com/crystal-lang/crystal-db/issues/113Maybe a good start would be to mention this trap in the documentation.