fix datetime conversion
This commit is contained in:
+2
-1
@@ -348,6 +348,7 @@ async def delete_expired_invoices(
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
# payments
|
||||
# --------
|
||||
|
||||
@@ -399,7 +400,7 @@ async def create_payment(
|
||||
if extra and extra != {} and type(extra) is dict
|
||||
else None,
|
||||
webhook,
|
||||
expiration_date,
|
||||
db.datetime_to_timestamp(expiration_date),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -197,6 +197,10 @@ async def m006_add_invoice_expiry_to_apipayments(db):
|
||||
Adds invoice expiry field to apipayments and precomputes them for
|
||||
existing entries
|
||||
"""
|
||||
try:
|
||||
await db.execute("ALTER TABLE apipayments ADD COLUMN expiry TIMESTAMP")
|
||||
except OperationalError:
|
||||
pass
|
||||
try:
|
||||
rows = await (
|
||||
await db.execute(
|
||||
@@ -206,7 +210,7 @@ async def m006_add_invoice_expiry_to_apipayments(db):
|
||||
WHERE pending = true
|
||||
AND bolt11 IS NOT NULL
|
||||
AND expiry IS NULL
|
||||
AND amount > 0 AND time < {db.timestamp_now} - {db.interval_seconds(86400)}
|
||||
AND amount > 0 AND time < {db.timestamp_now}
|
||||
"""
|
||||
)
|
||||
).fetchall()
|
||||
@@ -237,7 +241,7 @@ async def m006_add_invoice_expiry_to_apipayments(db):
|
||||
WHERE checking_id = ? AND amount > 0
|
||||
""",
|
||||
(
|
||||
expiration_date,
|
||||
db.datetime_to_timestamp(expiration_date),
|
||||
invoice.payment_hash,
|
||||
),
|
||||
)
|
||||
|
||||
+8
-8
@@ -29,6 +29,13 @@ class Compat:
|
||||
return f"{seconds}"
|
||||
return "<nothing>"
|
||||
|
||||
def datetime_to_timestamp(self, date: datetime.datetime):
|
||||
if self.type in {POSTGRES, COCKROACH}:
|
||||
return date.strftime("%Y-%m-%d %H:%M:%S")
|
||||
elif self.type == SQLITE:
|
||||
return time.mktime(date.timetuple())
|
||||
return "<nothing>"
|
||||
|
||||
@property
|
||||
def timestamp_now(self) -> str:
|
||||
if self.type in {POSTGRES, COCKROACH}:
|
||||
@@ -149,14 +156,7 @@ class Database(Compat):
|
||||
|
||||
psycopg2.extensions.register_type(
|
||||
psycopg2.extensions.new_type(
|
||||
(1184, 1114),
|
||||
"TIMESTAMP2INT",
|
||||
_parse_timestamp
|
||||
# lambda value, curs: time.mktime(
|
||||
# datetime.datetime.strptime(
|
||||
# value, "%Y-%m-%d %H:%M:%S.%f"
|
||||
# ).timetuple()
|
||||
# ),
|
||||
(1184, 1114), "TIMESTAMP2INT", _parse_timestamp
|
||||
)
|
||||
)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user