File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed
tests/apps/migrations/auto/integration Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,10 @@ def _generate_migration_meta(app_config: AppConfig) -> NewMigrationMeta:
8383 )
8484
8585
86+ class NoChanges (Exception ):
87+ pass
88+
89+
8690async def _create_new_migration (
8791 app_config : AppConfig , auto = False
8892) -> NewMigrationMeta :
@@ -108,8 +112,7 @@ async def _create_new_migration(
108112 )
109113
110114 if sum ([len (i .statements ) for i in alter_statements ]) == 0 :
111- print ("No changes detected - exiting." )
112- sys .exit (0 )
115+ raise NoChanges ()
113116
114117 file_contents = render_template (
115118 migration_id = meta .migration_id ,
@@ -193,4 +196,7 @@ async def new(app_name: str, auto: bool = False):
193196 app_config = Finder ().get_app_config (app_name = app_name )
194197
195198 _create_migrations_folder (app_config .migrations_folder_path )
196- await _create_new_migration (app_config = app_config , auto = auto )
199+ try :
200+ await _create_new_migration (app_config = app_config , auto = auto )
201+ except NoChanges :
202+ print ("No changes detected - exiting." )
Original file line number Diff line number Diff line change @@ -540,7 +540,7 @@ def get_sql_value(self, value: t.Any) -> t.Any:
540540 elif isinstance (value , bool ):
541541 output = str (value ).lower ()
542542 elif isinstance (value , datetime .datetime ):
543- output = f"'{ value .isoformat ().replace ('T' , '' )} '"
543+ output = f"'{ value .isoformat ().replace ('T' , ' ' )} '"
544544 elif isinstance (value , bytes ):
545545 output = f"'{ value .hex ()} '"
546546 elif isinstance (value , uuid .UUID ):
Original file line number Diff line number Diff line change 11from __future__ import annotations
2+ import datetime
23import os
34import shutil
45import tempfile
1415 Integer ,
1516 SmallInt ,
1617 Text ,
18+ Timestamp ,
1719 UUID ,
1820 Varchar ,
1921)
@@ -43,6 +45,10 @@ def uuid_default():
4345 return uuid .uuid4 ()
4446
4547
48+ def datetime_default ():
49+ return datetime .datetime .now ()
50+
51+
4652@postgres_only
4753class TestMigrations (TestCase ):
4854 def tearDown (self ):
@@ -198,3 +204,22 @@ def test_uuid_column(self):
198204 ]
199205 ]
200206 )
207+
208+ def test_timestamp_column (self ):
209+ self ._test_migrations (
210+ table_classes = [
211+ self .table (column )
212+ for column in [
213+ Timestamp (),
214+ Timestamp (
215+ default = datetime .datetime (year = 2021 , month = 1 , day = 1 )
216+ ),
217+ Timestamp (default = datetime .datetime .now ),
218+ Timestamp (default = datetime_default ),
219+ Timestamp (null = True , default = None ),
220+ Timestamp (null = False ),
221+ Timestamp (index = True ),
222+ Timestamp (index = False ),
223+ ]
224+ ]
225+ )
You can’t perform that action at this time.
0 commit comments