<s> from contracts import contract <EOL> from neat . contracts_primitive import * <EOL> from neat . contracts_extra import * <EOL> from sqlalchemy import * <EOL> from sqlalchemy . sql import func <EOL> from neat . db import Database <EOL> import logging <EOL> log = logging . getLogger ( __name__ ) <EOL> @ contract <EOL> def init_db ( sql_connection ) : <EOL> """<STR_LIT>""" <EOL> engine = create_engine ( sql_connection ) <EOL> metadata = MetaData ( ) <EOL> metadata . bind = engine <EOL> hosts = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , String ( <NUM_LIT:255> ) , nullable = False ) , <EOL> Column ( '<STR_LIT>' , Integer , nullable = False ) , <EOL> Column ( '<STR_LIT>' , Integer , nullable = False ) , <EOL> Column ( '<STR_LIT>' , Integer , nullable = False ) ) <EOL> host_resource_usage = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) , <EOL> Column ( '<STR_LIT>' , DateTime , default = func . now ( ) ) , <EOL> Column ( '<STR_LIT>' , Integer , nullable = False ) ) <EOL> vms = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , String ( <NUM_LIT> ) , nullable = False ) ) <EOL> vm_resource_usage = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) , <EOL> Column ( '<STR_LIT>' , DateTime , default = func . now ( ) ) , <EOL> Column ( '<STR_LIT>' , Integer , nullable = False ) ) <EOL> vm_migrations = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) , <EOL> Column ( '<STR_LIT>' , DateTime , default = func . now ( ) ) ) <EOL> host_states = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) , <EOL> Column ( '<STR_LIT>' , DateTime , default = func . now ( ) ) , <EOL> Column ( '<STR_LIT:state>' , Integer , nullable = False ) ) <EOL> host_overload = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) , <EOL> Column ( '<STR_LIT>' , DateTime , default = func . now ( ) ) , <EOL> Column ( '<STR_LIT>' , Integer , nullable = False ) ) <EOL> metadata . create_all ( ) <EOL> connection = engine . connect ( ) <EOL> db = Database ( connection , hosts , host_resource_usage , vms , <EOL> vm_resource_usage , vm_migrations , host_states , host_overload ) <EOL> log . debug ( '<STR_LIT>' , sql_connection ) <EOL> return db </s>
