Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 298
Benjamin B. Avatar asked May 04 '15 18:05

Benjamin B.


1 Answers

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.

like image 195
Arne Claassen Avatar answered Sep 29 '22 13:09

Arne Claassen