-
-
Notifications
You must be signed in to change notification settings - Fork 259
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
Introduce a more robust SQL generator #165
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
All feedback has been applied, gonna merge and we can cut a beta on Monday. :) |
Do it. I dare you! |
Where are some things that it have to be noticed if switched to |
This was referenced Sep 24, 2021
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rework how we do SQL generation.
Currently,
cargo pgx schema
works by scanning source files and producing SQL related to the raw source of the project. This generally works quite well, but it doesn't give us a lot of help when it comes to things like type resolution, or handling things like macros which might themselves produce things like#[pg_extern]
s.This PR instead uses Proc macros and
petgraph
to build up an inventory of SQL entities and then creates a dependency graph to drive ordering using a topological sort.It introduces a few breaking changes:
load-order.txt
is no longer supported. There is now anextension_sql_file!()
to load whole SQL files.extension_sql!()
andextension_sql_file!()
ordering are configurable. Users have access torequires
, andcreates
options on both.mod schema_name { /* code /* }
. Users must specify#[pg_schema]
on any schema they want to be used in the generated SQL.default!()
's second parameter must be a NULL, numeric, a boolean, or a Rust string literal.true
,"true"
,1
,NULL
,"NULL"
or"'Yay'"
(note the'
quotes), or"ARRAY[1,2]"
are all valid.pg_sys::Oid
)cargo pgx schema
now can optionally be passed apg11
or other version, likecargo pgx run
.cargo pgx schema
proxies to an extension binary.pgx
will create one for you automatically (src/bin/sql-generator.rs
) and keep it up to date.crate-type = [ "cdylib", "rlib" ]
to support linking to the extension from the newsql-generator
binary.cargo pgx schema
can output GraphViz DOT files This lets users visualize their extension inter-dependencies.Here's an example of one of the DOT graphs produced by the
custom_types
example:dot -Gsplines=ortho out.dot -Tjpg -Grankdir=LR > demo.jpg
Other non-breaking changes:
custom_sql
example showing ordering of different extension sqls:Post-merge Migration Guide
Update your
cargo-pgx
:cargo install --force cargo-pgx
In your
Cargo.toml
, setcrate-type
to include"rlib"
:Tell
cargo-pgx
to force update your.cargo/
andsrc/bin
files it needs:cargo pgx schema -f
Remove any
sql/*.generated.sql
files, as well as theload-order.txt
.For each
sql/*.sql
remaining, insertextension_sql_file!("../sql/that_file.sql")
; into yoursrc/lib.rs
If the files depend on entities which already exist, you might need to set a
requires
attribute:For any
mod floof { fn boop() { todo!() } }
style blocks you were using to infer schema name (making that functionfloof.boop
), decorate the schema with#[pg_schema]
:For any functions have a custom
sql
block for (like below), update that to usepgxsql
now:Run
cargo pgx schema
again!If you have any trouble, try running
cargo pgx schema -v
and investigating the output. We made sure to update thecargo doc
output ofpgx
with updated usage for the various macros and derives, they might have some advice, too.You can ask us questions via issues here or Discord if you get stuck.
Closes #154, #60.