Add updated_at column to actor_profile table
This commit is contained in:
parent
d63c19a996
commit
d658c3e802
6 changed files with 34 additions and 6 deletions
1
migrations/V0025__actor_profile__add_updated_at.sql
Normal file
1
migrations/V0025__actor_profile__add_updated_at.sql
Normal file
|
@ -0,0 +1 @@
|
|||
ALTER TABLE actor_profile ADD COLUMN updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP;
|
|
@ -14,7 +14,8 @@ CREATE TABLE actor_profile (
|
|||
post_count INTEGER NOT NULL CHECK (post_count >= 0) DEFAULT 0,
|
||||
actor_json JSONB,
|
||||
actor_id VARCHAR(200) UNIQUE GENERATED ALWAYS AS (actor_json ->> 'id') STORED,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE user_invite_code (
|
||||
|
|
|
@ -70,7 +70,7 @@ pub struct DbPost {
|
|||
pub token_id: Option<i32>,
|
||||
pub token_tx_id: Option<String>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
pub updated_at: Option<DateTime<Utc>>, // edited at
|
||||
}
|
||||
|
||||
// List of user's actions
|
||||
|
|
|
@ -71,7 +71,8 @@ pub async fn update_profile(
|
|||
banner_file_name = $5,
|
||||
identity_proofs = $6,
|
||||
extra_fields = $7,
|
||||
actor_json = $8
|
||||
actor_json = $8,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $9
|
||||
RETURNING actor_profile
|
||||
",
|
||||
|
@ -538,6 +539,28 @@ mod tests {
|
|||
assert_eq!(error.to_string(), "profile already exists");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_update_profile() {
|
||||
let db_client = create_test_database().await;
|
||||
let profile_data = ProfileCreateData {
|
||||
username: "test".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
let profile = create_profile(&db_client, profile_data).await.unwrap();
|
||||
let mut profile_data = ProfileUpdateData::from(&profile);
|
||||
let bio = "test bio";
|
||||
profile_data.bio = Some(bio.to_string());
|
||||
let profile_updated = update_profile(
|
||||
&db_client,
|
||||
&profile.id,
|
||||
profile_data,
|
||||
).await.unwrap();
|
||||
assert_eq!(profile_updated.username, profile.username);
|
||||
assert_eq!(profile_updated.bio.unwrap(), bio);
|
||||
assert!(profile_updated.updated_at != profile.updated_at);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_delete_profile() {
|
||||
|
|
|
@ -75,6 +75,7 @@ pub struct DbActorProfile {
|
|||
pub following_count: i32,
|
||||
pub post_count: i32,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub actor_json: Option<Actor>,
|
||||
|
||||
// auto-generated database fields
|
||||
|
@ -116,6 +117,7 @@ impl DbActorProfile {
|
|||
#[cfg(test)]
|
||||
impl Default for DbActorProfile {
|
||||
fn default() -> Self {
|
||||
let now = Utc::now();
|
||||
Self {
|
||||
id: Uuid::new_v4(),
|
||||
username: "".to_string(),
|
||||
|
@ -130,7 +132,8 @@ impl Default for DbActorProfile {
|
|||
follower_count: 0,
|
||||
following_count: 0,
|
||||
post_count: 0,
|
||||
created_at: Utc::now(),
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
actor_json: None,
|
||||
actor_id: None,
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ async fn nft_monitor_task(
|
|||
};
|
||||
process_nft_events(
|
||||
&blockchain.contract_set.web3,
|
||||
&collectible,
|
||||
collectible,
|
||||
&mut blockchain.sync_state,
|
||||
db_pool,
|
||||
token_waitlist_map,
|
||||
|
@ -74,7 +74,7 @@ async fn subscription_monitor_task(
|
|||
};
|
||||
check_subscriptions(
|
||||
&blockchain.contract_set.web3,
|
||||
&subscription,
|
||||
subscription,
|
||||
&mut blockchain.sync_state,
|
||||
db_pool,
|
||||
).await.map_err(Error::from)
|
||||
|
|
Loading…
Reference in a new issue