[Fix] Durability
This commit is contained in:
parent
8e709513c0
commit
c2e7061041
5 changed files with 13 additions and 3 deletions
|
|
@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS users (
|
|||
sub_end BIGINT NOT NULL DEFAULT 0,
|
||||
public_key BLOB NOT NULL,
|
||||
token BLOB NOT NULL,
|
||||
created_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
|
||||
UNIQUE KEY uk_users_username (username),
|
||||
KEY idx_users_iota_id (iota_id),
|
||||
|
|
|
|||
2
migrations/008_user_created_at.sql
Normal file
2
migrations/008_user_created_at.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN created_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);
|
||||
|
|
@ -101,9 +101,9 @@ pub(crate) fn is_duplicate_key(error: &sqlx::Error) -> bool {
|
|||
})
|
||||
}
|
||||
|
||||
const USER_BY_USERNAME_QUERY: &str = "SELECT id, iota_id, username, display, status, presence_preference, about, avatar, sub_level, sub_end, public_key, token FROM users WHERE username = ?";
|
||||
const USER_BY_ID_QUERY: &str = "SELECT id, iota_id, username, display, status, presence_preference, about, avatar, sub_level, sub_end, public_key, token FROM users WHERE id = ?";
|
||||
const USER_COLUMNS: &str = "SELECT id, iota_id, username, display, status, presence_preference, about, avatar, sub_level, sub_end, public_key, token FROM users";
|
||||
const USER_BY_USERNAME_QUERY: &str = "SELECT id, iota_id, username, display, status, presence_preference, about, avatar, sub_level, sub_end, public_key, token, CAST(UNIX_TIMESTAMP(created_at) * 1000 AS SIGNED) AS created_at FROM users WHERE username = ?";
|
||||
const USER_BY_ID_QUERY: &str = "SELECT id, iota_id, username, display, status, presence_preference, about, avatar, sub_level, sub_end, public_key, token, CAST(UNIX_TIMESTAMP(created_at) * 1000 AS SIGNED) AS created_at FROM users WHERE id = ?";
|
||||
const USER_COLUMNS: &str = "SELECT id, iota_id, username, display, status, presence_preference, about, avatar, sub_level, sub_end, public_key, token, CAST(UNIX_TIMESTAMP(created_at) * 1000 AS SIGNED) AS created_at FROM users";
|
||||
|
||||
#[derive(FromRow)]
|
||||
struct UserRow {
|
||||
|
|
@ -119,6 +119,7 @@ struct UserRow {
|
|||
sub_end: i64,
|
||||
public_key: Vec<u8>,
|
||||
token: Vec<u8>,
|
||||
created_at: i64,
|
||||
}
|
||||
|
||||
impl TryFrom<UserRow> for User {
|
||||
|
|
@ -142,6 +143,7 @@ impl TryFrom<UserRow> for User {
|
|||
sub_end: row.sub_end,
|
||||
public_key,
|
||||
token: decode(row.token)?,
|
||||
created_at: row.created_at,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,4 +17,5 @@ pub struct User {
|
|||
pub public_key: PublicKeyBundle,
|
||||
#[serde(skip_serializing)]
|
||||
pub token: String,
|
||||
pub created_at: i64,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,10 @@ pub async fn get_user(
|
|||
DataValue::Str(user.public_key.try_to_base64()?),
|
||||
)
|
||||
.add_typed_default(DataType::UserId, DataValue::SignedNumber(id.into()))
|
||||
.add_typed_default(
|
||||
DataType::CreatedAt,
|
||||
DataValue::SignedNumber(user.created_at.into()),
|
||||
)
|
||||
.add_typed_default(DataType::Display, DataValue::Str(display))
|
||||
.add_typed_default(
|
||||
DataType::SubLevel,
|
||||
|
|
|
|||
Loading…
Reference in a new issue