Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding new ids #2

Merged
merged 4 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .cargo/config

This file was deleted.

3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[target.'cfg(target_os="macos")']
# Postgres symbols won't be available until runtime
rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"]
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
.github
.gitignore
*.md
*.yml

target
Cargo.lock
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI
on:
pull_request:
branches: [main, rewrite]
types: [opened, reopened, synchronize]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
ci:
name: CI
needs: [test, lint, lockfile]
runs-on: ubuntu-latest
steps:
- name: Done
run: exit 0
test:
name: Tests
strategy:
fail-fast: false
matrix:
postgres: [14, 15, 16]
runner:
- ubuntu-22.04
- buildjet-8vcpu-ubuntu-2204-arm
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build
run: docker buildx build --build-arg PG_MAJOR=${{ matrix.postgres }} -t test .
- name: Test
run: docker run test cargo pgrx test pg${{ matrix.postgres }}
lint:
name: Linting (fmt + clippy)
runs-on: ubuntu-latest
steps:
- name: Install rust
uses: dtolnay/[email protected]
with:
components: rustfmt, clippy
- name: Checkout
uses: actions/checkout@v3
- name: Format check
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check

lockfile:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install rust
uses: dtolnay/[email protected]
- name: Lockfile check
run: cargo update -w --locked
120 changes: 120 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
env:
NAME: uids_postgres
EXT_NAME: ulid
PKG_NAME: uids_postgres
name: Release
on:
push:
tags: [v*]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
create-release:
name: Create release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- name: Create Release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
build-linux-gnu:
name: Build & Release for linux
needs:
- create-release
strategy:
fail-fast: false
matrix:
postgres: [14, 15, 16]
box:
- runner: ubuntu-22.04
arch: amd64
- runner: buildjet-8vcpu-ubuntu-2204-arm
arch: arm64
runs-on: ${{ matrix.box.runner }}
timeout-minutes: 45
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install rust
uses: dtolnay/[email protected]
- name: Install dependencies
run: |
# Add postgres package repo
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null

sudo apt-get update
sudo apt-get install -y --no-install-recommends git build-essential libpq-dev curl libreadline6-dev zlib1g-dev pkg-config cmake
sudo apt-get install -y --no-install-recommends libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache
sudo apt-get install -y --no-install-recommends clang libclang-dev llvm-dev gcc tree

# Install requested postgres version
sudo apt-get install -y postgresql-${{ matrix.postgres }} postgresql-server-dev-${{ matrix.postgres }} -y

# Ensure installed pg_config is first on path
export PATH=$PATH:/usr/lib/postgresql/${{ matrix.postgres }}/bin

cargo install cargo-pgrx --version 0.11.2 --locked
cargo pgrx init --pg${{ matrix.postgres }}=/usr/lib/postgresql/${{ matrix.postgres }}/bin/pg_config
- name: Build artifacts
run: |
# selects the pgVer from pg_config on path
# https://github.com/tcdi/pgrx/issues/288
cargo pgrx package --no-default-features --features pg${{ matrix.postgres }}

# Create installable package
mkdir archive
cp `find target/release -type f -name "${{ env.EXT_NAME }}*"` archive

# Copy files into directory structure
mkdir -p package/usr/lib/postgresql/lib
mkdir -p package/var/lib/postgresql/extension
cp archive/*.so package/usr/lib/postgresql/lib
cp archive/*.control package/var/lib/postgresql/extension
cp archive/*.sql package/var/lib/postgresql/extension

# symlinks to Copy files into directory structure
mkdir -p package/usr/lib/postgresql/${{ matrix.postgres }}/lib
cd package/usr/lib/postgresql/${{ matrix.postgres }}/lib
cp -s ../../lib/*.so .
cd ../../../../../..

mkdir -p package/usr/share/postgresql/${{ matrix.postgres }}/extension
cd package/usr/share/postgresql/${{ matrix.postgres }}/extension

cp -s ../../../../../var/lib/postgresql/extension/${{ env.EXT_NAME }}.control .
cp -s ../../../../../var/lib/postgresql/extension/${{ env.EXT_NAME }}*.sql .
cd ../../../../../..

# Create install control file
extension_version=${{ github.ref_name }}
# strip the leading v
deb_version=${extension_version:1}

mkdir -p package/DEBIAN
touch package/DEBIAN/control
echo 'Package: ${{ env.PKG_NAME }}' >> package/DEBIAN/control
echo 'Version:' ${deb_version} >> package/DEBIAN/control
echo 'Architecture: ${{ matrix.box.arch }}' >> package/DEBIAN/control
echo 'Maintainer: Pavan Sunkara' >> package/DEBIAN/control
echo 'Description: A PostgreSQL extension for ULID' >> package/DEBIAN/control

# Create deb package
sudo chown -R root:root package
sudo chmod -R 00755 package
sudo dpkg-deb -Zxz --build --root-owner-group package
- name: Upload artifacts
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./package.deb
asset_name: ${{ env.NAME }}-${{ github.ref_name }}-pg${{ matrix.postgres }}-${{ matrix.box.arch }}-linux-gnu.deb
asset_content_type: application/vnd.debian.binary-package
7 changes: 0 additions & 7 deletions .vscode/settings.json

This file was deleted.

38 changes: 25 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
[package]
name = "uids"
version = "0.2.0"
version = "0.0.0"
edition = "2021"
description = "PostgreSQL Extension to generate various type of Unique IDS."

[lib]
crate-type = ["cdylib"]

[features]
default = ["pg13"]
pg10 = ["pgx/pg10", "pgx-tests/pg10"]
pg11 = ["pgx/pg11", "pgx-tests/pg11"]
pg12 = ["pgx/pg12", "pgx-tests/pg12"]
pg13 = ["pgx/pg13", "pgx-tests/pg13"]
pg14 = ["pgx/pg14", "pgx-tests/pg14"]
default = ["pg16"]
pg11 = ["pgrx/pg11", "pgrx-tests/pg11"]
pg12 = ["pgrx/pg12", "pgrx-tests/pg12"]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
pg_test = []

[dependencies]
nanoid = "0.4.0"
pgx = "0.4.5"
rusty_ulid = "1.0.0"
svix-ksuid = "0.6.0"
pgrx = "=0.11.4"
rusty_ulid = "2.0.0"
svix-ksuid = "0.8.0"
type-safe-id = "0.3.0"
uuid = { version = "1.8.0", features = [
"v7",
"v4",
"v6",
"v8",
"fast-rng",
"macro-diagnostics",
] }
getrandom = "0.2"
cuid2 = "0.1.2"
timeflake-rs = "0.3.0"
pushid = "0.0.1"

[dev-dependencies]
pgx-tests = "0.4.5"
pgrx-tests = "=0.11.4"

[profile.dev]
panic = "unwind"
lto = "thin"

[profile.release]
panic = "unwind"
Expand Down
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
ARG PG_MAJOR

FROM postgres:${PG_MAJOR}

RUN apt-get update

ENV build_deps ca-certificates \
git \
build-essential \
libpq-dev \
postgresql-server-dev-${PG_MAJOR} \
curl \
libreadline6-dev \
zlib1g-dev

RUN apt-get install -y --no-install-recommends $build_deps pkg-config cmake

WORKDIR /home/postgres

ENV HOME=/home/postgres
ENV PATH=/home/postgres/.cargo/bin:$PATH

RUN chown postgres:postgres /home/postgres

USER postgres

RUN \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain 1.74.0 && \
rustup --version && \
rustc --version && \
cargo --version

# pgrx
RUN cargo install cargo-pgrx --version 0.11.2 --locked

RUN cargo pgrx init --pg${PG_MAJOR} $(which pg_config)

USER root

COPY . .

RUN cargo pgrx install

RUN chown -R postgres:postgres /home/postgres
RUN chown -R postgres:postgres /usr/share/postgresql/${PG_MAJOR}/extension
RUN chown -R postgres:postgres /usr/lib/postgresql/${PG_MAJOR}/lib

USER postgres

ENV POSTGRES_HOST_AUTH_METHOD=trust
ENV USER=postgres
Loading
Loading