Skip to content
James Reeves edited this page Jun 25, 2015 · 15 revisions

SQL migrations can be written in two ways.

edn

The first way is to create a .edn file that contains a map that has :up and :down keys. Both keys should contain an ordered collection of SQL statements.

For example, we might create a file resources/migrations/001-create-foo.edn:

{:up   ["CREATE TABLE foo (name VARCHAR(100))"
        "INSERT INTO foo VALUES ('alice'), ('bob')"]
 :down ["DROP TABLE "foo"]}

SQL

Alternatively, we can write the SQL directly. The "up" part of the migration will go into a file resources/migrations/001-create-foo.up.sql:

CREATE TABLE foo (name VARCHAR(100));
INSERT INTO foo VALUES ('alice'), ('bob');

And the "down" part of the migration will go in resources/migrations/001-create-foo.down.sql:

DROP TABLE foo;

Ragtime uses the extension (.up.sql or .down.sql) to determine whether the file represents the "up" or "down" part of the migration.

Clone this wiki locally