Project

General

Profile

Actions

Feature #6377

open

Wt::Dbo::createTables if table already exists

Added by Emeric Poupon almost 6 years ago. Updated almost 6 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
05/19/2018
Due date:
% Done:

0%

Estimated time:

Description

Hello,

I think it may be safer to use "CREATE TABLE IF NOT EXISTS" when calling Wt::Dbo::Session::createTables().

Or maybe add a boolean for this?

It would be easier to automatically add the new tables in the schema.

What do you think?

Actions #1

Updated by Wim Dumon almost 6 years ago

  • Status changed from New to Feedback

Hey Emeric,

Wt::Dbo doesn't support DB migration, and our strategy to cope with that is quite naive: try to create the schema and throw an exception if it fails.

createTables() throwing exceptions in its 'normal' use case (i.e. the database exists and is correct) is a bit weird, and atypical for how Wt handles exceptions. There's no portable syntax that I know of to test if a table exists before creating it, and also 'create tables if not exist' is not portable across sql servers. Ideally, I think createTables should do nothing if the database is not completely empty, but again I'm not sure if we can easily test for that.

With respect to adding new tables: Session has a method tableCreationSql(). You could e.g. save the output of this call to a file on startup, so that you can copy-paste the relevant fragments to the database. More often than not, DB migration will involve more than only the creation of a new table, so manual intervention will be required.

Best regards,

Wim.

Actions

Also available in: Atom PDF