#NEWLINE# def get_alter_table_sql( self , diff ) : #NEWLINE# #INDENT# '\n        Get the ALTER TABLE SQL statement\n\n        :param diff: The table diff\n        :type diff: orator.dbal.table_diff.TableDiff\n\n        :rtype: list\n        ' #NEWLINE# sql = [ ] #NEWLINE# for column_diff in diff . changed_columns . values ( ) : #NEWLINE# #INDENT# if self . is_unchanged_binary_column ( column_diff ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# old_column_name = column_diff . get_old_column_name ( ) . get_quoted_name ( self ) #NEWLINE# column = column_diff . column #NEWLINE# if any ( [ column_diff . has_changed ( 'type' ) , column_diff . has_changed ( 'precision' ) , column_diff . has_changed ( 'scale' ) , column_diff . has_changed ( 'fixed' ) ] ) : #NEWLINE# #INDENT# query = ( ( ( 'ALTER ' + old_column_name ) + ' TYPE ' ) + self . get_sql_type_declaration ( column . to_dict ( ) ) ) #NEWLINE# sql . append ( ( ( ( 'ALTER TABLE ' + diff . get_name ( self ) . get_quoted_name ( self ) ) + ' ' ) + query ) ) #NEWLINE# #UNINDENT# if ( column_diff . has_changed ( 'default' ) or column_diff . has_changed ( 'type' ) ) : #NEWLINE# #INDENT# if ( column . get_default ( ) is None ) : #NEWLINE# #INDENT# default_clause = ' DROP DEFAULT' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# default_clause = ( ' SET' + self . get_default_value_declaration_sql ( column . to_dict ( ) ) ) #NEWLINE# #UNINDENT# query = ( ( 'ALTER ' + old_column_name ) + default_clause ) #NEWLINE# sql . append ( ( ( ( 'ALTER TABLE ' + diff . get_name ( self ) . get_quoted_name ( self ) ) + ' ' ) + query ) ) #NEWLINE# #UNINDENT# if column_diff . has_changed ( 'notnull' ) : #NEWLINE# #INDENT# op = 'DROP' #NEWLINE# if column . get_notnull ( ) : #NEWLINE# #INDENT# op = 'SET' #NEWLINE# #UNINDENT# query = ( ( ( ( 'ALTER ' + old_column_name ) + ' ' ) + op ) + ' NOT NULL' ) #NEWLINE# sql . append ( ( ( ( 'ALTER TABLE ' + diff . get_name ( self ) . get_quoted_name ( self ) ) + ' ' ) + query ) ) #NEWLINE# #UNINDENT# if column_diff . has_changed ( 'autoincrement' ) : #NEWLINE# #INDENT# if column . get_autoincrement ( ) : #NEWLINE# #INDENT# seq_name = self . get_identity_sequence_name ( diff . name , old_column_name ) #NEWLINE# sql . append ( ( 'CREATE SEQUENCE ' + seq_name ) ) #NEWLINE# sql . append ( ( ( ( ( ( ( "SELECT setval('" + seq_name ) + "', (SELECT MAX(" ) + old_column_name ) + ') FROM ' ) + diff . name ) + '))' ) ) #NEWLINE# query = ( ( ( ( 'ALTER ' + old_column_name ) + " SET DEFAULT nextval('" ) + seq_name ) + "')" ) #NEWLINE# sql . append ( ( ( ( 'ALTER TABLE ' + diff . get_name ( self ) . get_quoted_name ( self ) ) + ' ' ) + query ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# query = ( ( 'ALTER ' + old_column_name ) + ' DROP DEFAULT' ) #NEWLINE# sql . append ( ( ( ( 'ALTER TABLE ' + diff . get_name ( self ) . get_quoted_name ( self ) ) + ' ' ) + query ) ) #NEWLINE# #UNINDENT# #UNINDENT# if column_diff . has_changed ( 'length' ) : #NEWLINE# #INDENT# query = ( ( ( 'ALTER ' + old_column_name ) + ' TYPE ' ) + self . get_sql_type_declaration ( column . to_dict ( ) ) ) #NEWLINE# sql . append ( ( ( ( 'ALTER TABLE ' + diff . get_name ( self ) . get_quoted_name ( self ) ) + ' ' ) + query ) ) #NEWLINE# #UNINDENT# #UNINDENT# for ( old_column_name , column ) in diff . renamed_columns . items ( ) : #NEWLINE# #INDENT# sql . append ( ( ( ( ( ( 'ALTER TABLE ' + diff . get_name ( self ) . get_quoted_name ( self ) ) + ' RENAME COLUMN ' ) + Identifier ( old_column_name ) . get_quoted_name ( self ) ) + ' TO ' ) + column . get_quoted_name ( self ) ) ) #NEWLINE# #UNINDENT# return sql