Skip to content

Commit

Permalink
Update pgx to 0.2
Browse files Browse the repository at this point in the history
This commit updates our pgx version to the `0.2`. This brings us back to
using stock pgx, and opens the way for Postgres 14 support.

The big change for the `0.2` series, and the cause of the version-bump
along with most of the changes seen in this commit, is a change to how
install scripts are generated: whereas they were previously generated by
`cargo pgx` reading through all the Rust files looking for pgx's
markers, it is now generated by the pgx-macros themselves. The macros
that generate the Postgres shims–`#[pg_extern]`,
`#[derive(PostgresType)`, etc–now also generate functions that describe
the meaning of these objects. This info, along with a catalog of
well-known types are used to generate the equivalent SQL when the
extension is run as a binary. There are more details to this than
explained here, but the important change for our purposes is that while
SQL generation for functions used to be entirely nominal–the generator
would look at the names of the argument types and put that in the SQL–it
is now type-based. This leads us to a number of changes:
  1. Instead of using `type Foo = pg_sys::Datum` when we want raw access
     to a Datum of a given type, we now have a `raw` module containing
     slightly more principled raw types.
  2. We need to migrate to the upstream `Internal` type, instead of our
     existing polymorphic one. In order to maximize type safety, and
     minimize the amount of churn, we provide a new type `Inner<...>`
     which serves the same role as our old `Internal<...>` type, and
     add shims to communicate with the SQL generator. Long-term we
     should communicate with pgx and look into providing richer internal
     types, or an aggregate generator that creates the shims on its own.
  3. `varlena_type!()` is obsolete! Since SQL generation is type-based
     it can see through our macros and generate the correct SQL despite
     the actual types not being visible in the top-level files.
  4. As part of this we need to move the actual type-creation into the
     schema-generating modules, we cannot just have the marker there.

Something that this commit does not take advantage of, that we may want
to consider in the future, is removing the `toolkit_experimental::`
qualifications from arguments and return types of experimental
functions. Since type schema-qualification is now based on the type and
not the path, it should be possible to do so, and should make the code
more readable.
  • Loading branch information
JLockerman committed Nov 10, 2021
1 parent 3753078 commit d18ebe6
Show file tree
Hide file tree
Showing 47 changed files with 3,225 additions and 2,325 deletions.
19 changes: 19 additions & 0 deletions .cargo/pgx-linker-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /usr/bin/env bash
# Auto-generated by pgx. You may edit this, or delete it to have a new one created.

if [[ $CARGO_BIN_NAME == "sql-generator" ]]; then
UNAME=$(uname)
if [[ $UNAME == "Darwin" ]]; then
TEMP=$(mktemp pgx-XXX)
echo "*_pgx_internals_*" > ${TEMP}
gcc -exported_symbols_list ${TEMP} $@
rm -rf ${TEMP}
else
TEMP=$(mktemp pgx-XXX)
echo "{ __pgx_internals_*; };" > ${TEMP}
gcc -Wl,-dynamic-list=${TEMP} $@
rm -rf ${TEMP}
fi
else
gcc -Wl,-undefined,dynamic_lookup $@
fi
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ jobs:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-pg12-2
key: ${{ runner.os }}-cargo-pg12-3
restore-keys: |
${{ runner.os }}-cargo-pg12-2
${{ runner.os }}-cargo-pg12
- name: Cache cargo target dir
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-target-pg12-2
key: ${{ runner.os }}-cargo-build-target-pg12-3
restore-keys: |
${{ runner.os }}-cargo-build-target-pg12-2
${{ runner.os }}-cargo-build-target-pg12
- name: Run PG 12 Tests
Expand All @@ -56,7 +58,7 @@ jobs:
- name: Run post-install tests
run: |
sudo -HEsu postgres sh -c "/usr/local/cargo/bin/cargo pgx stop pg12 && /usr/local/cargo/bin/cargo pgx start pg12"
RUST_BACKTRACE=short cargo run --manifest-path ./tools/post-install/Cargo.toml /home/postgres/.pgx/12.6/pgx-install/bin/pg_config
RUST_BACKTRACE=short cargo run --manifest-path ./tools/post-install/Cargo.toml /home/postgres/.pgx/12.8/pgx-install/bin/pg_config
cargo run --manifest-path ./tools/testrunner/Cargo.toml -- -h localhost -p 28812
- name: Run Doc Tests
Expand Down Expand Up @@ -92,16 +94,18 @@ jobs:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-build-target-pg13-2
key: ${{ runner.os }}-cargo-build-target-pg13-3
restore-keys: |
${{ runner.os }}-cargo-build-target-pg13-2
${{ runner.os }}-cargo-pg13
- name: Cache cargo target dir
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-target-pg13-2
key: ${{ runner.os }}-cargo-build-target-pg13-3
restore-keys: |
${{ runner.os }}-cargo-build-target-pg13-2
${{ runner.os }}-cargo-build-target-pg13
- name: Run PG 13 Tests
Expand All @@ -110,7 +114,7 @@ jobs:
- name: Run post-install tests
run: |
sudo -HEsu postgres sh -c "/usr/local/cargo/bin/cargo pgx stop pg13 && /usr/local/cargo/bin/cargo pgx start pg13"
RUST_BACKTRACE=short cargo run --manifest-path ./tools/post-install/Cargo.toml /home/postgres/.pgx/13.2/pgx-install/bin/pg_config
RUST_BACKTRACE=short cargo run --manifest-path ./tools/post-install/Cargo.toml /home/postgres/.pgx/13.4/pgx-install/bin/pg_config
cargo run --manifest-path ./tools/testrunner/Cargo.toml -- -h localhost -p 28813
- name: Run Doc Tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
/target
*.iml
sql/*.generated.sql
extension/sql/timescaledb_toolkit-*.sql
/target-analyzer
.editorconfig
Loading

0 comments on commit d18ebe6

Please sign in to comment.