+from wizard import scripts, shell, sql, util
+
+def dsn_callback(options):
+ if not isinstance(options.dsn, sqlalchemy.engine.url.URL):
+ options.dsn = sqlalchemy.engine.url.make_url(options.dsn)
+ # do some guessing with sql
+ options.dsn = sql.fill_url(options.dsn)
+ # perform some sanity checks on the database
+ database = options.dsn.database
+ options.dsn.database = None
+ engine = sqlalchemy.create_engine(options.dsn)
+ # generates warnings http://groups.google.com/group/sqlalchemy/browse_thread/thread/b7123fefb7dd83d5
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ engine.execute("CREATE DATABASE IF NOT EXISTS `%s`" % database)
+ options.dsn.database = database
+ # XXX: another good thing to check might be that the database is empty