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

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

async = require 'async'
dashdash = require 'dashdash'


createDatabase = (arg, callback) ->
	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 = []
	funcs.push((callback) -> create config.MYSQL_DATABASE_URL, callback) if arg is 'main' or arg is 'both'
	funcs.push((callback) -> create config.MYSQL_DATABASE_URL_TEST, callback) if arg is 'test' or arg is 'both'
	
	async.parallel funcs, callback


dropDatabase = (arg, callback) ->
	checkArgs opts.drop_database, ['main', 'test', 'both']
	
	drop = (db_url, callback) ->
		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) ->
			if error?
				if error.code != 'ER_DB_DROP_EXISTS'
					callback error
					return
				console.log "#{db_name} already dropped."
			else
				console.log "#{db_name} dropped."
			callback null
	
	funcs = []
	funcs.push((callback) -> drop config.MYSQL_DATABASE_URL, callback) if arg is 'main' or arg is 'both'
	funcs.push((callback) -> drop config.MYSQL_DATABASE_URL_TEST, callback) if arg is 'test' or arg is 'both'
	
	async.parallel funcs, callback


migrateTables = (callback) ->
	mysqlConnection = anyDB.createConnection(config.MYSQL_DATABASE_URL)
	utils.migration.migrate mysqlConnection, callback


options = [
	names: [
		'help'
