pgx_ulid: init at 0.2.0
This commit is contained in:
@@ -20,6 +20,7 @@ in
|
||||
anonymizer = importWithArgs ./anonymizer.nix;
|
||||
pgjwt = importWithArgs ./pgjwt.nix;
|
||||
pgvecto-rs = importWithArgs ./pgvecto-rs.nix;
|
||||
pgx_ulid = importWithArgs ./pgx_ulid.nix;
|
||||
timescaledb = importWithArgs ./timescaledb.nix;
|
||||
tsja = importWithArgs ./tsja.nix;
|
||||
wal2json = importWithArgs ./wal2json.nix;
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
{
|
||||
pkgs,
|
||||
makeTest,
|
||||
}:
|
||||
let
|
||||
inherit (pkgs) lib;
|
||||
|
||||
test-sql = pkgs.writeText "postgresql-test" ''
|
||||
CREATE EXTENSION ulid;
|
||||
|
||||
CREATE TABLE items (
|
||||
id ulid NOT NULL DEFAULT gen_monotonic_ulid() PRIMARY KEY,
|
||||
created_at TIMESTAMP GENERATED ALWAYS AS (id::TIMESTAMP) STORED
|
||||
);
|
||||
|
||||
INSERT INTO items (id) VALUES
|
||||
('01JGSK6X4APE5X5629ESGJBBV8'), -- 2025-01-03T21:23:17.770Z
|
||||
('01ARZ3NDEKTSV4RRFFQ69G5FAV'); -- 2016-07-30T23:54:10.259Z
|
||||
'';
|
||||
|
||||
makeTestFor =
|
||||
package:
|
||||
makeTest {
|
||||
name = "pgx_ulid-${package.name}";
|
||||
meta = with lib.maintainers; {
|
||||
maintainers = [ myypo ];
|
||||
};
|
||||
|
||||
nodes.machine =
|
||||
{ ... }:
|
||||
{
|
||||
services.postgresql = {
|
||||
inherit package;
|
||||
enable = true;
|
||||
enableJIT = lib.hasInfix "-jit-" package.name;
|
||||
extensions =
|
||||
ps: with ps; [
|
||||
pgx_ulid
|
||||
];
|
||||
settings.shared_preload_libraries = "pgx_ulid";
|
||||
};
|
||||
};
|
||||
|
||||
testScript =
|
||||
{ nodes, ... }:
|
||||
let
|
||||
inherit (nodes.machine.services.postgresql.package.pkgs) pgx_ulid;
|
||||
in
|
||||
''
|
||||
def check_count(statement, lines):
|
||||
return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format(
|
||||
statement, lines
|
||||
)
|
||||
|
||||
machine.start()
|
||||
machine.wait_for_unit("postgresql")
|
||||
|
||||
with subtest("Postgresql with extension ulid is available just after unit start"):
|
||||
machine.succeed(check_count("SELECT * FROM pg_available_extensions WHERE name = 'ulid' AND default_version = '${pgx_ulid.version}';", 1))
|
||||
|
||||
machine.succeed("sudo -u postgres psql -f ${test-sql}")
|
||||
|
||||
machine.succeed(check_count("SELECT gen_ulid();", 1))
|
||||
machine.succeed(check_count("SELECT gen_monotonic_ulid();", 1))
|
||||
|
||||
with subtest("Can generate default ULIDs and query by ULID-derived timestamps"):
|
||||
machine.succeed("""
|
||||
sudo -u postgres \\
|
||||
psql -c "SELECT id FROM items ORDER BY created_at DESC LIMIT 1;" \\
|
||||
| grep "01JGSK6X4APE5X5629ESGJBBV8"
|
||||
""")
|
||||
machine.succeed("""
|
||||
sudo -u postgres \\
|
||||
psql -c "INSERT INTO items DEFAULT VALUES;"
|
||||
""")
|
||||
machine.succeed("""
|
||||
sudo -u postgres \\
|
||||
psql -c "SELECT id FROM items ORDER BY created_at ASC LIMIT 1;" \\
|
||||
| grep "01ARZ3NDEKTSV4RRFFQ69G5FAV"
|
||||
""")
|
||||
|
||||
machine.shutdown()
|
||||
'';
|
||||
};
|
||||
in
|
||||
lib.recurseIntoAttrs (
|
||||
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) (
|
||||
lib.filterAttrs (_: p: !p.pkgs.pgx_ulid.meta.broken) pkgs.postgresqlVersions
|
||||
)
|
||||
// {
|
||||
passthru.override = p: makeTestFor p;
|
||||
}
|
||||
)
|
||||
@@ -93,6 +93,8 @@ in {
|
||||
|
||||
pgrouting = super.callPackage ./pgrouting.nix { };
|
||||
|
||||
pgx_ulid = super.callPackage ./pgx_ulid.nix { };
|
||||
|
||||
pg_partman = super.callPackage ./pg_partman.nix { };
|
||||
|
||||
pg_relusage = super.callPackage ./pg_relusage.nix { };
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
lib,
|
||||
buildPgrxExtension,
|
||||
fetchFromGitHub,
|
||||
nix-update-script,
|
||||
nixosTests,
|
||||
postgresql,
|
||||
util-linux,
|
||||
}:
|
||||
buildPgrxExtension rec {
|
||||
inherit postgresql;
|
||||
|
||||
pname = "pgx_ulid";
|
||||
version = "0.2.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "pksunkara";
|
||||
repo = "pgx_ulid";
|
||||
tag = "v${version}";
|
||||
hash = "sha256-VdLWwkUA0sVs5Z/Lyf5oTRhcHVzPmhgnYQhIM8MWJ0c=";
|
||||
};
|
||||
|
||||
cargoHash = "sha256-Gn+SjzGaxnGKJYI9+WyE1+TzlF/2Ne43aKbXrSzfQKM=";
|
||||
|
||||
postInstall = ''
|
||||
# Upstream renames the extension when packaging
|
||||
# https://github.com/pksunkara/pgx_ulid/blob/084778c3e2af08d16ec5ec3ef4e8f345ba0daa33/.github/workflows/release.yml#L81
|
||||
# Upgrade scripts should be added later, so we also rename them with wildcard
|
||||
# https://github.com/pksunkara/pgx_ulid/issues/49
|
||||
${util-linux}/bin/rename ${pname} ulid $out/share/postgresql/extension/${pname}*
|
||||
'';
|
||||
|
||||
# pgrx tests try to install the extension into postgresql nix store
|
||||
doCheck = false;
|
||||
|
||||
passthru = {
|
||||
updateScript = nix-update-script { };
|
||||
tests = nixosTests.postgresql.pgx_ulid.passthru.override postgresql;
|
||||
};
|
||||
|
||||
meta = {
|
||||
# Support for PostgreSQL 13 was removed in 0.2.0: https://github.com/pksunkara/pgx_ulid/blob/084778c3e2af08d16ec5ec3ef4e8f345ba0daa33/CHANGELOG.md?plain=1#L6
|
||||
broken = (lib.versionOlder postgresql.version "14") && (lib.versionAtLeast version "0.2.0");
|
||||
description = "ULID Postgres extension written in Rust";
|
||||
homepage = "https://github.com/pksunkara/pgx_ulid";
|
||||
changelog = "https://github.com/pksunkara/pgx_ulid/blob/v${version}/CHANGELOG.md";
|
||||
license = lib.licenses.mit;
|
||||
maintainers = with lib.maintainers; [ myypo ];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user