1+ from piccolo .columns .column_types import Varchar
12from unittest import TestCase
23
3- from piccolo .columns import Integer , Numeric
4+ from piccolo .columns import BigInt , Integer , Numeric
45from piccolo .table import Table
56
67from ..base import DBTestCase , postgres_only
@@ -113,7 +114,6 @@ def test_unique(self):
113114 self .assertTrue (len (response ), 2 )
114115
115116
116- # TODO - make it work for SQLite. Should work.
117117@postgres_only
118118class TestMultiple (DBTestCase ):
119119 """
@@ -137,6 +137,61 @@ def test_multiple(self):
137137 self .assertTrue ("column_b" in column_names )
138138
139139
140+ @postgres_only
141+ class TestSetColumnType (DBTestCase ):
142+ def test_integer_to_bigint (self ):
143+ """
144+ Test converting an Integer column to BigInt.
145+ """
146+ self .insert_row ()
147+
148+ alter_query = Band .alter ().set_column_type (
149+ old_column = Band .popularity , new_column = BigInt ()
150+ )
151+ alter_query .run_sync ()
152+
153+ query = """
154+ SELECT data_type FROM information_schema.columns
155+ WHERE table_name = 'band'
156+ AND table_catalog = 'piccolo'
157+ AND column_name = 'popularity'
158+ """
159+
160+ response = Band .raw (query ).run_sync ()
161+ self .assertEqual (response [0 ]["data_type" ].upper (), "BIGINT" )
162+
163+ popularity = (
164+ Band .select (Band .popularity ).first ().run_sync ()["popularity" ]
165+ )
166+ self .assertEqual (popularity , 1000 )
167+
168+ def test_integer_to_varchar (self ):
169+ """
170+ Test converting an Integer column to Varchar.
171+ """
172+ self .insert_row ()
173+
174+ alter_query = Band .alter ().set_column_type (
175+ old_column = Band .popularity , new_column = Varchar ()
176+ )
177+ alter_query .run_sync ()
178+
179+ query = """
180+ SELECT data_type FROM information_schema.columns
181+ WHERE table_name = 'band'
182+ AND table_catalog = 'piccolo'
183+ AND column_name = 'popularity'
184+ """
185+
186+ response = Band .raw (query ).run_sync ()
187+ self .assertEqual (response [0 ]["data_type" ].upper (), "CHARACTER VARYING" )
188+
189+ popularity = (
190+ Band .select (Band .popularity ).first ().run_sync ()["popularity" ]
191+ )
192+ self .assertEqual (popularity , "1000" )
193+
194+
140195@postgres_only
141196class TestSetNull (DBTestCase ):
142197 def test_set_null (self ):
0 commit comments