diff --git a/crates/core/src/database/auth.rs b/crates/core/src/database/auth.rs index a7be386..39e4ccd 100644 --- a/crates/core/src/database/auth.rs +++ b/crates/core/src/database/auth.rs @@ -32,15 +32,15 @@ impl DataManager { salt: get!(x->4(String)), settings: serde_json::from_str(&get!(x->5(String)).to_string()).unwrap(), tokens: serde_json::from_str(&get!(x->6(String)).to_string()).unwrap(), - permissions: FinePermission::from_bits(get!(x->7(i64)) as u32).unwrap(), - is_verified: if get!(x->8(i64)) as i8 == 1 { + permissions: FinePermission::from_bits(get!(x->7(i32)) as u32).unwrap(), + is_verified: if get!(x->8(i32)) as i8 == 1 { true } else { false }, - notification_count: get!(x->9(i64)) as usize, - follower_count: get!(x->10(i64)) as usize, - following_count: get!(x->11(i64)) as usize, + notification_count: get!(x->9(i32)) as usize, + follower_count: get!(x->10(i32)) as usize, + following_count: get!(x->11(i32)) as usize, last_seen: get!(x->12(i64)) as usize, } } @@ -118,11 +118,11 @@ impl DataManager { &data.salt, &serde_json::to_string(&data.settings).unwrap(), &serde_json::to_string(&data.tokens).unwrap(), - &(FinePermission::DEFAULT.bits() as i64), - &(if data.is_verified { 1 as i64 } else { 0 as i64 }), - &(0 as i64), - &(0 as i64), - &(0 as i64), + &(FinePermission::DEFAULT.bits() as i32), + &(if data.is_verified { 1 as i32 } else { 0 as i32 }), + &(0 as i32), + &(0 as i32), + &(0 as i32), &(data.last_seen as i64), ] ); @@ -253,7 +253,7 @@ impl DataManager { let res = execute!( &conn, "UPDATE users SET verified = $1 WHERE id = $2", - params![&(if x { 1 } else { 0 } as i64), &(id as i64)] + params![&(if x { 1 } else { 0 } as i32), &(id as i64)] ); if let Err(e) = res { @@ -367,7 +367,7 @@ impl DataManager { let res = execute!( &conn, "UPDATE users SET permissions = $1 WHERE id = $2", - params![&(role.bits() as i64), &(id as i64)] + params![&(role.bits() as i32), &(id as i64)] ); if let Err(e) = res { diff --git a/crates/core/src/database/communities.rs b/crates/core/src/database/communities.rs index 5025cd8..3a52a67 100644 --- a/crates/core/src/database/communities.rs +++ b/crates/core/src/database/communities.rs @@ -35,10 +35,10 @@ impl DataManager { write_access: serde_json::from_str(&get!(x->6(String))).unwrap(), join_access: serde_json::from_str(&get!(x->7(String))).unwrap(), // likes - likes: get!(x->8(i64)) as isize, - dislikes: get!(x->9(i64)) as isize, + likes: get!(x->8(i32)) as isize, + dislikes: get!(x->9(i32)) as isize, // counts - member_count: get!(x->10(i64)) as usize, + member_count: get!(x->10(i32)) as usize, } } @@ -211,9 +211,9 @@ impl DataManager { &serde_json::to_string(&data.read_access).unwrap().as_str(), &serde_json::to_string(&data.write_access).unwrap().as_str(), &serde_json::to_string(&data.join_access).unwrap().as_str(), - &(0 as i64), - &(0 as i64), - &(1 as i64) + &(0 as i32), + &(0 as i32), + &(1 as i32) ] ); diff --git a/crates/core/src/database/drivers/postgres.rs b/crates/core/src/database/drivers/postgres.rs index d97c33e..7e739c1 100644 --- a/crates/core/src/database/drivers/postgres.rs +++ b/crates/core/src/database/drivers/postgres.rs @@ -35,18 +35,17 @@ impl DataManager { /// Create a new [`DataManager`] (and init database). pub async fn new(config: Config) -> Result { - let manager = PostgresConnectionManager::new( - PgConfig::from_str(&format!( - "postgresql://{}:{}@{}/{}?target_session_attrs=read-write", - config.database.user, - config.database.password, - config.database.url, - config.database.name - )) - .unwrap(), - NoTls, + let con_url = &format!( + "postgresql://{}:{}@{}/{}?target_session_attrs=read-write", + config.database.user, + config.database.password, + config.database.url, + config.database.name ); + println!("attempting connection on: {con_url}"); + let manager = PostgresConnectionManager::new(PgConfig::from_str(con_url).unwrap(), NoTls); + let pool = Pool::builder().max_size(15).build(manager).await.unwrap(); Ok(Self( config.clone(), diff --git a/crates/core/src/database/drivers/sql/create_communities.sql b/crates/core/src/database/drivers/sql/create_communities.sql index c2252af..e245eef 100644 --- a/crates/core/src/database/drivers/sql/create_communities.sql +++ b/crates/core/src/database/drivers/sql/create_communities.sql @@ -8,8 +8,8 @@ CREATE TABLE IF NOT EXISTS communities ( write_access TEXT NOT NULL, join_access TEXT NOT NULL, -- likes - likes BIGINT NOT NULL, - dislikes BIGINT NOT NULL, + likes INT NOT NULL, + dislikes INT NOT NULL, -- counts - member_count BIGINT NOT NULL + member_count INT NOT NULL ) diff --git a/crates/core/src/database/drivers/sql/create_memberships.sql b/crates/core/src/database/drivers/sql/create_memberships.sql index 7461c1c..3f0e2e0 100644 --- a/crates/core/src/database/drivers/sql/create_memberships.sql +++ b/crates/core/src/database/drivers/sql/create_memberships.sql @@ -3,5 +3,5 @@ CREATE TABLE IF NOT EXISTS memberships ( created BIGINT NOT NULL, owner BIGINT NOT NULL, community BIGINT NOT NULL, - role BIGINT NOT NULL + role INT NOT NULL ) diff --git a/crates/core/src/database/drivers/sql/create_notifications.sql b/crates/core/src/database/drivers/sql/create_notifications.sql index 5933be7..a680bab 100644 --- a/crates/core/src/database/drivers/sql/create_notifications.sql +++ b/crates/core/src/database/drivers/sql/create_notifications.sql @@ -4,5 +4,5 @@ CREATE TABLE IF NOT EXISTS notifications ( title TEXT NOT NULL, content TEXT NOT NULL, owner BIGINT NOT NULL, - read BIGINT NOT NULL + read INT NOT NULL ) diff --git a/crates/core/src/database/drivers/sql/create_posts.sql b/crates/core/src/database/drivers/sql/create_posts.sql index 4d455a0..92bbc40 100644 --- a/crates/core/src/database/drivers/sql/create_posts.sql +++ b/crates/core/src/database/drivers/sql/create_posts.sql @@ -5,10 +5,10 @@ CREATE TABLE IF NOT EXISTS posts ( owner BIGINT NOT NULL, community BIGINT NOT NULL, context TEXT NOT NULL, - replying_to BIGINT, -- the ID of the post this is a comment on... NULL means it isn't a reply + replying_to BIGINT, -- the ID of the post this is a comment on... 0 means it isn't a reply -- likes - likes BIGINT NOT NULL, - dislikes BIGINT NOT NULL, + likes INT NOT NULL, + dislikes INT NOT NULL, -- other counts - comment_count BIGINT NOT NULL + comment_count INT NOT NULL ) diff --git a/crates/core/src/database/drivers/sql/create_reactions.sql b/crates/core/src/database/drivers/sql/create_reactions.sql index 3e60fa3..8b4565f 100644 --- a/crates/core/src/database/drivers/sql/create_reactions.sql +++ b/crates/core/src/database/drivers/sql/create_reactions.sql @@ -4,5 +4,5 @@ CREATE TABLE IF NOT EXISTS reactions ( owner BIGINT NOT NULL, asset BIGINT NOT NULL, asset_type TEXT NOT NULL, - is_like BIGINT NOT NULL + is_like INT NOT NULL ) diff --git a/crates/core/src/database/drivers/sql/create_users.sql b/crates/core/src/database/drivers/sql/create_users.sql index 7209117..e4d7c19 100644 --- a/crates/core/src/database/drivers/sql/create_users.sql +++ b/crates/core/src/database/drivers/sql/create_users.sql @@ -6,10 +6,10 @@ CREATE TABLE IF NOT EXISTS users ( salt TEXT NOT NULL, settings TEXT NOT NULL, tokens TEXT NOT NULL, - permissions BIGINT NOT NULL, - verified BIGINT NOT NULL, - notification_count BIGINT NOT NULL, - follower_count BIGINT NOT NULL, - following_count BIGINT NOT NULL, + permissions INT NOT NULL, + verified INT NOT NULL, + notification_count INT NOT NULL, + follower_count INT NOT NULL, + following_count INT NOT NULL, last_seen BIGINT NOT NULL ) diff --git a/crates/core/src/database/memberships.rs b/crates/core/src/database/memberships.rs index 475d05c..38d1832 100644 --- a/crates/core/src/database/memberships.rs +++ b/crates/core/src/database/memberships.rs @@ -28,7 +28,7 @@ impl DataManager { created: get!(x->1(i64)) as usize, owner: get!(x->2(i64)) as usize, community: get!(x->3(i64)) as usize, - role: CommunityPermission::from_bits(get!(x->4(i64)) as u32).unwrap(), + role: CommunityPermission::from_bits(get!(x->4(i32)) as u32).unwrap(), } } @@ -147,7 +147,7 @@ impl DataManager { &(data.created as i64), &(data.owner as i64), &(data.community as i64), - &(data.role.bits() as i64), + &(data.role.bits() as i32), ] ); diff --git a/crates/core/src/database/notifications.rs b/crates/core/src/database/notifications.rs index cb9e8a7..e7befc4 100644 --- a/crates/core/src/database/notifications.rs +++ b/crates/core/src/database/notifications.rs @@ -21,7 +21,7 @@ impl DataManager { title: get!(x->2(String)), content: get!(x->3(String)), owner: get!(x->4(i64)) as usize, - read: if get!(x->5(i64)) as i8 == 1 { + read: if get!(x->5(i32)) as i8 == 1 { true } else { false @@ -71,7 +71,7 @@ impl DataManager { &data.title, &data.content, &(data.owner as i64), - &(if data.read { 1 } else { 0 } as i64) + &(if data.read { 1 } else { 0 } as i32) ] ); @@ -162,7 +162,7 @@ impl DataManager { let res = execute!( &conn, "UPDATE notifications SET read = $1 WHERE id = $2", - params![&(if new_read { 1 } else { 0 } as i64), &(id as i64)] + params![&(if new_read { 1 } else { 0 } as i32), &(id as i64)] ); if let Err(e) = res { diff --git a/crates/core/src/database/posts.rs b/crates/core/src/database/posts.rs index 64092df..d1a3cb3 100644 --- a/crates/core/src/database/posts.rs +++ b/crates/core/src/database/posts.rs @@ -38,10 +38,10 @@ impl DataManager { None }, // likes - likes: get!(x->7(i64)) as isize, - dislikes: get!(x->8(i64)) as isize, + likes: get!(x->7(i32)) as isize, + dislikes: get!(x->8(i32)) as isize, // other counts - comment_count: get!(x->9(i64)) as usize, + comment_count: get!(x->9(i32)) as usize, } } @@ -407,9 +407,9 @@ impl DataManager { } else { 0 as i64 }, - &(0 as i64), - &(0 as i64), - &(0 as i64) + &(0 as i32), + &(0 as i32), + &(0 as i32) ] ); diff --git a/crates/core/src/database/reactions.rs b/crates/core/src/database/reactions.rs index e376656..760c197 100644 --- a/crates/core/src/database/reactions.rs +++ b/crates/core/src/database/reactions.rs @@ -26,7 +26,7 @@ impl DataManager { owner: get!(x->2(i64)) as usize, asset: get!(x->3(i64)) as usize, asset_type: serde_json::from_str(&get!(x->4(String))).unwrap(), - is_like: if get!(x->5(i64)) as i8 == 1 { + is_like: if get!(x->5(i32)) as i8 == 1 { true } else { false @@ -80,7 +80,7 @@ impl DataManager { &(data.owner as i64), &(data.asset as i64), &serde_json::to_string(&data.asset_type).unwrap().as_str(), - &(if data.is_like { 1 } else { 0 } as i64) + &(if data.is_like { 1 } else { 0 } as i32) ] );