schema.sql: add users.last_session

- gateway.websocket: update users.last_session

SQL for instances:
```sql
ALTER TABLE users ADD COLUMN last_session timestamp without time zone default (now() at time zone 'utc');
```
This commit is contained in:
Luna Mendes 2018-10-27 23:40:35 -03:00
parent 9aa9b3839b
commit 80c29265f3
2 changed files with 10 additions and 0 deletions

View File

@ -406,6 +406,13 @@ class GatewayWebsocket:
# link the state to the user
self.ext.state_manager.insert(self.state)
# update last_session
await self.ext.db.execute("""
UPDATE users
SET last_session = (now() at time zone 'utc')
WHERE id = $1
""", user_id)
await self.update_status(presence)
await self.subscribe_all()
await self.dispatch_ready()

View File

@ -75,6 +75,9 @@ CREATE TABLE IF NOT EXISTS users (
phone varchar(60) DEFAULT '',
password_hash text NOT NULL,
-- store the last time the user logged in via the gateway
last_session timestamp without time zone default (now() at time zone 'utc'),
PRIMARY KEY (id, username, discriminator)
);