@@ -111,6 +111,70 @@ public function testChangeTextColumnToTextColumn()
111
111
}
112
112
}
113
113
114
+ public function testModifyNullableColumn ()
115
+ {
116
+ if (! in_array ($ this ->driver , ['mysql ' , 'mariadb ' ])) {
117
+ $ this ->markTestSkipped ('Test requires a MySQL or a MariaDB connection. ' );
118
+ }
119
+
120
+ Schema::create ('test ' , static function (Blueprint $ table ) {
121
+ $ table ->string ('not_null_column_to_not_null ' );
122
+ $ table ->string ('not_null_column_to_nullable ' );
123
+ $ table ->string ('nullable_column_to_nullable ' )->nullable ();
124
+ $ table ->string ('nullable_column_to_not_null ' )->nullable ();
125
+ });
126
+
127
+ $ blueprint = new Blueprint ('test ' , function ($ table ) {
128
+ $ table ->text ('not_null_column_to_not_null ' )->change ();
129
+ $ table ->text ('not_null_column_to_nullable ' )->nullable ()->change ();
130
+ $ table ->text ('nullable_column_to_nullable ' )->nullable ()->change ();
131
+ $ table ->text ('nullable_column_to_not_null ' )->change ();
132
+ });
133
+
134
+ $ queries = $ blueprint ->toSql ($ this ->getConnection (), $ this ->getConnection ()->getSchemaGrammar ());
135
+
136
+ $ expected = [
137
+ 'alter table `test` '
138
+ .'modify `not_null_column_to_not_null` text not null, '
139
+ .'modify `not_null_column_to_nullable` text null, '
140
+ .'modify `nullable_column_to_nullable` text null, '
141
+ .'modify `nullable_column_to_not_null` text not null ' ,
142
+ ];
143
+
144
+ $ this ->assertEquals ($ expected , $ queries );
145
+ }
146
+
147
+ public function testChangeNullableColumn ()
148
+ {
149
+ Schema::create ('test ' , function (Blueprint $ table ) {
150
+ $ table ->string ('not_null_column_to_not_null ' );
151
+ $ table ->string ('not_null_column_to_nullable ' );
152
+ $ table ->string ('nullable_column_to_nullable ' )->nullable ();
153
+ $ table ->string ('nullable_column_to_not_null ' )->nullable ();
154
+ });
155
+
156
+ $ columns = collect (Schema::getColumns ('test ' ));
157
+
158
+ $ this ->assertFalse ($ columns ->firstWhere ('name ' , 'not_null_column_to_not_null ' )['nullable ' ]);
159
+ $ this ->assertFalse ($ columns ->firstWhere ('name ' , 'not_null_column_to_nullable ' )['nullable ' ]);
160
+ $ this ->assertTrue ($ columns ->firstWhere ('name ' , 'nullable_column_to_nullable ' )['nullable ' ]);
161
+ $ this ->assertTrue ($ columns ->firstWhere ('name ' , 'nullable_column_to_not_null ' )['nullable ' ]);
162
+
163
+ Schema::table ('test ' , function (Blueprint $ table ) {
164
+ $ table ->text ('not_null_column_to_not_null ' )->change ();
165
+ $ table ->text ('not_null_column_to_nullable ' )->nullable ()->change ();
166
+ $ table ->text ('nullable_column_to_nullable ' )->nullable ()->change ();
167
+ $ table ->text ('nullable_column_to_not_null ' )->change ();
168
+ });
169
+
170
+ $ columns = collect (Schema::getColumns ('test ' ));
171
+
172
+ $ this ->assertFalse ($ columns ->firstWhere ('name ' , 'not_null_column_to_not_null ' )['nullable ' ]);
173
+ $ this ->assertTrue ($ columns ->firstWhere ('name ' , 'not_null_column_to_nullable ' )['nullable ' ]);
174
+ $ this ->assertTrue ($ columns ->firstWhere ('name ' , 'nullable_column_to_nullable ' )['nullable ' ]);
175
+ $ this ->assertFalse ($ columns ->firstWhere ('name ' , 'nullable_column_to_not_null ' )['nullable ' ]);
176
+ }
177
+
114
178
public function testRenameColumnWithDefault ()
115
179
{
116
180
Schema::create ('test ' , static function (Blueprint $ table ) {
0 commit comments