diff --git a/Cargo.lock b/Cargo.lock index 1db6999e..833bdf7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -581,6 +581,9 @@ name = "either" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +dependencies = [ + "serde", +] [[package]] name = "encoding_rs" @@ -1793,9 +1796,11 @@ dependencies = [ "dotenvy", "either", "heck", + "hex", "once_cell", "proc-macro2", "quote", + "serde", "serde_json", "sha2", "sqlx-core", diff --git a/Cargo.toml b/Cargo.toml index 6a0f8d54..20ef2ab9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ publish = false [dependencies] actix-web = "4.3.1" anyhow = "1.0.69" -sqlx = { version = "0.6.2", features = [ "json", "runtime-tokio-native-tls" , "postgres", "time" ] } +sqlx = { version = "0.6.2", features = [ "json", "runtime-tokio-native-tls" , "postgres", "time", "offline" ] } url = "2.3.1" thiserror = "1.0.39" log = "0.4.17" diff --git a/Dockerfile b/Dockerfile index b891473c..cb8abd8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM rust:1.68.0 as builder -COPY Cargo.toml Cargo.lock ./ +COPY sqlx-data.json Cargo.toml Cargo.lock ./ COPY src ./src COPY registry-s3 ./registry-s3 RUN cargo build && \ diff --git a/sqlx-data.json b/sqlx-data.json new file mode 100644 index 00000000..5ea22aaa --- /dev/null +++ b/sqlx-data.json @@ -0,0 +1,307 @@ +{ + "db": "PostgreSQL", + "3b932eb9f7a785a2bb9ec6c1753f8c31d34486c37d9489708041b17ab01a5417": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Text" + ] + } + }, + "query": "UPDATE extensions\n SET updated_at = (now() at time zone 'utc')\n WHERE name = $1" + }, + "48a96a05f91d89cfd30f0cd3b119f0690a53d71d82ad9d40a5b0a07941fc31c9": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Int8" + }, + { + "name": "name", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "updated_at", + "ordinal": 2, + "type_info": "Timestamp" + }, + { + "name": "created_at", + "ordinal": 3, + "type_info": "Timestamp" + }, + { + "name": "downloads", + "ordinal": 4, + "type_info": "Int4" + }, + { + "name": "description", + "ordinal": 5, + "type_info": "Varchar" + }, + { + "name": "homepage", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "documentation", + "ordinal": 7, + "type_info": "Varchar" + }, + { + "name": "repository", + "ordinal": 8, + "type_info": "Varchar" + } + ], + "nullable": [ + false, + true, + true, + true, + true, + true, + true, + true, + true + ], + "parameters": { + "Left": [] + } + }, + "query": "SELECT * FROM extensions" + }, + "4b2365bc80293846957f284d63c2d23a2ac6d2e3629e1f836f12c0eca2dd4339": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Int8" + }, + { + "name": "name", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "updated_at", + "ordinal": 2, + "type_info": "Timestamp" + }, + { + "name": "created_at", + "ordinal": 3, + "type_info": "Timestamp" + }, + { + "name": "downloads", + "ordinal": 4, + "type_info": "Int4" + }, + { + "name": "description", + "ordinal": 5, + "type_info": "Varchar" + }, + { + "name": "homepage", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "documentation", + "ordinal": 7, + "type_info": "Varchar" + }, + { + "name": "repository", + "ordinal": 8, + "type_info": "Varchar" + } + ], + "nullable": [ + false, + true, + true, + true, + true, + true, + true, + true, + true + ], + "parameters": { + "Left": [ + "Text" + ] + } + }, + "query": "SELECT * FROM extensions WHERE name = $1" + }, + "6cdd35899d214093e96bd8cae07778d12089e0a8712cfe94dc6b747c9b37c3d5": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + } + }, + "query": "UPDATE versions\n SET updated_at = (now() at time zone 'utc')\n WHERE extension_id = $1\n AND num = $2" + }, + "7a931ec93bcc1516737bfc65fd24b339401996a7f23891c7770a3b5b5c79ffc2": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Int8" + }, + { + "name": "extension_id", + "ordinal": 1, + "type_info": "Int4" + }, + { + "name": "num", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "updated_at", + "ordinal": 3, + "type_info": "Timestamp" + }, + { + "name": "created_at", + "ordinal": 4, + "type_info": "Timestamp" + }, + { + "name": "downloads", + "ordinal": 5, + "type_info": "Int4" + }, + { + "name": "features", + "ordinal": 6, + "type_info": "Jsonb" + }, + { + "name": "yanked", + "ordinal": 7, + "type_info": "Bool" + }, + { + "name": "license", + "ordinal": 8, + "type_info": "Varchar" + }, + { + "name": "extension_size", + "ordinal": 9, + "type_info": "Int4" + }, + { + "name": "published_by", + "ordinal": 10, + "type_info": "Int4" + }, + { + "name": "checksum", + "ordinal": 11, + "type_info": "Bpchar" + }, + { + "name": "links", + "ordinal": 12, + "type_info": "Varchar" + } + ], + "nullable": [ + false, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + } + }, + "query": "SELECT *\n FROM versions\n WHERE \n extension_id = $1\n and num = $2" + }, + "c5ad3eb48a64a84f9a09a0b2cb9c27f3bb3ef3c9b5d11c532d97e9a3030d8c6b": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Int8" + } + ], + "nullable": [ + false + ], + "parameters": { + "Left": [ + "Varchar", + "Varchar", + "Varchar" + ] + } + }, + "query": "\n INSERT INTO extensions(name, created_at, description, homepage)\n VALUES ($1, (now() at time zone 'utc'), $2, $3)\n RETURNING id\n " + }, + "c9f6b97900ea30be7f940f72c7e20ab21cd00f5f5ef4e4e52c228e2b7e070e9b": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Int4", + "Varchar", + "Bool", + "Varchar" + ] + } + }, + "query": "\n INSERT INTO versions(extension_id, num, created_at, yanked, license)\n VALUES ($1, $2, (now() at time zone 'utc'), $3, $4)\n " + }, + "f1213b6f0350efbce183597c665e9494141b8063f4fdd096c11337272b484556": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Int4", + "Varchar", + "Bool", + "Varchar" + ] + } + }, + "query": "\n INSERT INTO versions(extension_id, num, created_at, yanked, license)\n VALUES ($1, $2, (now() at time zone 'utc'), $3, $4)\n " + } +} \ No newline at end of file diff --git a/src/publish.rs b/src/publish.rs index dafae176..0cc9c6c3 100644 --- a/src/publish.rs +++ b/src/publish.rs @@ -6,7 +6,6 @@ use crate::errors::ExtensionRegistryError; use crate::views::extension_publish::ExtensionUpload; use actix_web::{error, post, web, HttpResponse}; use futures::StreamExt; -use sqlx::Row; const MAX_SIZE: usize = 262_144; // max payload size is 256k diff --git a/src/routes.rs b/src/routes.rs index 18d4bd96..20a70616 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -2,7 +2,6 @@ use crate::config::Config; use crate::connect; use crate::errors::ExtensionRegistryError; use actix_web::{get, web, HttpResponse, Responder}; -use log::info; #[get("/")] pub async fn running() -> impl Responder { HttpResponse::Ok().body("API is up and running!") @@ -18,7 +17,9 @@ pub async fn get_all_extensions( // Create a transaction on the database, if there are no errors, // commit the transactions to record a new or updated extension. let mut tx = conn.begin().await?; - let rows = sqlx::query!("SELECT * FROM extensions").fetch_all(&mut tx).await?; + let rows = sqlx::query!("SELECT * FROM extensions") + .fetch_all(&mut tx) + .await?; for row in rows.iter() { extensions.push(row.name.as_ref().unwrap().to_owned()); }