Skip to content

Commit 847ca22

Browse files
authored
database: Add crate_owner_invitations.expires_at column (#10553)
1 parent 653b003 commit 847ca22

File tree

6 files changed

+17
-2
lines changed

6 files changed

+17
-2
lines changed

crates/crates_io_database/src/schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ diesel::table! {
221221
///
222222
/// (Automatically generated by Diesel.)
223223
token -> Text,
224+
/// Point in time at which the invitation expires/expired.
225+
expires_at -> Nullable<Timestamptz>,
224226
}
225227
}
226228

crates/crates_io_database_dump/src/dump-db.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ invited_by_user_id = "private"
5959
crate_id = "private"
6060
created_at = "private"
6161
token = "private"
62+
expires_at = "private"
6263

6364
[crate_owners]
6465
dependencies = ["crates", "users"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table crate_owner_invitations drop column expires_at;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
alter table crate_owner_invitations add column expires_at timestamptz;
2+
3+
comment on column public.crate_owner_invitations.expires_at is 'Point in time at which the invitation expires/expired.'
4+
5+
-- to be performed manually after the migration:
6+
--
7+
-- update table crate_owner_invitations set expires_at = now() + interval '30 day';

src/models/crate_owner_invitation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use chrono::{NaiveDateTime, Utc};
1+
use chrono::{DateTime, NaiveDateTime, Utc};
22
use diesel::prelude::*;
33
use diesel_async::scoped_futures::ScopedFutureExt;
44
use diesel_async::{AsyncConnection, AsyncPgConnection, RunQueryDsl};
@@ -20,6 +20,7 @@ pub struct NewCrateOwnerInvitation {
2020
pub invited_user_id: i32,
2121
pub invited_by_user_id: i32,
2222
pub crate_id: i32,
23+
pub expires_at: DateTime<Utc>,
2324
}
2425

2526
impl NewCrateOwnerInvitation {
@@ -82,6 +83,7 @@ pub struct CrateOwnerInvitation {
8283
pub created_at: NaiveDateTime,
8384
#[diesel(deserialize_as = String)]
8485
pub token: SecretString,
86+
pub expires_at: Option<DateTime<Utc>>,
8587
}
8688

8789
impl CrateOwnerInvitation {

src/models/krate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use chrono::NaiveDateTime;
1+
use chrono::{NaiveDateTime, Utc};
22
use diesel::associations::Identifiable;
33
use diesel::dsl;
44
use diesel::pg::Pg;
@@ -400,10 +400,12 @@ impl Crate {
400400
match owner {
401401
// Users are invited and must accept before being added
402402
Owner::User(user) => {
403+
let expires_at = Utc::now() + app.config.ownership_invitations_expiration;
403404
let invite = NewCrateOwnerInvitation {
404405
invited_user_id: user.id,
405406
invited_by_user_id: req_user.id,
406407
crate_id: self.id,
408+
expires_at,
407409
};
408410

409411
let creation_ret = invite

0 commit comments

Comments
 (0)