fix deprecation warnings associated with usage of datetime.utcnow

fixes #96
M yoyo/backends/base.py +7 -3
@@ 14,6 14,7 @@ 
 
 from collections.abc import Mapping
 from datetime import datetime
+from datetime import timezone
 from contextlib import contextmanager
 from importlib import import_module
 from itertools import count

          
@@ 336,7 337,10 @@ class DatabaseBackend:
                     self.execute(
                         "INSERT INTO {} (locked, ctime, pid) "
                         "VALUES (1, :when, :pid)".format(self.lock_table_quoted),
-                        {"when": datetime.utcnow(), "pid": pid},
+                        {
+                            "when": datetime.now(timezone.utc).replace(tzinfo=None),
+                            "pid": pid,
+                        },
                     )
             except self.DatabaseError:
                 if timeout and time.time() > started + timeout:

          
@@ 536,7 540,7 @@ class DatabaseBackend:
             {
                 "migration_hash": migration.hash,
                 "migration_id": migration.id,
-                "when": datetime.utcnow(),
+                "when": datetime.now(timezone.utc).replace(tzinfo=None),
             },
         )
         if log:

          
@@ 557,7 561,7 @@ class DatabaseBackend:
             "migration_hash": migration.hash if migration else None,
             "username": getpass.getuser(),
             "hostname": socket.getfqdn(),
-            "created_at_utc": datetime.utcnow(),
+            "created_at_utc": datetime.now(timezone.utc).replace(tzinfo=None),
             "operation": operation,
             "comment": comment,
         }

          
M yoyo/backends/contrib/redshift.py +5 -1
@@ 14,6 14,7 @@ 
 
 import time
 from datetime import datetime
+from datetime import timezone
 
 from yoyo import exceptions
 from yoyo.backends.core.postgresql import PostgresqlBackend

          
@@ 50,7 51,10 @@ class RedshiftBackend(PostgresqlBackend)
                     self.execute(
                         "INSERT INTO {} (locked, ctime, pid) "
                         "VALUES (1, :when, :pid)".format(self.lock_table_quoted),
-                        {"when": datetime.utcnow(), "pid": pid},
+                        {
+                            "when": datetime.now(timezone.utc).replace(tzinfo=None),
+                            "pid": pid,
+                        },
                     )
                     return
                 elif timeout and time.time() > started + timeout:

          
M yoyo/internalmigrations/__init__.py +2 -1
@@ 3,6 3,7 @@ Migrate yoyo's internal table structure
 """
 
 from datetime import datetime
+from datetime import timezone
 
 from . import v1
 from . import v2

          
@@ 65,5 66,5 @@ def mark_schema_version(backend, version
         return
     backend.execute(
         "INSERT INTO {0.version_table_quoted} VALUES (:version, :when)".format(backend),
-        {"version": version, "when": datetime.utcnow()},
+        {"version": version, "when": datetime.now(timezone.utc).replace(tzinfo=None)},
     )

          
M yoyo/tests/test_cli_script.py +2 -1
@@ 14,6 14,7 @@ 
 
 from shutil import rmtree
 from datetime import datetime
+from datetime import timezone
 from tempfile import mkdtemp
 from functools import partial
 from itertools import count

          
@@ 259,7 260,7 @@ class TestYoyoScript(TestInteractiveScri
         backend = get_backend(dburi)
         backend.execute(
             "INSERT INTO yoyo_lock (locked, ctime, pid) " "VALUES (1, :now, 1)",
-            {"now": datetime.utcnow()},
+            {"now": datetime.now(timezone.utc).replace(tzinfo=None)},
         )
         backend.commit()
         main(["break-lock", "--database", dburi])

          
M yoyo/tests/test_migrations.py +7 -2
@@ 14,6 14,7 @@ 
 
 from datetime import datetime
 from datetime import timedelta
+from datetime import timezone
 from unittest.mock import Mock, patch
 import io
 import os

          
@@ 566,7 567,9 @@ class TestLogging(object):
             logged = self.get_last_log_entry(backend)
             assert logged["migration_id"] == "a"
             assert logged["operation"] == "apply"
-            assert logged["created_at_utc"] >= datetime.utcnow() - timedelta(seconds=3)
+            assert logged["created_at_utc"] >= (
+                datetime.now(timezone.utc).replace(tzinfo=None) - timedelta(seconds=3)
+            )
             apply_time = logged["created_at_utc"]
 
             backend.rollback_migrations(migrations)

          
@@ 584,7 587,9 @@ class TestLogging(object):
             logged = self.get_last_log_entry(backend)
             assert logged["migration_id"] == "a"
             assert logged["operation"] == "mark"
-            assert logged["created_at_utc"] >= datetime.utcnow() - timedelta(seconds=3)
+            assert logged["created_at_utc"] >= (
+                datetime.now(timezone.utc).replace(tzinfo=None) - timedelta(seconds=3)
+            )
             marked_time = logged["created_at_utc"]
 
             backend.unmark_migrations(migrations)