Skip to content

Commit

Permalink
extend owners.avatar field length
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar authored and GuillaumeGomez committed Dec 19, 2024
1 parent 5efa5e0 commit c595fb1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions migrations/20241219091521_owner-avatar-longer.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE owners SET avatar = '' WHERE LENGTH(avatar) > 255;
ALTER TABLE owners ALTER COLUMN avatar TYPE VARCHAR(255);
1 change: 1 addition & 0 deletions migrations/20241219091521_owner-avatar-longer.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE owners ALTER COLUMN avatar TYPE TEXT;
40 changes: 40 additions & 0 deletions src/db/add_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,46 @@ mod test {
})
}

#[test]
fn new_owner_long_avatar() {
async_wrapper(|env| async move {
let mut conn = env.async_db().await.async_conn().await;
let crate_id = initialize_crate(&mut conn, "krate").await?;

let owner1 = CrateOwner {
avatar: "avatar".repeat(100),
login: "login".into(),
kind: OwnerKind::User,
};

update_owners_in_database(&mut conn, &[owner1.clone()], crate_id).await?;

let owner_def = sqlx::query!(
r#"SELECT login, avatar, kind as "kind: OwnerKind"
FROM owners"#
)
.fetch_one(&mut *conn)
.await?;
assert_eq!(owner_def.login, owner1.login);
assert_eq!(owner_def.avatar, owner1.avatar);
assert_eq!(owner_def.kind, owner1.kind);

let owner_rel = sqlx::query!(
"SELECT o.login
FROM owners o, owner_rels r
WHERE
o.id = r.oid AND
r.cid = $1",
crate_id.0
)
.fetch_one(&mut *conn)
.await?;
assert_eq!(owner_rel.login, owner1.login);

Ok(())
})
}

#[test]
fn new_owners() {
async_wrapper(|env| async move {
Expand Down

0 comments on commit c595fb1

Please sign in to comment.