Skip to content

Commit

Permalink
migrate submissions id to bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
Kriptikz committed Sep 20, 2024
1 parent 03abca8 commit 8bebabb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE submissions MODIFY COLUMN id INT NOT NULL AUTO_INCREMENT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE submissions MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT
6 changes: 3 additions & 3 deletions src/app_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl AppDatabase {
};
}

pub async fn get_submission_id_with_nonce(&self, nonce: u64) -> Result<i32, AppDatabaseError> {
pub async fn get_submission_id_with_nonce(&self, nonce: u64) -> Result<i64, AppDatabaseError> {
if let Ok(db_conn) = self.connection_pool.get().await {
let res = db_conn
.interact(move |conn: &mut MysqlConnection| {
Expand Down Expand Up @@ -272,14 +272,14 @@ impl AppDatabase {
pub async fn update_challenge_rewards(
&self,
challenge: Vec<u8>,
submission_id: i32,
submission_id: i64,
rewards: u64,
) -> Result<(), AppDatabaseError> {
if let Ok(db_conn) = self.connection_pool.get().await {
let res = db_conn.interact(move |conn: &mut MysqlConnection| {
diesel::sql_query("UPDATE challenges SET rewards_earned = ?, submission_id = ? WHERE challenge = ?")
.bind::<Nullable<Unsigned<BigInt>>, _>(Some(rewards))
.bind::<Nullable<Integer>, _>(submission_id)
.bind::<Nullable<BigInt>, _>(submission_id)
.bind::<Binary, _>(challenge)
.execute(conn)
}).await;
Expand Down
8 changes: 4 additions & 4 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub struct Pool {
#[diesel(table_name = crate::schema::submissions)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Submission {
pub id: i32,
pub id: i64,
pub miner_id: i32,
pub challenge_id: i32,
pub nonce: u64,
Expand All @@ -103,8 +103,8 @@ pub struct Submission {

#[derive(Debug, Deserialize, Serialize, QueryableByName)]
pub struct SubmissionWithPubkey {
#[diesel(sql_type = Integer)]
pub id: i32,
#[diesel(sql_type = BigInt)]
pub id: i64,
#[diesel(sql_type = Integer)]
pub miner_id: i32,
#[diesel(sql_type = Integer)]
Expand Down Expand Up @@ -133,7 +133,7 @@ pub struct InsertSubmission {
#[diesel(table_name = crate::schema::submissions)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct SubmissionWithId {
pub id: i32,
pub id: i64,
}

#[derive(Debug, Serialize, Deserialize, Queryable, Selectable, QueryableByName)]
Expand Down
2 changes: 1 addition & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ diesel::table! {

diesel::table! {
submissions (id) {
id -> Integer,
id -> Bigint,
miner_id -> Integer,
challenge_id -> Integer,
difficulty -> Tinyint,
Expand Down

0 comments on commit 8bebabb

Please sign in to comment.