diff --git a/rust/.direnv/flake-profile b/rust/.direnv/flake-profile new file mode 120000 index 0000000..0c05709 --- /dev/null +++ b/rust/.direnv/flake-profile @@ -0,0 +1 @@ +flake-profile-1-link \ No newline at end of file diff --git a/rust/.direnv/flake-profile-1-link b/rust/.direnv/flake-profile-1-link new file mode 120000 index 0000000..840bd04 --- /dev/null +++ b/rust/.direnv/flake-profile-1-link @@ -0,0 +1 @@ +/nix/store/v3k7n7q44754h7cd8fvr3gyjq6dwmqk8-nix-shell-env \ No newline at end of file diff --git a/rust/.env b/rust/.env new file mode 100644 index 0000000..2dc9251 --- /dev/null +++ b/rust/.env @@ -0,0 +1 @@ +DATABASE_URL=sqlite://db.sqlite \ No newline at end of file diff --git a/rust/.envrc b/rust/.envrc new file mode 100644 index 0000000..437a1ae --- /dev/null +++ b/rust/.envrc @@ -0,0 +1,2 @@ +use flake +dotenv \ No newline at end of file diff --git a/rust/.gitignore b/rust/.gitignore new file mode 100644 index 0000000..bfcdc2c --- /dev/null +++ b/rust/.gitignore @@ -0,0 +1,2 @@ +target +db.sqlite \ No newline at end of file diff --git a/rust/Cargo.lock b/rust/Cargo.lock new file mode 100644 index 0000000..97764bd --- /dev/null +++ b/rust/Cargo.lock @@ -0,0 +1,145 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "deranged" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" + +[[package]] +name = "diesel" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7a532c1f99a0f596f6960a60d1e119e91582b24b39e2d83a190e61262c3ef0c" +dependencies = [ + "diesel_derives", + "libsqlite3-sys", + "time", +] + +[[package]] +name = "diesel_derives" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74398b79d81e52e130d991afeed9c86034bb1b7735f46d2f5bf7deb261d80303" +dependencies = [ + "diesel_table_macro_syntax", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "diesel_table_macro_syntax" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" +dependencies = [ + "syn", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "libsqlite3-sys" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc22eff61b133b115c6e8c74e818c628d6d5e7a502afea6f64dee076dd94326" +dependencies = [ + "pkg-config", + "vcpkg", +] + +[[package]] +name = "nixpkgs-update" +version = "0.1.0" +dependencies = [ + "diesel", +] + +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.183" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" + +[[package]] +name = "syn" +version = "2.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "time" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" +dependencies = [ + "deranged", + "itoa", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" + +[[package]] +name = "time-macros" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" +dependencies = [ + "time-core", +] + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 0000000..55ea34e --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "nixpkgs-update" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +diesel = { version = "2.1.0", features = ["sqlite"] } diff --git a/rust/diesel.toml b/rust/diesel.toml new file mode 100644 index 0000000..c028f4a --- /dev/null +++ b/rust/diesel.toml @@ -0,0 +1,9 @@ +# For documentation on how to configure this file, +# see https://diesel.rs/guides/configuring-diesel-cli + +[print_schema] +file = "src/schema.rs" +custom_type_derives = ["diesel::query_builder::QueryId"] + +[migrations_directory] +dir = "migrations" diff --git a/rust/flake.lock b/rust/flake.lock new file mode 100644 index 0000000..1a63724 --- /dev/null +++ b/rust/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1691709280, + "narHash": "sha256-zmfH2OlZEXwv572d0g8f6M5Ac6RiO8TxymOpY3uuqrM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cf73a86c35a84de0e2f3ba494327cf6fb51c0dfd", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/rust/flake.nix b/rust/flake.nix new file mode 100644 index 0000000..ba4a20a --- /dev/null +++ b/rust/flake.nix @@ -0,0 +1,16 @@ +{ + description = "update nixpkgs automatically"; + + outputs = { self, nixpkgs } @ args: let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + in { + devShells.x86_64-linux.default = pkgs.mkShell { + packages = [ + pkgs.cargo + pkgs.clippy + pkgs.sqlite + pkgs.diesel-cli + ]; + }; + }; +} diff --git a/rust/migrations/2023-08-12-152848_create_packages/down.sql b/rust/migrations/2023-08-12-152848_create_packages/down.sql new file mode 100644 index 0000000..9507fe8 --- /dev/null +++ b/rust/migrations/2023-08-12-152848_create_packages/down.sql @@ -0,0 +1 @@ +DROP table packages; diff --git a/rust/migrations/2023-08-12-152848_create_packages/up.sql b/rust/migrations/2023-08-12-152848_create_packages/up.sql new file mode 100644 index 0000000..1ea5a93 --- /dev/null +++ b/rust/migrations/2023-08-12-152848_create_packages/up.sql @@ -0,0 +1,27 @@ +CREATE TABLE packages ( + id text PRIMARY KEY NOT NULL + , attr_path text NOT NULL + , version_nixpkgs_master text + , version_nixpkgs_staging text + , version_nixpkgs_staging_next text + , version_repology text + , version_github text + , version_gitlab text + , version_pypi text + , project_repology text + , nixpkgs_name_replogy text + , owner_github text + , repo_github text + , owner_gitlab text + , repo_gitlab text + , last_checked_repology text + , last_checked_github text + , last_hecked_gitlab text + , last_hecked_pypi text + , last_checked_pending_pr text + , last_update_attempt text + , pending_pr integer + , pending_pr_owner text + , pending_pr_branch_name text + , last_update_log text +) diff --git a/rust/src/lib.rs b/rust/src/lib.rs new file mode 100644 index 0000000..453bf4b --- /dev/null +++ b/rust/src/lib.rs @@ -0,0 +1,11 @@ +pub mod models; +pub mod schema; + +use diesel::prelude::*; +use std::env; + +pub fn establish_connection() -> SqliteConnection { + let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set"); + SqliteConnection::establish(&database_url) + .unwrap_or_else(|_| panic!("Error connecting to {}", database_url)) +} diff --git a/rust/src/main.rs b/rust/src/main.rs new file mode 100644 index 0000000..5d5f1d4 --- /dev/null +++ b/rust/src/main.rs @@ -0,0 +1,18 @@ +use nixpkgs_update::models::*; +use nixpkgs_update::*; +use diesel::prelude::*; + +fn main() { + use nixpkgs_update::schema::packages::dsl::*; + + let connection = &mut establish_connection(); + let results : Vec = + packages. + load(connection) + .expect("Error loading packages"); + + println!("Displaying {} packages", results.len()); + for package in results { + println!("{} {}", package.id, package.attr_path); + } +} diff --git a/rust/src/models.rs b/rust/src/models.rs new file mode 100644 index 0000000..8a24fb5 --- /dev/null +++ b/rust/src/models.rs @@ -0,0 +1,33 @@ +use diesel::prelude::*; + +#[derive(Queryable, Selectable)] +#[diesel(table_name = crate::schema::packages)] +#[diesel(check_for_backend(diesel::sqlite::Sqlite))] +pub struct Package { + pub id: String, + pub attr_path: String, + pub version_nixpkgs_master: Option, + pub version_nixpkgs_staging: Option, + pub version_nixpkgs_staging_next: Option, + pub version_repology: Option, + pub version_github: Option, + pub version_gitlab: Option, + pub version_pypi: Option, + pub project_repology: Option, + pub nixpkgs_name_replogy: Option, + pub owner_github: Option, + pub repo_github: Option, + pub owner_gitlab: Option, + pub repo_gitlab: Option, + pub last_checked_repology: Option, + pub last_checked_github: Option, + pub last_hecked_gitlab: Option, + pub last_hecked_pypi: Option, + pub last_checked_pending_pr: Option, + pub last_update_attempt: Option, + pub pending_pr: Option, + pub pending_pr_owner: Option, + pub pending_pr_branch_name: Option, + pub last_update_log: Option, + +} diff --git a/rust/src/schema.rs b/rust/src/schema.rs new file mode 100644 index 0000000..23b9e50 --- /dev/null +++ b/rust/src/schema.rs @@ -0,0 +1,31 @@ +// @generated automatically by Diesel CLI. + +diesel::table! { + packages (id) { + id -> Text, + attr_path -> Text, + version_nixpkgs_master -> Nullable, + version_nixpkgs_staging -> Nullable, + version_nixpkgs_staging_next -> Nullable, + version_repology -> Nullable, + version_github -> Nullable, + version_gitlab -> Nullable, + version_pypi -> Nullable, + project_repology -> Nullable, + nixpkgs_name_replogy -> Nullable, + owner_github -> Nullable, + repo_github -> Nullable, + owner_gitlab -> Nullable, + repo_gitlab -> Nullable, + last_checked_repology -> Nullable, + last_checked_github -> Nullable, + last_hecked_gitlab -> Nullable, + last_hecked_pypi -> Nullable, + last_checked_pending_pr -> Nullable, + last_update_attempt -> Nullable, + pending_pr -> Nullable, + pending_pr_owner -> Nullable, + pending_pr_branch_name -> Nullable, + last_update_log -> Nullable, + } +}