weavejester / ragtime

Database-independent migration library
Eclipse Public License 1.0
610 stars 85 forks source link

Support parameterized statements in SQL migrations #115

Open dryewo opened 7 years ago

dryewo commented 7 years ago

Currently, :up and :down migrations are vectors of strings. Each string is then wrapped in a vector and given to jdbc/execute! However, jdbc/execute! expects a vector in the format:

["SOME STUFF(?, ?)" "foo" 42]

? are placeholders, where the "foo" and 42 are substituted in a safe way.

Currently there is no possibility to make use of it when defining migrations in EDN.

Would be nice to be able to do something like:

{:up ["CREATE TABLE foo (id int)"
      ["INSERT INTO foo(id) VALUES(?)" 1]]
 :down ["DROP TABLE foo"]}

For example, I needed this when I was generating migrations dynamically, inserting some user-defined value into the table.

This patch enables the described functionality.

weavejester commented 7 years ago

Let me consider this. There might be a better way of achieving the same result.

Also, can you fix the commit message and make sure it's capitalised? So something like:

Add support for parameters to SQL migrations

Since SQL migrations are not necessarily loaded from edn files, I don't think that part of your commit message makes sense.

dryewo commented 7 years ago

Done.

Another way might be using:

(if (sequential? s) s [s])

But I don't see any pros/cons.

dryewo commented 7 years ago

Oh, actually, there is an issue about this already: #112