Benjamin
Benjamin

Reputation: 143

Check table existence in slick 3.0

How do you check if a table exists with slick 3.0?

There was a way in previous versions of slick by using:

MTable.getTables.list()

But this doesn't compile anymore.

The idea behind this question is to dynamically create a table when it doesn't exists, pretty much like this:

if (Tables.contains("USERS") == false)
    Users.createTable()

Upvotes: 14

Views: 4612

Answers (1)

Arne Claassen
Arne Claassen

Reputation: 14404

With Slick 3.0 MTable.getTables is a DBAction which was to be run via a Database instance:

val tables = Await.result(db.run(MTable.getTables), 1.seconds).toList

Of course, you should probable deal with the Future returned by db.run in an asynchronous manner (via map or for-comprehension) rather than blocking on it as I did for the example.

Upvotes: 18

Related Questions