#NEWLINE# def copy_database( raw_conn , from_database , to_database ) : #NEWLINE# #INDENT# logger . debug ( 'copy_database(%r, %r)' , from_database , to_database ) #NEWLINE# terminate_database_connections ( raw_conn , from_database ) #NEWLINE# if ( raw_conn . engine . dialect . name == 'postgresql' ) : #NEWLINE# #INDENT# raw_conn . execute ( ( '\n                CREATE DATABASE "%s" WITH TEMPLATE "%s";\n            ' % ( to_database , from_database ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( raw_conn . engine . dialect . name == 'mysql' ) : #NEWLINE# #INDENT# create_database ( raw_conn , to_database ) #NEWLINE# for row in raw_conn . execute ( ( 'SHOW TABLES in %s;' % from_database ) ) : #NEWLINE# #INDENT# raw_conn . execute ( ( '\n                CREATE TABLE %s.%s LIKE %s.%s\n            ' % ( to_database , row [ 0 ] , from_database , row [ 0 ] ) ) ) #NEWLINE# raw_conn . execute ( ( 'ALTER TABLE %s.%s DISABLE KEYS' % ( to_database , row [ 0 ] ) ) ) #NEWLINE# raw_conn . execute ( ( '\n                INSERT INTO %s.%s SELECT * FROM %s.%s\n            ' % ( to_database , row [ 0 ] , raw_conn , row [ 0 ] ) ) ) #NEWLINE# raw_conn . execute ( ( 'ALTER TABLE %s.%s ENABLE KEYS' % ( to_database , row [ 0 ] ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise NotSupportedDatabase ( )