Skip to content

Commit 8d69500

Browse files
committed
new column
1 parent b19eb75 commit 8d69500

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

packages/postgres-database/src/simcore_postgres_database/models/confirmations.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
""" User's confirmations table
1+
"""User's confirmations table
22
3-
- Keeps a list of tokens to identify an action (registration, invitation, reset, etc) authorized
4-
by link to a a user in the framework
5-
- These tokens have an expiration date defined by configuration
3+
- Keeps a list of tokens to identify an action (registration, invitation, reset, etc) authorized
4+
by link to a a user in the framework
5+
- These tokens have an expiration date defined by configuration
66
77
"""
8+
89
import enum
910

1011
import sqlalchemy as sa
1112

12-
from ._common import RefActions
13+
from ._common import RefActions, column_created_datetime
1314
from .base import metadata
1415
from .users import users
1516

@@ -47,12 +48,8 @@ class ConfirmationAction(enum.Enum):
4748
sa.Text,
4849
doc="Extra data associated to the action. SEE handlers_confirmation.py::email_confirmation",
4950
),
50-
sa.Column(
51-
"created_at",
52-
sa.DateTime(),
53-
nullable=False,
54-
# NOTE: that here it would be convenient to have a server_default=now()!
55-
doc="Creation date of this code."
51+
column_created_datetime(
52+
doc="Creation date of this code. "
5653
"Can be used as reference to determine the expiration date. SEE ${ACTION}_CONFIRMATION_LIFETIME",
5754
),
5855
# constraints ----------------

services/web/server/src/simcore_service_webserver/login/_confirmation_repository.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from datetime import datetime
32
from typing import Any
43

54
import sqlalchemy as sa
@@ -21,7 +20,15 @@
2120

2221

2322
def _to_domain(confirmation_row: Row) -> Confirmation:
24-
return Confirmation.model_validate(confirmation_row)
23+
return Confirmation.model_validate(
24+
{
25+
"code": confirmation_row.code,
26+
"user_id": confirmation_row.user_id,
27+
"action": confirmation_row.action.value, # conversion to literal string
28+
"data": confirmation_row.data,
29+
"created_at": confirmation_row.created, # renames
30+
}
31+
)
2532

2633

2734
class ConfirmationRepository(BaseRepository):
@@ -57,7 +64,6 @@ async def create_confirmation(
5764
user_id=user_id,
5865
action=action,
5966
data=data,
60-
created_at=datetime.utcnow(),
6167
)
6268
.returning(*confirmations.c)
6369
)

services/web/server/tests/unit/with_dbs/03/login/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pytest_simcore.helpers.webserver_users import NewUser, UserInfoDict
1818
from simcore_postgres_database.models.users import users
1919
from simcore_postgres_database.models.wallets import wallets
20+
from simcore_service_webserver.db.plugin import get_asyncpg_engine
2021
from simcore_service_webserver.login._confirmation_repository import (
2122
ConfirmationRepository,
2223
)
@@ -88,7 +89,7 @@ def confirmation_repository(client: TestClient) -> ConfirmationRepository:
8889
"""Modern confirmation repository instance"""
8990
assert client.app
9091
# Get the async engine from the application
91-
engine = client.app["postgres_db_engine"]
92+
engine = get_asyncpg_engine(client.app)
9293
return ConfirmationRepository(engine)
9394

9495

0 commit comments

Comments
 (0)