A decentralized music tracking and discovery platform built on AT Protocol 🎵 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz

add xataid extension for postgres

+199
+36
.github/workflows/docker-build-and-push-postgres.yml
··· 1 + name: Build and Push Postgres Docker Image 2 + 3 + on: 4 + push: 5 + branches: 6 + - main 7 + 8 + jobs: 9 + build-and-push: 10 + runs-on: ubuntu-latest 11 + permissions: 12 + contents: read 13 + packages: write 14 + 15 + steps: 16 + - name: Checkout repository 17 + uses: actions/checkout@v4 18 + 19 + - name: Set up Docker Buildx 20 + uses: docker/setup-buildx-action@v3 21 + 22 + - name: Log in to GitHub Container Registry 23 + uses: docker/login-action@v3 24 + with: 25 + registry: ghcr.io 26 + username: ${{ github.actor }} 27 + password: ${{ secrets.GITHUB_TOKEN }} 28 + 29 + - name: Build and push Docker image 30 + uses: docker/build-push-action@v6 31 + with: 32 + context: crates/xataid-extension 33 + push: true 34 + tags: | 35 + ghcr.io/tsirysndr/postgres-xataid:${{ github.sha }} 36 + ghcr.io/tsirysndr/postgres-xataid:latest
+3
crates/xataid-extension/.cargo/config.toml
··· 1 + [target.'cfg(target_os="macos")'] 2 + # Postgres symbols won't be available until runtime 3 + rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"]
+9
crates/xataid-extension/.gitignore
··· 1 + .DS_Store 2 + .idea/ 3 + /target 4 + *.iml 5 + **/*.rs.bk 6 + Cargo.lock 7 + pg_regress/results 8 + pg_regress/regression.diffs 9 + pg_regress/regression.out
+37
crates/xataid-extension/Cargo.toml
··· 1 + [package] 2 + name = "xataid_extension" 3 + version = "0.0.0" 4 + edition = "2021" 5 + 6 + [lib] 7 + crate-type = ["cdylib", "lib"] 8 + 9 + [[bin]] 10 + name = "pgrx_embed_xataid_extension" 11 + path = "./src/bin/pgrx_embed.rs" 12 + 13 + [features] 14 + default = ["pg13"] 15 + pg13 = ["pgrx/pg13", "pgrx-tests/pg13"] 16 + pg14 = ["pgrx/pg14", "pgrx-tests/pg14"] 17 + pg15 = ["pgrx/pg15", "pgrx-tests/pg15"] 18 + pg16 = ["pgrx/pg16", "pgrx-tests/pg16"] 19 + pg17 = ["pgrx/pg17", "pgrx-tests/pg17"] 20 + pg18 = ["pgrx/pg18", "pgrx-tests/pg18"] 21 + pg_test = [] 22 + 23 + [dependencies] 24 + pgrx = "=0.15.0" 25 + xid = "1.1.1" 26 + 27 + [dev-dependencies] 28 + pgrx-tests = "=0.15.0" 29 + 30 + [profile.dev] 31 + panic = "unwind" 32 + 33 + [profile.release] 34 + panic = "unwind" 35 + opt-level = 3 36 + lto = "fat" 37 + codegen-units = 1
+29
crates/xataid-extension/Dockerfile
··· 1 + FROM rust:1.88-bookworm AS builder 2 + 3 + RUN apt-get update && apt-get install -y \ 4 + libreadline-dev \ 5 + pkg-config \ 6 + flex \ 7 + bison \ 8 + build-essential 9 + 10 + RUN cargo install --locked cargo-pgrx 11 + 12 + RUN cargo pgrx init 13 + 14 + RUN apt-get install -y libclang-dev 15 + 16 + WORKDIR /app 17 + 18 + COPY . . 19 + 20 + RUN cargo pgrx package 21 + 22 + FROM postgres:15 23 + 24 + COPY --from=builder /app/target/release/xataid_extension-pg15/usr/lib/postgresql/15/lib/xataid_extension.so /usr/lib/postgresql/15/lib/xataid_extension.so 25 + 26 + COPY --from=builder /app/target/release/xataid_extension-pg15/usr/share/postgresql/15/extension/xataid_extension--0.0.0.sql /usr/share/postgresql/15/extension/xataid_extension--0.0.0.sql 27 + 28 + COPY --from=builder /app/target/release/xataid_extension-pg15/usr/share/postgresql/15/extension/xataid_extension.control /usr/share/postgresql/15/extension/xataid_extension.control 29 +
+3
crates/xataid-extension/pg_regress/expected/setup.out
··· 1 + -- this setup file is run immediately after the regression database is (re)created 2 + -- the file is optional but you likely want to create the extension 3 + CREATE EXTENSION xataid_extension;
+3
crates/xataid-extension/pg_regress/sql/setup.sql
··· 1 + -- this setup file is run immediately after the regression database is (re)created 2 + -- the file is optional but you likely want to create the extension 3 + CREATE EXTENSION xataid_extension;
+1
crates/xataid-extension/src/bin/pgrx_embed.rs
··· 1 + ::pgrx::pgrx_embed!();
+72
crates/xataid-extension/src/lib.rs
··· 1 + use pgrx::prelude::*; 2 + 3 + ::pgrx::pg_module_magic!(name, version); 4 + 5 + fn generate_xata_id() -> String { 6 + format!("rec_{}", xid::new()) 7 + } 8 + 9 + #[pg_extern] 10 + fn xata_id() -> String { 11 + generate_xata_id() 12 + } 13 + 14 + #[cfg(any(test, feature = "pg_test"))] 15 + #[pg_schema] 16 + mod tests { 17 + use pgrx::prelude::*; 18 + 19 + #[pg_test] 20 + fn test_xata_id_length_and_prefix() { 21 + let id = crate::generate_xata_id(); 22 + assert_eq!(id.len(), 24, "ID length should be 24"); 23 + assert!(id.starts_with("rec_"), "ID should start with 'rec_'"); 24 + } 25 + 26 + #[pg_test] 27 + fn test_xata_id_valid_characters() { 28 + let id = crate::generate_xata_id(); 29 + let random_part = &id[4..]; 30 + for c in random_part.chars() { 31 + assert!( 32 + c.is_ascii_lowercase() || c.is_ascii_digit(), 33 + "Invalid character in random part: {}", 34 + c 35 + ); 36 + } 37 + } 38 + 39 + #[pg_test] 40 + fn test_xata_id_uniqueness() { 41 + let id1 = crate::generate_xata_id(); 42 + let id2 = crate::generate_xata_id(); 43 + assert_ne!(id1, id2, "IDs should be unique"); 44 + } 45 + 46 + #[pg_test] 47 + fn test_xata_id_multiple() { 48 + for _ in 0..100 { 49 + let id = crate::generate_xata_id(); 50 + assert_eq!(id.len(), 24, "ID length should be 24"); 51 + assert!(id.starts_with("rec_"), "ID should start with 'rec_'"); 52 + for c in id[4..].chars() { 53 + assert!( 54 + c.is_ascii_lowercase() || c.is_ascii_digit(), 55 + "Invalid character: {}", 56 + c 57 + ); 58 + } 59 + } 60 + } 61 + } 62 + 63 + #[cfg(test)] 64 + pub mod pg_test { 65 + pub fn setup(_options: Vec<&str>) { 66 + // No initialization needed 67 + } 68 + 69 + pub fn postgresql_conf_options() -> Vec<&'static str> { 70 + vec![] 71 + } 72 + }
+6
crates/xataid-extension/xataid_extension.control
··· 1 + comment = 'xataid_extension: Created by pgrx' 2 + default_version = '@CARGO_VERSION@' 3 + module_pathname = 'xataSid_extension' 4 + relocatable = false 5 + superuser = true 6 + trusted = false