fix: ci schema-check failing

This commit is contained in:
FrenchGithubUser
2025-12-07 00:16:11 +01:00
parent 96118edf6b
commit af9eceb838
12 changed files with 297 additions and 194 deletions

View File

@@ -0,0 +1,56 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n id,\n upload_factor,\n download_factor,\n seeders,\n leechers,\n times_completed,\n CASE\n WHEN deleted_at IS NOT NULL THEN TRUE\n ELSE FALSE\n END AS \"is_deleted!\"\n FROM torrents\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "upload_factor",
"type_info": "Int2"
},
{
"ordinal": 2,
"name": "download_factor",
"type_info": "Int2"
},
{
"ordinal": 3,
"name": "seeders",
"type_info": "Int8"
},
{
"ordinal": 4,
"name": "leechers",
"type_info": "Int8"
},
{
"ordinal": 5,
"name": "times_completed",
"type_info": "Int4"
},
{
"ordinal": 6,
"name": "is_deleted!",
"type_info": "Bool"
}
],
"parameters": {
"Left": []
},
"nullable": [
false,
false,
false,
false,
false,
false,
null
]
},
"hash": "46d7eee133e0653d9f11ab67f5d6faec7050c9b4c6a8c78e2097015d3e0fb7fb"
}

View File

@@ -0,0 +1,26 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n id,\n passkey as \"passkey: Passkey\"\n FROM users\n WHERE banned = FALSE\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "passkey: Passkey",
"type_info": "Varchar"
}
],
"parameters": {
"Left": []
},
"nullable": [
false,
false
]
},
"hash": "4edda78ffd766d9ec15eb015fe5b985755924b0f0b44d5cf9411059cfbc5c757"
}

View File

@@ -0,0 +1,26 @@
{
"db_name": "PostgreSQL",
"query": "\n INSERT INTO peers (\n peer_id,\n ip,\n port,\n agent,\n uploaded,\n downloaded,\n \"left\",\n active,\n seeder,\n created_at,\n updated_at,\n torrent_id,\n user_id\n )\n SELECT\n t.peer_id,\n t.ip,\n t.port,\n t.agent,\n t.uploaded,\n t.downloaded,\n t.\"left\",\n t.active,\n t.seeder,\n -- stored as timestamp without time zone in DB\n (t.created_at AT TIME ZONE 'UTC')::timestamp,\n (t.updated_at AT TIME ZONE 'UTC')::timestamp,\n t.torrent_id,\n t.user_id\n FROM (\n SELECT * FROM unnest(\n $1::bytea[],\n $2::inet[],\n $3::int[],\n $4::varchar[],\n $5::bigint[],\n $6::bigint[],\n $7::bigint[],\n $8::boolean[],\n $9::boolean[],\n $10::timestamptz[],\n $11::timestamptz[],\n $12::int[],\n $13::int[]\n ) AS t(\n peer_id,\n ip,\n port,\n agent,\n uploaded,\n downloaded,\n \"left\",\n active,\n seeder,\n created_at,\n updated_at,\n torrent_id,\n user_id\n )\n ) AS t\n ON CONFLICT (user_id, torrent_id, peer_id) DO UPDATE SET\n ip = EXCLUDED.ip,\n port = EXCLUDED.port,\n agent = EXCLUDED.agent,\n uploaded = EXCLUDED.uploaded,\n downloaded = EXCLUDED.downloaded,\n \"left\" = EXCLUDED.\"left\",\n active = EXCLUDED.active,\n seeder = EXCLUDED.seeder,\n updated_at = EXCLUDED.updated_at\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"ByteaArray",
"InetArray",
"Int4Array",
"VarcharArray",
"Int8Array",
"Int8Array",
"Int8Array",
"BoolArray",
"BoolArray",
"TimestamptzArray",
"TimestamptzArray",
"Int4Array",
"Int4Array"
]
},
"nullable": []
},
"hash": "599587c7ce69b090843274603171c411af859ae256fc01eaf66af2aa2a922900"
}

View File

@@ -0,0 +1,18 @@
{
"db_name": "PostgreSQL",
"query": "\n UPDATE users\n SET\n uploaded = uploaded + updates.uploaded_delta,\n downloaded = downloaded + updates.downloaded_delta,\n real_uploaded = real_uploaded + updates.uploaded_delta,\n real_downloaded = real_downloaded + updates.downloaded_delta\n FROM (\n SELECT * FROM unnest($1::int[], $2::bigint[], $3::bigint[], $4::bigint[], $5::bigint[]) AS\n t(user_id, uploaded_delta, downloaded_delta, real_uploaded_delta, real_downloaded_delta)\n ) AS updates\n WHERE users.id = updates.user_id\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4Array",
"Int8Array",
"Int8Array",
"Int8Array",
"Int8Array"
]
},
"nullable": []
},
"hash": "68c566af855b2cb1e46b77cd829934488b1d4da1086f74b7491d7468753f539a"
}

View File

@@ -0,0 +1,16 @@
{
"db_name": "PostgreSQL",
"query": "\n DELETE FROM peers\n WHERE (user_id, torrent_id, peer_id) IN (\n SELECT t.user_id, t.torrent_id, t.peer_id\n FROM (\n SELECT * FROM unnest(\n $1::int[],\n $2::int[],\n $3::bytea[]\n ) AS t(user_id, torrent_id, peer_id)\n ) AS t\n )\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4Array",
"Int4Array",
"ByteaArray"
]
},
"nullable": []
},
"hash": "7da73662a96a68e239d011598ace3bc5b287a82c5b0c34ce9543842a1bed0ea4"
}

View File

@@ -0,0 +1,38 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n id,\n passkey as \"passkey: Passkey\",\n 0::INT AS \"num_seeding!\",\n 0::INT AS \"num_leeching!\"\n FROM users\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "passkey: Passkey",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "num_seeding!",
"type_info": "Int4"
},
{
"ordinal": 3,
"name": "num_leeching!",
"type_info": "Int4"
}
],
"parameters": {
"Left": []
},
"nullable": [
false,
false,
null,
null
]
},
"hash": "bb66b1b13123112781db47d98cd02b28d11470b7c84d7aec56ec102fee20264d"
}

View File

@@ -0,0 +1,17 @@
{
"db_name": "PostgreSQL",
"query": "\n UPDATE torrents\n SET\n seeders = seeders + updates.seeder_delta,\n leechers = leechers + updates.leecher_delta,\n times_completed = times_completed + updates.times_completed_delta\n FROM (\n SELECT * FROM unnest($1::int[], $2::bigint[], $3::bigint[], $4::bigint[]) AS\n t(torrent_id, seeder_delta, leecher_delta, times_completed_delta)\n ) AS updates\n WHERE torrents.id = updates.torrent_id\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4Array",
"Int8Array",
"Int8Array",
"Int8Array"
]
},
"nullable": []
},
"hash": "c45f235654a1b2aa8c849c5644443fe34ea7a4dd976fe6b4405e7b4a585a1325"
}

View File

@@ -0,0 +1,26 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n id,\n info_hash as \"info_hash: InfoHash\"\n FROM torrents\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "info_hash: InfoHash",
"type_info": "Bytea"
}
],
"parameters": {
"Left": []
},
"nullable": [
false,
false
]
},
"hash": "d94c7cf9c02a4f060345d02ac4bd2434069fc46d43e6f3e7e3618737c2dcd547"
}

View File

@@ -0,0 +1,74 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n peers.ip AS \"ip_address: IpAddr\",\n peers.user_id AS \"user_id\",\n peers.torrent_id AS \"torrent_id\",\n peers.port AS \"port\",\n peers.seeder AS \"is_seeder: bool\",\n peers.active AS \"is_active: bool\",\n peers.updated_at AS \"updated_at: DateTime<Utc>\",\n peers.uploaded AS \"uploaded\",\n peers.downloaded AS \"downloaded\",\n peers.peer_id AS \"peer_id: PeerId\"\n FROM peers\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "ip_address: IpAddr",
"type_info": "Inet"
},
{
"ordinal": 1,
"name": "user_id",
"type_info": "Int4"
},
{
"ordinal": 2,
"name": "torrent_id",
"type_info": "Int4"
},
{
"ordinal": 3,
"name": "port",
"type_info": "Int4"
},
{
"ordinal": 4,
"name": "is_seeder: bool",
"type_info": "Bool"
},
{
"ordinal": 5,
"name": "is_active: bool",
"type_info": "Bool"
},
{
"ordinal": 6,
"name": "updated_at: DateTime<Utc>",
"type_info": "Timestamp"
},
{
"ordinal": 7,
"name": "uploaded",
"type_info": "Int8"
},
{
"ordinal": 8,
"name": "downloaded",
"type_info": "Int8"
},
{
"ordinal": 9,
"name": "peer_id: PeerId",
"type_info": "Bytea"
}
],
"parameters": {
"Left": []
},
"nullable": [
false,
false,
false,
false,
false,
false,
true,
false,
false,
false
]
},
"hash": "f6d849721ff84614c129c14455d9a6adbe0ad29b7876963d5bd9015c0f73ba9d"
}

View File

@@ -9,7 +9,6 @@ pub mod gift_repository;
pub mod invitation_repository;
pub mod master_group_repository;
pub mod notification_repository;
pub mod peer_repository;
pub mod series_repository;
pub mod staff_pm_repository;
pub mod stats_repository;

View File

@@ -1,161 +0,0 @@
use crate::connection_pool::ConnectionPool;
// use crate::models::peer::PeerStatus;
// use arcadia_common::error::Result;
// use arcadia_common::models::tracker::announce::{Announce, Peer};
// use sqlx::types::ipnetwork::IpNetwork;
// use std::borrow::Borrow;
// use crate::models;
impl ConnectionPool {
// pub async fn get_user_peers(&self, user_id: i32) -> Vec<models::peer::Peer> {
// sqlx::query_as!(
// models::peer::Peer,
// r#"
// SELECT
// ip,
// port,
// agent,
// MIN(first_seen_at) as "first_seen_at!",
// MAX(last_seen_at) as "last_seen_at!",
// SUM(real_uploaded)::BIGINT as "real_uploaded!",
// SUM(real_downloaded)::BIGINT as "real_downloaded!",
// status::peer_status_enum as "status!: PeerStatus"
// FROM peers
// WHERE user_id = $1
// GROUP BY (peer_id, ip, port, agent, status)
// "#,
// user_id
// )
// .fetch_all(self.borrow())
// .await
// .expect("failed to retrieve peers")
// }
// pub async fn remove_peer(
// &self,
// torrent_id: &i32,
// peer_id: &[u8; 20],
// ip: &IpNetwork,
// port: u16,
// ) {
// sqlx::query!(
// r#"
// DELETE FROM peers WHERE
// (torrent_id, peer_id, ip, port) = ($1, $2, $3, $4)
// "#,
// torrent_id,
// peer_id,
// ip,
// port as i32
// )
// .execute(self.borrow())
// .await
// .expect("failed removing peer from table");
// }
// returns uploaded/downloaded before the update
// pub async fn insert_or_update_peer(
// &self,
// torrent_id: &i32,
// ip: &IpNetwork,
// user_id: &i32,
// ann: &Announce,
// agent: Option<&str>,
// ) -> (i64, i64) {
// let existing = sqlx::query!(
// r#"
// SELECT real_uploaded, real_downloaded
// FROM peers
// WHERE torrent_id = $1 AND peer_id = $2 AND ip = $3 AND port = $4 AND user_id = $5
// "#,
// torrent_id,
// &ann.peer_id,
// ip,
// ann.port as i32,
// user_id
// )
// .fetch_optional(self.borrow())
// .await
// .expect("failed");
// let peer_status = if ann.left.unwrap() == 0 {
// PeerStatus::Seeding
// } else {
// PeerStatus::Leeching
// };
// sqlx::query!(
// r#"
// INSERT INTO peers(torrent_id, peer_id, ip, port, user_id, real_uploaded, real_downloaded, agent, status)
// VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9::peer_status_enum)
// ON CONFLICT (torrent_id, peer_id, ip, port) DO UPDATE
// SET
// last_seen_at = NOW(),
// real_uploaded = $6,
// real_downloaded = $7,
// status = $9::peer_status_enum
// "#,
// torrent_id,
// &ann.peer_id,
// ip,
// ann.port as i32,
// user_id,
// ann.uploaded.unwrap_or(0) as i64,
// ann.downloaded.unwrap_or(0) as i64,
// agent,
// peer_status as PeerStatus
// )
// .execute(self.borrow())
// .await
// .expect("failed");
// existing
// .map(|row| (row.real_uploaded, row.real_downloaded))
// .unwrap_or((0, 0))
// }
// pub async fn find_torrent_peers(&self, torrent_id: &i32, user_id: &i32) -> Vec<Peer> {
// let peers = sqlx::query!(
// r#"
// SELECT peers.ip AS ip, peers.port AS port
// FROM peers
// WHERE
// torrent_id = $1
// AND
// peers.user_id != $2
// "#,
// torrent_id,
// user_id
// )
// .fetch_all(self.borrow())
// .await
// .expect("failed");
// peers
// .into_iter()
// .map(|p| {
// let std::net::IpAddr::V4(ipv4) = p.ip.ip() else {
// panic!("oops");
// };
// Peer {
// ip: ipv4,
// port: p.port as u16,
// }
// })
// .collect::<Vec<_>>()
// }
// pub async fn remove_inactive_peers(&self, seconds_since_last_announce: f64) -> Result<u64> {
// let removed_peers_amount = sqlx::query!(
// r#"DELETE FROM peers WHERE last_seen_at < NOW() - INTERVAL '1 second' * $1"#,
// seconds_since_last_announce
// )
// .execute(self.borrow())
// .await?
// .rows_affected();
// Ok(removed_peers_amount)
// }
}

View File

@@ -735,38 +735,6 @@ impl ConnectionPool {
Ok(())
}
// pub async fn update_torrent_seeders_leechers(&self) -> Result<()> {
// let _ = sqlx::query!(
// r#"
// WITH peer_counts AS (
// SELECT
// torrent_id,
// COUNT(CASE WHEN status = 'seeding' THEN 1 END) AS current_seeders,
// COUNT(CASE WHEN status = 'leeching' THEN 1 END) AS current_leechers
// FROM
// peers
// GROUP BY
// torrent_id
// )
// UPDATE torrents AS t
// SET
// seeders = COALESCE(pc.current_seeders, 0),
// leechers = COALESCE(pc.current_leechers, 0)
// FROM
// torrents AS t_alias -- Use an alias for the table in the FROM clause to avoid ambiguity
// LEFT JOIN
// peer_counts AS pc ON t_alias.id = pc.torrent_id
// WHERE
// t.id = t_alias.id AND
// t.deleted_at IS NULL;
// "#
// )
// .execute(self.borrow())
// .await?;
// Ok(())
// }
pub async fn increment_torrent_times_completed(&self, torrent_id: i32) -> Result<()> {
let _ = sqlx::query!(
r#"