4

I'm creating a web app with Clojure and Luminus, but when I create a migration file with all the tables I need, it will only create the first. This is my user-table.up.sql file:

CREATE TABLE UserTable (
   id INTEGER PRIMARY KEY AUTOINCREMENT,
   first_name VARCHAR(50),
   last_name VARCHAR(50),
   gender VARCHAR(50),
   email VARCHAR(50) UNIQUE,
   password VARCHAR(400),
   time_stamp TIMESTAMP,
   is_active BOOLEAN
);

CREATE TABLE LoginTable (
   id INTEGER PRIMARY KEY AUTOINCREMENT,
   user_id INTEGER,
   time_stamp TIMESTAMP
);

When I run lein run migrate, only the table UserTable is created. Is this supposed to work like this? Do I need to create a migration file for each table?

Vasco Ferreira
  • 2,151
  • 2
  • 15
  • 21

2 Answers2

5

As you are using Luminus, you are probably using Migratus. If you want to execute multiple statements in one sql file, read this:

https://github.com/yogthos/migratus#multiple-statements

Michiel Borkent
  • 34,228
  • 15
  • 86
  • 149
2

Just to let Michiel answer here according your case, to run multiple statements in your migration, separate them with --;; in your case:

CREATE TABLE UserTable (
   id INTEGER PRIMARY KEY AUTOINCREMENT,
   first_name VARCHAR(50),
   last_name VARCHAR(50),
   gender VARCHAR(50),
   email VARCHAR(50) UNIQUE,
   password VARCHAR(400),
   time_stamp TIMESTAMP,
   is_active BOOLEAN
);
--;;
CREATE TABLE LoginTable (
   id INTEGER PRIMARY KEY AUTOINCREMENT,
   user_id INTEGER,
   time_stamp TIMESTAMP
);
Paulo Victor
  • 3,814
  • 2
  • 26
  • 29