<s> import sentry . models <EOL> from sentry . db import models <EOL> from sqlalchemy import Table , Column , Integer , Float , String , Text , DateTime , MetaData <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> column_map = { <EOL> models . String : lambda x : String ( <NUM_LIT:255> , default = x . default , nullable = True ) , <EOL> models . Text : lambda x : Text ( default = x . default , nullable = True ) , <EOL> models . Integer : lambda x : Integer ( default = x . default , nullable = True ) , <EOL> models . Float : lambda x : Float ( default = x . default , nullable = True ) , <EOL> models . DateTime : lambda x : DateTime ( default = x . default , nullable = True ) , <EOL> models . List : lambda x : Text ( default = x . default , nullable = True ) , <EOL> } <EOL> model_map = { } <EOL> model_meta = { } <EOL> def create_sqlalchemy_def ( metadata , model ) : <EOL> columns = [ <EOL> Column ( '<STR_LIT:id>' , String ( <NUM_LIT:32> ) , primary_key = True ) , <EOL> ] <EOL> for name , field in model . _meta . fields : <EOL> columns . append ( Column ( name , column_map [ field ] ( field ) , nullable = True ) ) <EOL> table = Table ( model . __name__ . lower ( ) , metadata , * columns ) <EOL> return table <EOL> def create_sqlalchemy_metadata_def ( metadata , model ) : <EOL> columns = [ <EOL> Column ( '<STR_LIT:id>' , String ( <NUM_LIT:32> ) , primary_key = True ) , <EOL> Column ( '<STR_LIT:key>' , String ( <NUM_LIT:255> ) , primary_key = True ) , <EOL> Column ( '<STR_LIT:value>' , Text ( nullable = True ) , primary_key = True ) , <EOL> ] <EOL> table = Table ( '<STR_LIT>' % ( model . __name__ . lower ( ) , ) , metadata , * columns ) <EOL> return table <EOL> metadata = MetaData ( ) <EOL> for var in dir ( sentry . models ) : <EOL> if isinstance ( var , models . Model ) : <EOL> model_map [ var ] = create_sqlalchemy_def ( metadata , var ) <EOL> model_meta [ var ] = create_sqlalchemy_metadata_def ( metadata , var ) </s>
