#NEWLINE# @ app . command ( ) #NEWLINE# def create( name , dependencies = ( 'd' , [ ] , 'migration dependencies' ) , prefix_date = ( 'p' , False , 'prefix migration name with date' ) , **opts ) : #NEWLINE# #INDENT# 'Create new migration\n    ' #NEWLINE# repo = opts [ 'repo' ] #NEWLINE# deps = map ( repo . get , dependencies ) #NEWLINE# if prefix_date : #NEWLINE# #INDENT# name = ( date . today ( ) . strftime ( '%Y%m%d-' ) + name ) #NEWLINE# #UNINDENT# path = op . join ( repo . path , name ) #NEWLINE# try : #NEWLINE# #INDENT# os . mkdir ( path ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# if ( e . errno == 17 ) : #NEWLINE# #INDENT# abort ( ( 'directory %s already exists' % path ) ) #NEWLINE# #UNINDENT# raise #NEWLINE# #UNINDENT# with open ( op . join ( path , 'migration.ini' ) , 'w' ) as f : #NEWLINE# #INDENT# f . write ( '[nomad]\n' ) #NEWLINE# f . write ( ( 'dependencies = %s\n' % ', ' . join ( ( d . name for d in deps ) ) ) ) #NEWLINE# #UNINDENT# with open ( op . join ( path , 'up.sql' ) , 'w' ) as f : #NEWLINE# #INDENT# f . write ( '-- SQL ALTER statements for database migration\n' )