Skip to content

Commit 78ec64d

Browse files
committed
database: Change users.gh_encrypted_token column to non-nullable
1 parent 7d4b6fa commit 78ec64d

File tree

16 files changed

+19
-3
lines changed

16 files changed

+19
-3
lines changed

crates/crates_io_database/src/models/user.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct User {
2424
#[serde(skip)]
2525
pub gh_access_token: SecretString,
2626
#[serde(skip)]
27-
pub gh_encrypted_token: Option<Vec<u8>>,
27+
pub gh_encrypted_token: Vec<u8>,
2828
pub account_lock_reason: Option<String>,
2929
pub account_lock_until: Option<DateTime<Utc>>,
3030
pub is_admin: bool,
@@ -96,7 +96,7 @@ pub struct NewUser<'a> {
9696
pub name: Option<&'a str>,
9797
pub gh_avatar: Option<&'a str>,
9898
pub gh_access_token: &'a str,
99-
pub gh_encrypted_token: Option<&'a [u8]>,
99+
pub gh_encrypted_token: &'a [u8],
100100
}
101101

102102
impl NewUser<'_> {

crates/crates_io_database/src/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ diesel::table! {
881881
/// Whether or not the user wants to receive notifications when a package they own is published
882882
publish_notifications -> Bool,
883883
/// Encrypted GitHub access token
884-
gh_encrypted_token -> Nullable<Bytea>,
884+
gh_encrypted_token -> Bytea,
885885
}
886886
}
887887

crates/crates_io_database_dump/src/dump-db.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ publish_notifications = "private"
235235
gh_encrypted_token = "private"
236236
[users.column_defaults]
237237
gh_access_token = "''"
238+
gh_encrypted_token = "''"
238239

239240
[version_downloads]
240241
dependencies = ["versions"]

crates/crates_io_database_dump/src/snapshots/[email protected]

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ BEGIN;
2424
-- Set defaults for non-nullable columns not included in the dump.
2525

2626
ALTER TABLE "users" ALTER COLUMN "gh_access_token" SET DEFAULT '';
27+
ALTER TABLE "users" ALTER COLUMN "gh_encrypted_token" SET DEFAULT '';
2728

2829
-- Truncate all tables.
2930

@@ -67,6 +68,7 @@ BEGIN;
6768
-- Drop the defaults again.
6869

6970
ALTER TABLE "users" ALTER COLUMN "gh_access_token" DROP DEFAULT;
71+
ALTER TABLE "users" ALTER COLUMN "gh_encrypted_token" DROP DEFAULT;
7072

7173
-- Reenable triggers on each table.
7274

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE users ALTER COLUMN gh_encrypted_token DROP NOT NULL;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE users ALTER COLUMN gh_encrypted_token SET NOT NULL;

src/controllers/version/docs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ mod tests {
107107
.gh_id(111)
108108
.gh_login("other_user")
109109
.gh_access_token("token")
110+
.gh_encrypted_token(&[])
110111
.build()
111112
.insert(&mut conn)
112113
.await?;

src/index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ mod tests {
157157
users::gh_login.eq("user1"),
158158
users::gh_id.eq(42),
159159
users::gh_access_token.eq("some random token"),
160+
users::gh_encrypted_token.eq(&[]),
160161
))
161162
.returning(users::id)
162163
.get_result::<i32>(&mut conn)

src/rate_limiter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ mod tests {
707707
.gh_id(0)
708708
.gh_login(gh_login)
709709
.gh_access_token("some random token")
710+
.gh_encrypted_token(&[])
710711
.build()
711712
.insert(conn)
712713
.await

src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn new_user(login: &str) -> NewUser<'_> {
9696
.gh_id(next_gh_id())
9797
.gh_login(login)
9898
.gh_access_token("some random token")
99+
.gh_encrypted_token(&[])
99100
.build()
100101
}
101102

0 commit comments

Comments
 (0)