2
2
//
3
3
// SPDX-License-Identifier: AGPL-3.0-or-later
4
4
5
+ use chrono:: { DateTime , Utc } ;
5
6
use phnxtypes:: { codec:: PhnxCodec , identifiers:: AsClientId } ;
6
7
use rusqlite:: { params, types:: FromSql , Connection , OptionalExtension , ToSql } ;
7
8
use serde:: { Deserialize , Serialize } ;
@@ -47,7 +48,7 @@ impl Storable for UserCreationState {
47
48
const CREATE_TABLE_STATEMENT : & ' static str = "
48
49
CREATE TABLE IF NOT EXISTS user_creation_state (
49
50
client_id BLOB PRIMARY KEY,
50
- state BLOB NOT NULL
51
+ state BLOB NOT NULL,
51
52
);" ;
52
53
53
54
fn from_row ( row : & rusqlite:: Row ) -> anyhow:: Result < Self , rusqlite:: Error > {
@@ -81,9 +82,11 @@ impl UserCreationState {
81
82
impl Storable for ClientRecord {
82
83
const CREATE_TABLE_STATEMENT : & ' static str = "
83
84
CREATE TABLE IF NOT EXISTS client_record (
84
- client_id BLOB PRIMARY KEY,
85
- record_state TEXT NOT NULL CHECK (record_state IN ('in_progress', 'finished'))
86
- );" ;
85
+ client_id BLOB NOT NULL PRIMARY KEY,
86
+ record_state TEXT NOT NULL CHECK (record_state IN ('in_progress', 'finished')),
87
+ created_at DATETIME NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now', 'utc')),
88
+ is_default BOOLEAN NOT NULL DEFAULT FALSE
89
+ )" ;
87
90
88
91
fn from_row ( row : & rusqlite:: Row ) -> anyhow:: Result < Self , rusqlite:: Error > {
89
92
let record_state_str: String = row. get ( 1 ) ?;
@@ -92,9 +95,13 @@ impl Storable for ClientRecord {
92
95
"finished" => ClientRecordState :: Finished ,
93
96
_ => return Err ( rusqlite:: Error :: InvalidQuery ) ,
94
97
} ;
98
+ let created_at: DateTime < Utc > = row. get ( 2 ) ?;
99
+ let is_default: bool = row. get ( 3 ) ?;
95
100
Ok ( Self {
96
101
as_client_id : row. get ( 0 ) ?,
97
102
client_record_state,
103
+ created_at,
104
+ is_default,
98
105
} )
99
106
}
100
107
}
@@ -136,8 +143,15 @@ impl ClientRecord {
136
143
ClientRecordState :: Finished => "finished" ,
137
144
} ;
138
145
connection. execute (
139
- "INSERT OR REPLACE INTO client_record (client_id, record_state) VALUES (?1, ?2)" ,
140
- params ! [ self . as_client_id, record_state_str] ,
146
+ "INSERT OR REPLACE INTO client_record
147
+ (client_id, record_state, created_at, is_default)
148
+ VALUES (?1, ?2, ?3, ?4)" ,
149
+ params ! [
150
+ self . as_client_id,
151
+ record_state_str,
152
+ self . created_at,
153
+ self . is_default,
154
+ ] ,
141
155
) ?;
142
156
Ok ( ( ) )
143
157
}
0 commit comments