tcdi / plrust

A Rust procedural language handler for PostgreSQL
PostgreSQL License
1.1k stars 32 forks source link

Add a function to list all the allowlisted crates with their respecti… #373

Closed anth0nyleung closed 1 year ago

anth0nyleung commented 1 year ago

This commit addresses issue #371

Introduce a function to list all the allowed dependencies and their respective versions and features.

E.g Given a toml like this,

$ > cat ~/allow.toml
owo-colors = "=3.5.0"
tokio = { version = "=1.19.2", features = ["rt", "net"] }
plutonium = "*"
syn = { version = "=2.0.28", default-features = false }
rand = ["=0.8.3", { version = ">0.8.4, <0.8.6", features = ["getrandom"] }]

the function returns a table

postgres=# SELECT * FROM plrust.list_allowed_dependencies();
    name    |    version     |  features   | default_features
------------+----------------+-------------+------------------
 owo-colors | =3.5.0         | {}          | t
 plutonium  | *              | {}          | t
 rand       | =0.8.3         | {}          | t
 rand       | >0.8.4, <0.8.6 | {getrandom} | t
 syn        | =2.0.28        | {}          | f
 tokio      | =1.19.2        | {rt,net}    | t
(6 rows)

This commit also bumps plrust to 1.1 and introduce the sql script for schema upgrade


Testing

  1. Install plrust 1.0 (v1.2.3)
    
    postgres=# CREATE EXTENSION plrust ;
    CREATE EXTENSION
    postgres=# \dx plrust
    List of installed extensions
    -[ RECORD 1 ]-----------------------------------------------------------
    Name        | plrust
    Version     | 1.0
    Schema      | plrust
    Description | plrust:  A Trusted Rust procedural language for PostgreSQL

postgres=# \df plrust.* List of functions -[ RECORD 1 ]-------+-------------------- Schema | plrust Name | plrust_call_handler Result data type | language_handler Argument data types | Type | func -[ RECORD 2 ]-------+-------------------- Schema | plrust Name | plrust_validator Result data type | void Argument data types | fn_oid oid Type | func

2. Update plrust to 1.1, new function is installed

postgres=# ALTER EXTENSION plrust UPDATE TO '1.1'; ALTER EXTENSION postgres=# \dx plrust List of installed extensions -[ RECORD 1 ]----------------------------------------------------------- Name | plrust Version | 1.1 Schema | plrust Description | plrust: A Trusted Rust procedural language for PostgreSQL

postgres=# \df plrust.* List of functions -[ RECORD 1 ]-------+-------------------------------------------------------------------------- Schema | plrust Name | list_allowed_dependencies Result data type | TABLE(name text, version text, features text[], default_features boolean) Argument data types | Type | func -[ RECORD 2 ]-------+-------------------------------------------------------------------------- Schema | plrust Name | plrust_call_handler Result data type | language_handler Argument data types | Type | func -[ RECORD 3 ]-------+-------------------------------------------------------------------------- Schema | plrust Name | plrust_validator Result data type | void Argument data types | fn_oid oid Type | func

postgres=# SELECT FROM plrust.list_allowed_dependencies(); name | version | features | default_features ------------+----------------+-------------+------------------ owo-colors | =3.5.0 | {} | t plutonium | | {} | t rand | =0.8.3 | {} | t rand | >0.8.4, <0.8.6 | {getrandom} | t syn | =2.0.28 | {} | f tokio | =1.19.2 | {rt,net} | t (6 rows)

eeeebbbbrrrr commented 1 year ago

Thanks! I’ll provide some feedback in the morning.