Schema.create, table already exists error

2,883 views
Skip to first unread message

Chka

unread,
Feb 8, 2012, 11:54:52 AM2/8/12
to Squeryl
Hi,

I have a problem with Schema.create. Everytime I run my program,
Schema.create is saying 'org.h2.jdbc.JdbcSQLException: Table
"TABLE_NAME" already exists; SQL statement:'.

Why does it happen? Does Schema.create check if tables already exist
in DB?

Here is the code:
SessionFactory.concreteFactory = Some(() =>
Session.create(DriverManager.getConnection(url, user, password),
adapter))
try {
transaction {
Session.currentSession.setLogger(println(_))
LookupTables.create
}
} catch { case e => println("Can't create Schemas : " +
e.toString) }

Thanks,
Chka

Maxime Lévesque

unread,
Feb 8, 2012, 12:34:11 PM2/8/12
to squ...@googlegroups.com

Schema.create  doesn't check for existing tables...

2012/2/8 Chka <chi...@gmail.com>

Chka

unread,
Feb 8, 2012, 12:56:33 PM2/8/12
to Squeryl
Thank you for replying.

So, what is the good way to check if table already exists?

Do you have any suggestion?

On Feb 8, 11:34 am, Maxime Lévesque <maxime.leves...@gmail.com> wrote:
> Schema.create  doesn't check for existing tables...
>
> 2012/2/8 Chka <chii...@gmail.com>

Maxime Lévesque

unread,
Feb 8, 2012, 2:09:12 PM2/8/12
to squ...@googlegroups.com

There aren't really other ways then to use straight JDBC for this.

2012/2/8 Chka <chi...@gmail.com>

Bayarmunkh Davaadorj

unread,
Feb 8, 2012, 2:55:31 PM2/8/12
to squ...@googlegroups.com
Ok. So, I may be doing wrong.

How do you create schemes?

Every example I have seen creates schema like this: 
 transaction {
    mySchema.create
 }

But, I wonder, how do their program run without the exception that says 'Table Already Exists'?

Or the schema creating is supposed to be ran only one time?

I also wonder, how to alter existing tables? What if I add a column or change the data type of a column?

Thanks,
Chka

2012/2/8 Maxime Lévesque <maxime....@gmail.com>



--
Regards,
Bayarmunkh
chi...@gmail.com

Cell Phone: 515/779-6183

Julian Backes

unread,
Feb 8, 2012, 4:03:38 PM2/8/12
to squ...@googlegroups.com
As far as i know, create() only creates the whole schema. squeryl does not support incremental schema updates.
Please correct me if I'm wrong :-)

2012/2/8 Bayarmunkh Davaadorj <chi...@gmail.com>

David Whittaker

unread,
Feb 8, 2012, 4:08:48 PM2/8/12
to squ...@googlegroups.com
That's correct.  At the moment, incremental updates need to be done by hand.  Schema.printDdl can be useful for outputting your current schema which you can then copy and paste from.

Maxime Lévesque

unread,
Feb 8, 2012, 4:10:01 PM2/8/12
to squ...@googlegroups.com

That is correct, schema.create is meant to be used early in development, not on prod databases,
in real life (in prod), one needs a strategy for schema evolution, it's something 
that Squeryl does not address.

Before going in production, a good idea is to dump the schema with  Schema.printDdl(println(_)),
put it in source control, and evolve things manually from there (or by using specialized tools).

ML

2012/2/8 Julian Backes <julian...@gmail.com>

Artie Pesh-Imam

unread,
Feb 8, 2012, 4:06:48 PM2/8/12
to squ...@googlegroups.com
We're using dbdeploy to do incremental schema updates. Another good tool out there is autopatch.


Both these tools require you to write your own patches to update the schema and then also exec the scripts through mvn or some other tool.




Sent with Sparrow

David Whittaker

unread,
Feb 8, 2012, 4:40:03 PM2/8/12
to squ...@googlegroups.com
Liquibase also seems to be fairly popular: (http://www.liquibase.org/) and when I was looking into options for Iradix I thought scala-migrations (http://code.google.com/p/scala-migrations/) seemed like a kind of interesting idea.  Flyway (http://code.google.com/p/flyway/) is another one.  I think one of the reasons this hasn't been integrated with Squeryl yet is that there are so many existing methods.
Reply all
Reply to author
Forward
0 new messages