@@ -3081,6 +3081,70 @@ function ( $old_name ) use ( $from_name, $new_field ) {
30813081 }
30823082 // We're done.
30833083 break ;
3084+ } elseif ( 'ALTER ' === $ op_type ) {
3085+ $ raw_from_name = 'COLUMN ' === $ op_subject ? $ this ->rewriter ->skip ()->token : $ op_raw_subject ;
3086+ $ from_name = $ this ->normalize_column_name ( $ raw_from_name );
3087+
3088+ $ set_or_drop_default = $ this ->rewriter ->peek ()->matches (
3089+ WP_SQLite_Token::TYPE_KEYWORD ,
3090+ WP_SQLite_Token::FLAG_KEYWORD_RESERVED ,
3091+ array ( 'SET ' , 'DROP ' )
3092+ ) && $ this ->rewriter ->peek_nth ( 2 )->matches (
3093+ WP_SQLite_Token::TYPE_KEYWORD ,
3094+ WP_SQLite_Token::FLAG_KEYWORD_RESERVED ,
3095+ array ( 'DEFAULT ' )
3096+ );
3097+
3098+ // Handle "CHANGE <column> DROP DEFAULT" and "CHANGE <column> SET DEFAULT <value>".
3099+ if ( $ set_or_drop_default ) {
3100+ $ this ->execute_change (
3101+ function ( $ old_name , $ old_column ) use ( $ from_name ) {
3102+ //$old_column->consume_all();
3103+ //var_dump($old_column->get_updated_query());ob_flush();
3104+ //$old_column->replace_all([]);
3105+ if ( $ from_name !== $ old_name ) {
3106+ return null ;
3107+ }
3108+
3109+ // 1. Drop "DEFAULT <value>" from old column definition.
3110+ do {
3111+ $ is_default = $ old_column ->peek ()->matches (
3112+ WP_SQLite_Token::TYPE_KEYWORD ,
3113+ WP_SQLite_Token::FLAG_KEYWORD_RESERVED ,
3114+ array ( 'DEFAULT ' )
3115+ );
3116+ if ( $ is_default ) {
3117+ $ old_column ->skip (); // DEFAULT
3118+ $ old_column ->skip (); // value
3119+ } else {
3120+ $ old_column ->consume ();
3121+ }
3122+ } while ( $ old_column ->peek () );
3123+
3124+ // 2. For SET, add new "DEFAULT <value>" to column definition.
3125+ $ keyword = $ this ->rewriter ->consume ();
3126+ if ( 'SET ' === $ keyword ->value ) {
3127+ $ old_column ->add ( new WP_SQLite_Token ( ' ' , WP_SQLite_Token::TYPE_WHITESPACE ) );
3128+ $ old_column ->add ( $ this ->rewriter ->consume () ); // DEFAULT
3129+ $ old_column ->add ( new WP_SQLite_Token ( ' ' , WP_SQLite_Token::TYPE_WHITESPACE ) );
3130+ $ old_column ->add ( $ this ->rewriter ->consume () ); // value
3131+ }
3132+ return $ old_column ->get_updated_query ();
3133+ }
3134+ );
3135+
3136+ if ( ', ' === $ this ->rewriter ->peek ()->value ) {
3137+ /*
3138+ * If the terminator was a comma,
3139+ * we need to continue processing the rest of the ALTER query.
3140+ */
3141+ $ this ->rewriter ->consume ();
3142+ $ comma = true ;
3143+ continue ;
3144+ }
3145+ // We're done.
3146+ break ;
3147+ }
30843148 } elseif ( 'ADD ' === $ op_type && $ is_index_op ) {
30853149 $ key_name = $ this ->rewriter ->consume ()->value ;
30863150 $ sqlite_index_type = $ this ->mysql_index_type_to_sqlite_type ( $ mysql_index_type );
0 commit comments