@@ -132,6 +132,54 @@ public function testGetCreateCommand(
132132 self ::assertSame ($ expectedPKs , $ tableReflection ->getPrimaryKeysNames ());
133133 }
134134
135+ public function testAddAndDropColumn (): void
136+ {
137+ $ dbName = $ this ->getDatabaseName ();
138+ $ columns = [TeradataColumn::createGenericColumn ('col1 ' ),
139+ TeradataColumn::createGenericColumn ('col2 ' )];
140+ $ sql = $ this ->qb ->getCreateTableCommand (
141+ $ this ->getDatabaseName (),
142+ self ::TABLE_GENERIC ,
143+ new ColumnCollection ($ columns ),
144+ );
145+ $ this ->connection ->executeQuery ($ sql );
146+
147+ // add column
148+ $ sql = $ this ->qb ->getAddColumnCommand (
149+ $ dbName ,
150+ self ::TABLE_GENERIC ,
151+ TeradataColumn::createGenericColumn ('col3 ' )
152+ );
153+ $ this ->assertEquals (
154+ sprintf (
155+ 'ALTER TABLE "%s"."%s" ADD "col3" VARCHAR (32000) NOT NULL DEFAULT \'\' CHARACTER SET UNICODE ' ,
156+ $ dbName ,
157+ self ::TABLE_GENERIC
158+ ),
159+ $ sql
160+ );
161+ $ this ->connection ->executeQuery ($ sql );
162+
163+ $ tableReflection = new TeradataTableReflection (
164+ $ this ->connection ,
165+ $ this ->getDatabaseName (),
166+ self ::TABLE_GENERIC
167+ );
168+ self ::assertSame (['col1 ' , 'col2 ' , 'col3 ' ], $ tableReflection ->getColumnsNames ());
169+
170+ // drop column
171+ $ sql = $ this ->qb ->getDropColumnCommand ($ dbName , self ::TABLE_GENERIC , 'col2 ' );
172+ $ this ->assertEquals (sprintf ('ALTER TABLE "%s"."%s" DROP "col2" ' , $ dbName , self ::TABLE_GENERIC ), $ sql );
173+ $ this ->connection ->executeQuery ($ sql );
174+
175+ $ tableReflection = new TeradataTableReflection (
176+ $ this ->connection ,
177+ $ this ->getDatabaseName (),
178+ self ::TABLE_GENERIC
179+ );
180+ self ::assertSame (['col1 ' , 'col3 ' ], $ tableReflection ->getColumnsNames ());
181+ }
182+
135183 /**
136184 * @return \Generator<string, mixed, mixed, mixed>
137185 */
0 commit comments