Replace i32 with u32 for database columns
We never expect to return signed integers and so we shouldn't use a signed type. I think this was a limitation of sqlx.
This commit is contained in:
parent
cfdf0a57b8
commit
29a4baf346
10 changed files with 41 additions and 45 deletions
|
@ -76,7 +76,7 @@ pub async fn validate_api_token<B>(req: Request<B>, next: Next<B>) -> impl IntoR
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct AuthenticatedUserParams {
|
struct AuthenticatedUserParams {
|
||||||
github_user_id: Option<i32>,
|
github_user_id: Option<u32>,
|
||||||
github_login: String,
|
github_login: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,14 +123,14 @@ async fn get_users(
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct CreateUserParams {
|
struct CreateUserParams {
|
||||||
github_user_id: i32,
|
github_user_id: u32,
|
||||||
github_login: String,
|
github_login: String,
|
||||||
email_address: String,
|
email_address: String,
|
||||||
email_confirmation_code: Option<String>,
|
email_confirmation_code: Option<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
admin: bool,
|
admin: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
invite_count: i32,
|
invite_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
|
@ -208,7 +208,7 @@ struct UpdateUserParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_user(
|
async fn update_user(
|
||||||
Path(user_id): Path<i32>,
|
Path(user_id): Path<u32>,
|
||||||
Json(params): Json<UpdateUserParams>,
|
Json(params): Json<UpdateUserParams>,
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
Extension(rpc_server): Extension<Arc<rpc::Server>>,
|
Extension(rpc_server): Extension<Arc<rpc::Server>>,
|
||||||
|
@ -230,7 +230,7 @@ async fn update_user(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn destroy_user(
|
async fn destroy_user(
|
||||||
Path(user_id): Path<i32>,
|
Path(user_id): Path<u32>,
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
app.db.destroy_user(UserId(user_id)).await?;
|
app.db.destroy_user(UserId(user_id)).await?;
|
||||||
|
|
|
@ -156,7 +156,7 @@ impl Database {
|
||||||
pub async fn get_user_by_github_account(
|
pub async fn get_user_by_github_account(
|
||||||
&self,
|
&self,
|
||||||
github_login: &str,
|
github_login: &str,
|
||||||
github_user_id: Option<i32>,
|
github_user_id: Option<u32>,
|
||||||
) -> Result<Option<User>> {
|
) -> Result<Option<User>> {
|
||||||
self.transact(|tx| async {
|
self.transact(|tx| async {
|
||||||
let tx = tx;
|
let tx = tx;
|
||||||
|
@ -896,7 +896,7 @@ impl Database {
|
||||||
user::Entity::update_many()
|
user::Entity::update_many()
|
||||||
.filter(user::Column::Id.eq(id))
|
.filter(user::Column::Id.eq(id))
|
||||||
.set(user::ActiveModel {
|
.set(user::ActiveModel {
|
||||||
invite_count: ActiveValue::set(count as i32),
|
invite_count: ActiveValue::set(count),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.exec(&tx)
|
.exec(&tx)
|
||||||
|
@ -979,9 +979,9 @@ impl Database {
|
||||||
room_participant::ActiveModel {
|
room_participant::ActiveModel {
|
||||||
room_id: ActiveValue::set(room_id),
|
room_id: ActiveValue::set(room_id),
|
||||||
user_id: ActiveValue::set(user_id),
|
user_id: ActiveValue::set(user_id),
|
||||||
answering_connection_id: ActiveValue::set(Some(connection_id.0 as i32)),
|
answering_connection_id: ActiveValue::set(Some(connection_id.0)),
|
||||||
calling_user_id: ActiveValue::set(user_id),
|
calling_user_id: ActiveValue::set(user_id),
|
||||||
calling_connection_id: ActiveValue::set(connection_id.0 as i32),
|
calling_connection_id: ActiveValue::set(connection_id.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.insert(&tx)
|
.insert(&tx)
|
||||||
|
@ -1006,7 +1006,7 @@ impl Database {
|
||||||
room_id: ActiveValue::set(room_id),
|
room_id: ActiveValue::set(room_id),
|
||||||
user_id: ActiveValue::set(called_user_id),
|
user_id: ActiveValue::set(called_user_id),
|
||||||
calling_user_id: ActiveValue::set(calling_user_id),
|
calling_user_id: ActiveValue::set(calling_user_id),
|
||||||
calling_connection_id: ActiveValue::set(calling_connection_id.0 as i32),
|
calling_connection_id: ActiveValue::set(calling_connection_id.0),
|
||||||
initial_project_id: ActiveValue::set(initial_project_id),
|
initial_project_id: ActiveValue::set(initial_project_id),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
@ -1123,7 +1123,7 @@ impl Database {
|
||||||
.and(room_participant::Column::AnsweringConnectionId.is_null()),
|
.and(room_participant::Column::AnsweringConnectionId.is_null()),
|
||||||
)
|
)
|
||||||
.set(room_participant::ActiveModel {
|
.set(room_participant::ActiveModel {
|
||||||
answering_connection_id: ActiveValue::set(Some(connection_id.0 as i32)),
|
answering_connection_id: ActiveValue::set(Some(connection_id.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.exec(&tx)
|
.exec(&tx)
|
||||||
|
@ -1485,14 +1485,14 @@ impl Database {
|
||||||
let project = project::ActiveModel {
|
let project = project::ActiveModel {
|
||||||
room_id: ActiveValue::set(participant.room_id),
|
room_id: ActiveValue::set(participant.room_id),
|
||||||
host_user_id: ActiveValue::set(participant.user_id),
|
host_user_id: ActiveValue::set(participant.user_id),
|
||||||
host_connection_id: ActiveValue::set(connection_id.0 as i32),
|
host_connection_id: ActiveValue::set(connection_id.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.insert(&tx)
|
.insert(&tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
worktree::Entity::insert_many(worktrees.iter().map(|worktree| worktree::ActiveModel {
|
worktree::Entity::insert_many(worktrees.iter().map(|worktree| worktree::ActiveModel {
|
||||||
id: ActiveValue::set(worktree.id as i32),
|
id: ActiveValue::set(WorktreeId(worktree.id as u32)),
|
||||||
project_id: ActiveValue::set(project.id),
|
project_id: ActiveValue::set(project.id),
|
||||||
abs_path: ActiveValue::set(worktree.abs_path.clone()),
|
abs_path: ActiveValue::set(worktree.abs_path.clone()),
|
||||||
root_name: ActiveValue::set(worktree.root_name.clone()),
|
root_name: ActiveValue::set(worktree.root_name.clone()),
|
||||||
|
@ -1505,7 +1505,7 @@ impl Database {
|
||||||
|
|
||||||
project_collaborator::ActiveModel {
|
project_collaborator::ActiveModel {
|
||||||
project_id: ActiveValue::set(project.id),
|
project_id: ActiveValue::set(project.id),
|
||||||
connection_id: ActiveValue::set(connection_id.0 as i32),
|
connection_id: ActiveValue::set(connection_id.0),
|
||||||
user_id: ActiveValue::set(participant.user_id),
|
user_id: ActiveValue::set(participant.user_id),
|
||||||
replica_id: ActiveValue::set(ReplicaId(0)),
|
replica_id: ActiveValue::set(ReplicaId(0)),
|
||||||
is_host: ActiveValue::set(true),
|
is_host: ActiveValue::set(true),
|
||||||
|
@ -1533,7 +1533,7 @@ impl Database {
|
||||||
.one(&tx)
|
.one(&tx)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| anyhow!("project not found"))?;
|
.ok_or_else(|| anyhow!("project not found"))?;
|
||||||
if project.host_connection_id == connection_id.0 as i32 {
|
if project.host_connection_id == connection_id.0 {
|
||||||
let room_id = project.room_id;
|
let room_id = project.room_id;
|
||||||
project::Entity::delete(project.into_active_model())
|
project::Entity::delete(project.into_active_model())
|
||||||
.exec(&tx)
|
.exec(&tx)
|
||||||
|
@ -1562,7 +1562,7 @@ impl Database {
|
||||||
.ok_or_else(|| anyhow!("no such project"))?;
|
.ok_or_else(|| anyhow!("no such project"))?;
|
||||||
|
|
||||||
worktree::Entity::insert_many(worktrees.iter().map(|worktree| worktree::ActiveModel {
|
worktree::Entity::insert_many(worktrees.iter().map(|worktree| worktree::ActiveModel {
|
||||||
id: ActiveValue::set(worktree.id as i32),
|
id: ActiveValue::set(WorktreeId(worktree.id as u32)),
|
||||||
project_id: ActiveValue::set(project.id),
|
project_id: ActiveValue::set(project.id),
|
||||||
abs_path: ActiveValue::set(worktree.abs_path.clone()),
|
abs_path: ActiveValue::set(worktree.abs_path.clone()),
|
||||||
root_name: ActiveValue::set(worktree.root_name.clone()),
|
root_name: ActiveValue::set(worktree.root_name.clone()),
|
||||||
|
@ -1578,7 +1578,7 @@ impl Database {
|
||||||
worktree::Column::Id.is_not_in(
|
worktree::Column::Id.is_not_in(
|
||||||
worktrees
|
worktrees
|
||||||
.iter()
|
.iter()
|
||||||
.map(|worktree| WorktreeId(worktree.id as i32)),
|
.map(|worktree| WorktreeId(worktree.id as u32)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -2093,7 +2093,7 @@ impl Database {
|
||||||
|
|
||||||
if collaborators
|
if collaborators
|
||||||
.iter()
|
.iter()
|
||||||
.any(|collaborator| collaborator.connection_id == connection_id.0 as i32)
|
.any(|collaborator| collaborator.connection_id == connection_id.0)
|
||||||
{
|
{
|
||||||
Ok(collaborators)
|
Ok(collaborators)
|
||||||
} else {
|
} else {
|
||||||
|
@ -2307,8 +2307,8 @@ impl<T> DerefMut for RoomGuard<T> {
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct NewUserParams {
|
pub struct NewUserParams {
|
||||||
pub github_login: String,
|
pub github_login: String,
|
||||||
pub github_user_id: i32,
|
pub github_user_id: u32,
|
||||||
pub invite_count: i32,
|
pub invite_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -2339,21 +2339,19 @@ macro_rules! id_type {
|
||||||
PartialOrd,
|
PartialOrd,
|
||||||
Ord,
|
Ord,
|
||||||
Hash,
|
Hash,
|
||||||
sqlx::Type,
|
|
||||||
Serialize,
|
Serialize,
|
||||||
Deserialize,
|
Deserialize,
|
||||||
)]
|
)]
|
||||||
#[sqlx(transparent)]
|
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct $name(pub i32);
|
pub struct $name(pub u32);
|
||||||
|
|
||||||
impl $name {
|
impl $name {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub const MAX: Self = Self(i32::MAX);
|
pub const MAX: Self = Self(u32::MAX);
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn from_proto(value: u64) -> Self {
|
pub fn from_proto(value: u64) -> Self {
|
||||||
Self(value as i32)
|
Self(value as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
@ -2370,7 +2368,7 @@ macro_rules! id_type {
|
||||||
|
|
||||||
impl From<$name> for sea_query::Value {
|
impl From<$name> for sea_query::Value {
|
||||||
fn from(value: $name) -> Self {
|
fn from(value: $name) -> Self {
|
||||||
sea_query::Value::Int(Some(value.0))
|
sea_query::Value::Unsigned(Some(value.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2380,7 +2378,7 @@ macro_rules! id_type {
|
||||||
pre: &str,
|
pre: &str,
|
||||||
col: &str,
|
col: &str,
|
||||||
) -> Result<Self, sea_orm::TryGetError> {
|
) -> Result<Self, sea_orm::TryGetError> {
|
||||||
Ok(Self(i32::try_get(res, pre, col)?))
|
Ok(Self(u32::try_get(res, pre, col)?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2420,11 +2418,11 @@ macro_rules! id_type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn array_type() -> sea_query::ArrayType {
|
fn array_type() -> sea_query::ArrayType {
|
||||||
sea_query::ArrayType::Int
|
sea_query::ArrayType::Unsigned
|
||||||
}
|
}
|
||||||
|
|
||||||
fn column_type() -> sea_query::ColumnType {
|
fn column_type() -> sea_query::ColumnType {
|
||||||
sea_query::ColumnType::Integer(None)
|
sea_query::ColumnType::Unsigned(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub struct Model {
|
||||||
pub id: ProjectId,
|
pub id: ProjectId,
|
||||||
pub room_id: RoomId,
|
pub room_id: RoomId,
|
||||||
pub host_user_id: UserId,
|
pub host_user_id: UserId,
|
||||||
pub host_connection_id: i32,
|
pub host_connection_id: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub struct Model {
|
||||||
#[sea_orm(primary_key)]
|
#[sea_orm(primary_key)]
|
||||||
pub id: ProjectCollaboratorId,
|
pub id: ProjectCollaboratorId,
|
||||||
pub project_id: ProjectId,
|
pub project_id: ProjectId,
|
||||||
pub connection_id: i32,
|
pub connection_id: u32,
|
||||||
pub user_id: UserId,
|
pub user_id: UserId,
|
||||||
pub replica_id: ReplicaId,
|
pub replica_id: ReplicaId,
|
||||||
pub is_host: bool,
|
pub is_host: bool,
|
||||||
|
|
|
@ -8,12 +8,12 @@ pub struct Model {
|
||||||
pub id: RoomParticipantId,
|
pub id: RoomParticipantId,
|
||||||
pub room_id: RoomId,
|
pub room_id: RoomId,
|
||||||
pub user_id: UserId,
|
pub user_id: UserId,
|
||||||
pub answering_connection_id: Option<i32>,
|
pub answering_connection_id: Option<u32>,
|
||||||
pub location_kind: Option<i32>,
|
pub location_kind: Option<u32>,
|
||||||
pub location_project_id: Option<ProjectId>,
|
pub location_project_id: Option<ProjectId>,
|
||||||
pub initial_project_id: Option<ProjectId>,
|
pub initial_project_id: Option<ProjectId>,
|
||||||
pub calling_user_id: UserId,
|
pub calling_user_id: UserId,
|
||||||
pub calling_connection_id: i32,
|
pub calling_connection_id: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
|
|
@ -430,7 +430,7 @@ async fn test_fuzzy_search_users() {
|
||||||
false,
|
false,
|
||||||
NewUserParams {
|
NewUserParams {
|
||||||
github_login: github_login.into(),
|
github_login: github_login.into(),
|
||||||
github_user_id: i as i32,
|
github_user_id: i as u32,
|
||||||
invite_count: 0,
|
invite_count: 0,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,11 +8,11 @@ pub struct Model {
|
||||||
#[sea_orm(primary_key)]
|
#[sea_orm(primary_key)]
|
||||||
pub id: UserId,
|
pub id: UserId,
|
||||||
pub github_login: String,
|
pub github_login: String,
|
||||||
pub github_user_id: Option<i32>,
|
pub github_user_id: Option<u32>,
|
||||||
pub email_address: Option<String>,
|
pub email_address: Option<String>,
|
||||||
pub admin: bool,
|
pub admin: bool,
|
||||||
pub invite_code: Option<String>,
|
pub invite_code: Option<String>,
|
||||||
pub invite_count: i32,
|
pub invite_count: u32,
|
||||||
pub inviter_id: Option<UserId>,
|
pub inviter_id: Option<UserId>,
|
||||||
pub connected_once: bool,
|
pub connected_once: bool,
|
||||||
pub metrics_id: Uuid,
|
pub metrics_id: Uuid,
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
|
use super::{ProjectId, WorktreeId};
|
||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
use super::ProjectId;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
||||||
#[sea_orm(table_name = "worktrees")]
|
#[sea_orm(table_name = "worktrees")]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[sea_orm(primary_key)]
|
#[sea_orm(primary_key)]
|
||||||
pub id: i32,
|
pub id: WorktreeId,
|
||||||
#[sea_orm(primary_key)]
|
#[sea_orm(primary_key)]
|
||||||
pub project_id: ProjectId,
|
pub project_id: ProjectId,
|
||||||
pub abs_path: String,
|
pub abs_path: String,
|
||||||
pub root_name: String,
|
pub root_name: String,
|
||||||
pub visible: bool,
|
pub visible: bool,
|
||||||
pub scan_id: i64,
|
pub scan_id: u32,
|
||||||
pub is_complete: bool,
|
pub is_complete: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5383,7 +5383,7 @@ async fn test_random_collaboration(
|
||||||
false,
|
false,
|
||||||
NewUserParams {
|
NewUserParams {
|
||||||
github_login: username.clone(),
|
github_login: username.clone(),
|
||||||
github_user_id: (ix + 1) as i32,
|
github_user_id: (ix + 1) as u32,
|
||||||
invite_count: 0,
|
invite_count: 0,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -1008,7 +1008,7 @@ async fn join_project(
|
||||||
let collaborators = project
|
let collaborators = project
|
||||||
.collaborators
|
.collaborators
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|collaborator| collaborator.connection_id != session.connection_id.0 as i32)
|
.filter(|collaborator| collaborator.connection_id != session.connection_id.0)
|
||||||
.map(|collaborator| proto::Collaborator {
|
.map(|collaborator| proto::Collaborator {
|
||||||
peer_id: collaborator.connection_id as u32,
|
peer_id: collaborator.connection_id as u32,
|
||||||
replica_id: collaborator.replica_id.0 as u32,
|
replica_id: collaborator.replica_id.0 as u32,
|
||||||
|
@ -1313,8 +1313,7 @@ async fn save_buffer(
|
||||||
.await
|
.await
|
||||||
.project_collaborators(project_id, session.connection_id)
|
.project_collaborators(project_id, session.connection_id)
|
||||||
.await?;
|
.await?;
|
||||||
collaborators
|
collaborators.retain(|collaborator| collaborator.connection_id != session.connection_id.0);
|
||||||
.retain(|collaborator| collaborator.connection_id != session.connection_id.0 as i32);
|
|
||||||
let project_connection_ids = collaborators
|
let project_connection_ids = collaborators
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|collaborator| ConnectionId(collaborator.connection_id as u32));
|
.map(|collaborator| ConnectionId(collaborator.connection_id as u32));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue