Skip to content

Commit 7e602e4

Browse files
Merge pull request #18 from rustprooflabs/dev
Rewrite to pgx
2 parents 7b5ea2f + 1dc0c6e commit 7e602e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1402
-206
lines changed

.cargo/config

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Auto-generated by pgx. You may edit this, or delete it to have a new one created.
2+
3+
[target.x86_64-unknown-linux-gnu]
4+
linker = "./.cargo/pgx-linker-script.sh"
5+
6+
[target.aarch64-unknown-linux-gnu]
7+
linker = "./.cargo/pgx-linker-script.sh"
8+
9+
[target.x86_64-apple-darwin]
10+
linker = "./.cargo/pgx-linker-script.sh"
11+
12+
[target.aarch64-apple-darwin]
13+
linker = "./.cargo/pgx-linker-script.sh"
14+
15+
[target.x86_64-unknown-freebsd]
16+
linker = "./.cargo/pgx-linker-script.sh"

.cargo/linker-script.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#! /usr/bin/env bash
2+
# Auto-generated by pgx. You may edit this, or delete it to have a new one created.
3+
4+
if [[ $CARGO_BIN_NAME == "sql-generator" ]]; then
5+
gcc -Wl,-undefined,dynamic_lookup,-dynamic-list=$CARGO_MANIFEST_DIR/.cargo/pgx-dynamic-list.txt $@
6+
else
7+
gcc -Wl,-undefined,dynamic_lookup $@
8+
fi

.cargo/pgx-dynamic-list.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ __pgx_internals_*; };

.cargo/pgx-linker-script.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#! /usr/bin/env bash
2+
# Auto-generated by pgx. You may edit this, or delete it to have a new one created.
3+
4+
if [[ $CARGO_BIN_NAME == "sql-generator" ]]; then
5+
UNAME=$(uname)
6+
if [[ $UNAME == "Darwin" ]]; then
7+
TEMP=$(mktemp pgx-XXX)
8+
echo "*_pgx_internals_*" > ${TEMP}
9+
gcc -exported_symbols_list ${TEMP} $@
10+
rm -rf ${TEMP}
11+
else
12+
TEMP=$(mktemp pgx-XXX)
13+
echo "{ __pgx_internals_*; };" > ${TEMP}
14+
gcc -Wl,-dynamic-list=${TEMP} $@
15+
rm -rf ${TEMP}
16+
fi
17+
else
18+
gcc -Wl,-undefined,dynamic_lookup $@
19+
fi

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/target
2+
*.iml
3+
**/*.rs.bk
4+
Cargo.lock
5+
sql/*.generated.sql
6+
extension.dot
7+
extension.jpg

.gitlab-ci.yml

-50
This file was deleted.

ADVANCED-INSTALL.md

+218
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
# PgDD Advanced installation
2+
3+
This page covers installing PgDD from source locally, and the Docker build
4+
method based on [ZomboDB's build system](https://github.com/zombodb/zombodb)
5+
used to create the binaries.
6+
7+
8+
## Install `pgdd` from source
9+
10+
11+
One way to install `pgdd` is to install from source by cloning this repository.
12+
13+
### Prereqs
14+
15+
Pgx and its dependencies are the main prereq for PgDD.
16+
Install Prereqs and ensure PostgreSQL dev tools are installed.
17+
18+
> See the [Cargo PGX](https://github.com/zombodb/pgx/tree/master/cargo-pgx)
19+
documentation for more information on using pgx.
20+
21+
22+
```bash
23+
sudo apt install postgresql-server-dev-all libreadline-dev zlib1g-dev curl \
24+
libssl-dev llvm-dev libclang-dev clang \
25+
graphviz
26+
```
27+
28+
[Install Rust](https://www.rust-lang.org/tools/install) and Pgx.
29+
30+
```bash
31+
curl https://sh.rustup.rs -sSf | sh -s -- -y
32+
source $HOME/.cargo/env
33+
```
34+
35+
Install `cargo-pgx` regularly (see dev steps below for non-standard install).
36+
37+
38+
```bash
39+
cargo install cargo-pgx
40+
```
41+
42+
43+
Install `cargo-deb` used for packaging binaries.
44+
45+
```bash
46+
cargo install cargo-deb
47+
```
48+
49+
50+
Initialize pgx. Need to run this after install AND occasionally to get updates
51+
to Postgres versions or glibc updates. Not typically required to follow pgx
52+
developments.
53+
54+
55+
```bash
56+
cargo pgx init
57+
```
58+
59+
60+
### Clone PgDD repo
61+
62+
```bash
63+
mkdir ~/git
64+
cd ~/git
65+
git clone https://github.com/rustprooflabs/pgdd.git
66+
cd ~/git/pgdd
67+
```
68+
69+
### Test deployment
70+
71+
Specify version, `pg10` through `pg13` are currently supported. This command will
72+
start a test instance of Postgres on port `28812`. Using a different version
73+
changes the last two digits of the port!
74+
75+
76+
```bash
77+
cargo pgx run pg13
78+
```
79+
80+
Example output.
81+
82+
```bash
83+
Stopping Postgres v13
84+
building extension with features `pg13`
85+
"cargo" "build" "--features" "pg13" "--no-default-features"
86+
Finished dev [unoptimized + debuginfo] target(s) in 0.05s
87+
88+
installing extension
89+
Copying control file to `/home/username/.pgx/13.4/pgx-install/share/postgresql/extension/pgdd.control`
90+
Copying shared library to `/home/username/.pgx/13.4/pgx-install/lib/postgresql/pgdd.so`
91+
Building SQL generator with features `pg13`
92+
"cargo" "build" "--bin" "sql-generator" "--features" "pg13" "--no-default-features"
93+
Finished dev [unoptimized + debuginfo] target(s) in 0.05s
94+
Discovering SQL entities
95+
Discovered 9 SQL entities: 0 schemas (0 unique), 6 functions, 0 types, 0 enums, 3 sqls, 0 ords, 0 hashes
96+
running SQL generator with features `pg13`
97+
"cargo" "run" "--bin" "sql-generator" "--features" "pg13" "--no-default-features" "--" "--sql" "/home/username/.pgx/13.4/pgx-install/share/postgresql/extension/pgdd--0.4.0-dev.sql"
98+
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
99+
Running `target/debug/sql-generator --sql /home/username/.pgx/13.4/pgx-install/share/postgresql/extension/pgdd--0.4.0-dev.sql`
100+
Copying extension schema file to `/home/username/.pgx/13.4/pgx-install/share/postgresql/extension/pgdd--0.3.1--0.4.0-dev.sql`
101+
Copying extension schema file to `/home/username/.pgx/13.4/pgx-install/share/postgresql/extension/pgdd--0.3--0.3.1.sql`
102+
Finished installing pgdd
103+
Starting Postgres v13 on port 28813
104+
Re-using existing database pgdd
105+
```
106+
107+
In the test instance of psql, create the extension in database.
108+
109+
```bash
110+
CREATE EXTENSION pgdd;
111+
```
112+
113+
114+
## Build binary packages
115+
116+
Debian/Ubuntu Bionic binaries are available for 0.4.0
117+
(first [pgx](https://github.com/zombodb/pgx) version)
118+
and later. More distributions will likely have binaries available in the future.
119+
120+
121+
```bash
122+
cd build/
123+
time bash ./build.sh
124+
```
125+
126+
Tagged versions will be attached to their [releases](https://github.com/rustprooflabs/pgdd/releases).
127+
128+
During development some versions may be copied to the `./standalone/` directory.
129+
130+
```bash
131+
cp ./target/artifacts/* ./standalone/
132+
```
133+
134+
## Pgx Generate graphviz
135+
136+
```bash
137+
cargo pgx schema -d
138+
dot -Goverlap=prism -Gspline=ortho -Tjpg extension.dot > extension.jpg
139+
```
140+
141+
![pgx dependencies for pgdd v0.4.0-dev](pgdd--0.4.0-dev.jpg)
142+
143+
144+
## Non-standard dev
145+
146+
When working against Pgx installed from a non-tagged branch, install pgx using:
147+
148+
```bash
149+
cargo install --force --git "https://github.com/zombodb/pgx" \
150+
--branch "develop" \
151+
"cargo-pgx"
152+
```
153+
154+
Changes to `Cargo.toml` required in `[lib]` and `[dependencies]` sections.
155+
156+
157+
```toml
158+
[lib]
159+
# rlib added to build against repo instead of crate (I think)
160+
crate-type = ["cdylib", "rlib"]
161+
#crate-type = ["cdylib"]
162+
```
163+
164+
165+
```toml
166+
[dependencies]
167+
168+
pgx = { git = "https://github.com/zombodb/pgx", branch = "oh-no-type-resolution" }
169+
pgx-macros = { git = "https://github.com/zombodb/pgx", branch = "develop" }
170+
#pgx = "0.1.21"
171+
#pgx-macros = "0.1.21"
172+
173+
# Won't be needed in final version (hopefully!)
174+
pgx-utils = { git = "https://github.com/zombodb/pgx", branch = "develop" }
175+
176+
[dev-dependencies]
177+
pgx-tests = { git = "https://github.com/zombodb/pgx", branch = "develop" }
178+
#pgx-tests = "0.1.21"
179+
```
180+
181+
182+
183+
The following command can be used to force pgx to overwrite the configs it needs to
184+
for various dev related changes.
185+
186+
187+
```bash
188+
cargo pgx schema -f
189+
```
190+
191+
Another option to try.
192+
193+
```bash
194+
cargo clean
195+
```
196+
197+
198+
## Non-standard In Docker
199+
200+
If testing this extension against non-standard pgx install, update the
201+
Dockerfile to install from the specific branch.
202+
203+
Change
204+
205+
```bash
206+
RUN /bin/bash rustup.sh -y \
207+
&& cargo install cargo-pgx
208+
```
209+
210+
To
211+
212+
```bash
213+
RUN /bin/bash rustup.sh -y \
214+
&& cargo install --force --git "https://github.com/zombodb/pgx" \
215+
--branch "develop" \
216+
"cargo-pgx"
217+
```
218+

Cargo.toml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[package]
2+
name = "pgdd"
3+
version = "0.4.0-dev"
4+
edition = "2018"
5+
description = "In-database (PostgreSQL) data dictionary providing database introspection via standard SQL query syntax."
6+
7+
[lib]
8+
# rlib added to build against repo instead of crate (I think)
9+
crate-type = ["cdylib", "rlib"]
10+
#crate-type = ["cdylib"]
11+
12+
[features]
13+
default = ["pg13"]
14+
pg10 = ["pgx/pg10"]
15+
pg11 = ["pgx/pg11"]
16+
pg12 = ["pgx/pg12"]
17+
pg13 = ["pgx/pg13"]
18+
pg_test = []
19+
20+
[dependencies]
21+
22+
pgx = { git = "https://github.com/zombodb/pgx", branch = "develop" }
23+
pgx-macros = { git = "https://github.com/zombodb/pgx", branch = "develop" }
24+
#pgx = "0.2.0-beta.1"
25+
#pgx-macros = "0.2.0-beta.1"
26+
27+
# Won't be needed in final version (hopefully!)
28+
pgx-utils = { git = "https://github.com/zombodb/pgx", branch = "develop" }
29+
#pgx-utils = "0.2.0-beta.1"
30+
31+
[dev-dependencies]
32+
pgx-tests = { git = "https://github.com/zombodb/pgx", branch = "develop" }
33+
#pgx-tests = "0.2.0-beta.1"
34+
35+
36+
[profile.dev]
37+
panic = "unwind"
38+
lto = "thin"
39+
40+
[profile.release]
41+
panic = "unwind"
42+
opt-level = 3
43+
lto = "thin"
44+
codegen-units = 1
45+

Dockerfile

-20
This file was deleted.

0 commit comments

Comments
 (0)