 	]
 	type: 'string'
 	help: 'Create database: "main", "test" or "both".'
+	action: createDatabase
 ,
 	names: [
 		'drop-database'

#	create config.MYSQL_DATABASE_URL if opts.create_database is 'main' or opts.create_database is 'both'
#	create config.MYSQL_DATABASE_URL_TEST if opts.create_database is 'test' or opts.create_database is 'both'

if opts.create_database?
	checkArgs opts.create_database, ['main', 'test', 'both']
	
	create = (db_url, callback) ->
		db_path = db_url.match(/.+\//)[0]
		db_name = db_url.match(/[^\/]+$/)[0]
		conn = anyDB.createConnection(db_path)
		conn.query 'CREATE DATABASE ' + db_name, [], (error, result) ->
			if error?
				if error.code != 'ER_DB_CREATE_EXISTS'
					callback error
					return
				console.log "#{db_name} already exists."
			else
				console.log "#{db_name} created."
			callback null
	
	funcs = []
	if opts.create_database is 'main' or opts.create_database is 'both'
		funcs.push((callback) -> create config.MYSQL_DATABASE_URL, callback)
	if opts.create_database is 'test' or opts.create_database is 'both'
		funcs.push((callback) -> create config.MYSQL_DATABASE_URL_TEST, callback)
	
	async.parallel funcs,
		(error, result) ->
			checkError error
			process.exit 0


if opts.drop_database?
	checkArgs opts.drop_database, ['main', 'test', 'both']
	
	func_count = 0
	drop = (db_url) ->
		func_count++
		db_path = db_url.match(/.+\//)[0]
		db_name = db_url.match(/[^\/]+$/)[0]
		conn = anyDB.createConnection(db_path)
		conn.query 'DROP DATABASE ' + db_name, [], (error, result) ->
			func_count--
			checkError error, func_count isnt 0
			console.log "#{db_name} dropped."
			process.exit 0 if func_count is 0
	drop config.MYSQL_DATABASE_URL if opts.drop_database is 'main' or opts.drop_database is 'both'
	drop config.MYSQL_DATABASE_URL_TEST if opts.drop_database is 'test' or opts.drop_database is 'both'

if opts.migrate_tables is true
	mysqlConnection = anyDB.createConnection(config.MYSQL_DATABASE_URL)
	utils.migration.migrate mysqlConnection, (error) ->
		checkError error
		process.exit 0

	]
	type: 'string'
	help: 'Drop database: "main", "test" or "both".'
	action: dropDatabase
,
	names: [
		'migrate-tables'
