Skip to content

Commit 7a55b5c

Browse files
authored
No schema flag (pgcentralfoundation#262)
introduce a --no-schema flag for cargo pgx run/test/install. cargo pgx package will always generate the schema
1 parent a0155b5 commit 7a55b5c

File tree

9 files changed

+70
-19
lines changed

9 files changed

+70
-19
lines changed

.github/workflows/cargo-pgx-init.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ jobs:
5656

5757
# hack Cargo.toml to use this version of pgx from github
5858
- name: hack Cargo.toml
59+
env:
60+
ACTIONS_ALLOW_UNSECURE_COMMANDS=: 'true'
5961
run: |
62+
echo "::set-env name=git_hash::$(git rev-parse --short $GITHUB_SHA)"
63+
echo "::set-env name=git_branch::${GITHUB_REF#refs/heads/}"
6064
echo '[patch.crates-io]' >> /tmp/sample/Cargo.toml
61-
echo pgx = '{' git = '"'https://github.com/zombodb/pgx'"', package = '"'pgx'"', rev = '"'${GITHUB_SHA}'"' '}' >> /tmp/sample/Cargo.toml
62-
echo pgx-macros = '{' git = '"'https://github.com/zombodb/pgx'"', package = '"'pgx-macros'"', rev = '"'${GITHUB_SHA}'"' '}' >> /tmp/sample/Cargo.toml
63-
echo pgx-tests = '{' git = '"'https://github.com/zombodb/pgx'"', package = '"'pgx-tests'"', rev = '"'${GITHUB_SHA}'"' '}' >> /tmp/sample/Cargo.toml
65+
echo pgx = '{' git = '"'https://github.com/zombodb/pgx'"', package = '"'pgx'"', branch = '"'${git_branch}'"', rev = '"'${git_hash}'"' '}' >> /tmp/sample/Cargo.toml
66+
echo pgx-macros = '{' git = '"'https://github.com/zombodb/pgx'"', package = '"'pgx-macros'"', branch = '"'${git_branch}'"', rev = '"'${git_hash}'"' '}' >> /tmp/sample/Cargo.toml
67+
echo pgx-tests = '{' git = '"'https://github.com/zombodb/pgx'"', package = '"'pgx-tests'"', branch = '"'${git_branch}'"', rev = '"'${git_hash}'"' '}' >> /tmp/sample/Cargo.toml
6468
6569
# test that sample extension on all 4 Postgres'
6670
- name: test sample on pg10

cargo-pgx/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ OPTIONS:
138138
download/compile/install it
139139
--pg13 <PG13_PG_CONFIG> if installed locally, the path to PG13's 'pg_config' tool, or 'download' to have pgx
140140
download/compile/install it
141+
--pg14 <PG14_PG_CONFIG> if installed locally, the path to PG14's 'pg_config' tool, or 'download' to have pgx
142+
download/compile/install it
141143
```
142144
143145
## Creating a new Extension
@@ -274,6 +276,7 @@ USAGE:
274276
FLAGS:
275277
-h, --help Prints help information
276278
-r, --release compile for release mode (default is debug)
279+
-n, --no-schema Don't regenerate the schema
277280
-V, --version Prints version information
278281
279282
OPTIONS:
@@ -366,6 +369,7 @@ USAGE:
366369
FLAGS:
367370
-h, --help Prints help information
368371
-r, --release compile for release mode (default is debug)
372+
-n, --no-schema Don't regenerate the schema
369373
-V, --version Prints version information
370374
371375
OPTIONS:
@@ -439,6 +443,7 @@ USAGE:
439443
FLAGS:
440444
-h, --help Prints help information
441445
-r, --release compile for release mode (default is debug)
446+
-n, --no-schema Don't regenerate the schema
442447
-V, --version Prints version information
443448
--workspace Test all packages in the workspace
444449

cargo-pgx/src/cli.yml

+12
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ subcommands:
8383
short: r
8484
long: release
8585
help: compile for release mode (default is debug)
86+
- no-schema:
87+
short: ns
88+
long: no-schema
89+
help: Don't regenerate the schema
8690
- pg_config:
8791
short: c
8892
long: pg_config
@@ -178,6 +182,10 @@ subcommands:
178182
short: r
179183
long: release
180184
help: compile for release mode (default is debug)
185+
- no-schema:
186+
short: ns
187+
long: no-schema
188+
help: Don't regenerate the schema
181189
- features:
182190
long: features
183191
help: additional cargo features to activate (default is '--no-default-features')
@@ -210,6 +218,10 @@ subcommands:
210218
short: r
211219
long: release
212220
help: compile for release mode (default is debug)
221+
- no-schema:
222+
short: ns
223+
long: no-schema
224+
help: Don't regenerate the schema
213225
- workspace:
214226
long: workspace
215227
help: Test all packages in the workspace

cargo-pgx/src/commands/install.rs

+24-12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::process::{Command, Stdio};
1111
pub(crate) fn install_extension(
1212
pg_config: &PgConfig,
1313
is_release: bool,
14+
no_schema: bool,
1415
base_directory: Option<PathBuf>,
1516
additional_features: Vec<&str>,
1617
) -> Result<(), std::io::Error> {
@@ -47,13 +48,17 @@ pub(crate) fn install_extension(
4748
copy_file(shlibpath, dest, "shared library");
4849
}
4950

50-
copy_sql_files(
51-
pg_config,
52-
is_release,
53-
additional_features,
54-
&extdir,
55-
&base_directory,
56-
)?;
51+
if !no_schema || !get_target_sql_file(&extdir, &base_directory).exists() {
52+
copy_sql_files(
53+
pg_config,
54+
is_release,
55+
additional_features,
56+
&extdir,
57+
&base_directory,
58+
)?;
59+
} else {
60+
println!("{} schema generation", " Skipping".bold().yellow());
61+
}
5762

5863
println!("{} installing {}", " Finished".bold().green(), extname);
5964
Ok(())
@@ -124,19 +129,26 @@ pub(crate) fn build_extension(major_version: u16, is_release: bool, additional_f
124129
}
125130
}
126131

132+
fn get_target_sql_file(extdir: &PathBuf, base_directory: &PathBuf) -> PathBuf {
133+
let mut dest = base_directory.clone();
134+
dest.push(extdir);
135+
136+
let (_, extname) = crate::commands::get::find_control_file();
137+
let version = get_version();
138+
dest.push(format!("{}--{}.sql", extname, version));
139+
140+
dest
141+
}
142+
127143
fn copy_sql_files(
128144
pg_config: &PgConfig,
129145
is_release: bool,
130146
additional_features: Vec<&str>,
131147
extdir: &PathBuf,
132148
base_directory: &PathBuf,
133149
) -> Result<(), std::io::Error> {
134-
let mut dest = base_directory.clone();
135-
dest.push(extdir);
136-
150+
let dest = get_target_sql_file(extdir, base_directory);
137151
let (_, extname) = crate::commands::get::find_control_file();
138-
let version = get_version();
139-
dest.push(format!("{}--{}.sql", extname, version));
140152

141153
crate::schema::generate_schema(
142154
pg_config,

cargo-pgx/src/commands/package.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ pub(crate) fn package_extension(
2121
if !base_path.exists() {
2222
std::fs::create_dir_all(&base_path)?;
2323
}
24-
install_extension(pg_config, !is_debug, Some(base_path), additional_features)
24+
install_extension(
25+
pg_config,
26+
!is_debug,
27+
false,
28+
Some(base_path),
29+
additional_features,
30+
)
2531
}
2632

2733
fn build_base_path(pg_config: &PgConfig, is_debug: bool) -> Result<PathBuf, std::io::Error> {

cargo-pgx/src/commands/run.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ pub(crate) fn run_psql(
1414
pg_config: &PgConfig,
1515
dbname: &str,
1616
is_release: bool,
17+
no_schema: bool,
1718
additional_features: Vec<&str>,
1819
) -> Result<(), std::io::Error> {
1920
// stop postgres
2021
stop_postgres(pg_config)?;
2122

2223
// install the extension
23-
install_extension(pg_config, is_release, None, additional_features)?;
24+
install_extension(pg_config, is_release, no_schema, None, additional_features)?;
2425

2526
// restart postgres
2627
start_postgres(pg_config)?;

cargo-pgx/src/commands/test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::process::{Command, Stdio};
99
pub fn test_extension(
1010
pg_config: &PgConfig,
1111
is_release: bool,
12+
no_schema: bool,
1213
test_workspace: bool,
1314
additional_features: Vec<&str>,
1415
testname: Option<&str>,
@@ -32,7 +33,8 @@ pub fn test_extension(
3233
.env(
3334
"PGX_BUILD_PROFILE",
3435
if is_release { "release" } else { "debug" },
35-
);
36+
)
37+
.env("PGX_NO_SCHEMA", if no_schema { "true" } else { "false" });
3638

3739
if is_release {
3840
command.arg("--release");

cargo-pgx/src/main.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ fn do_it() -> std::result::Result<(), std::io::Error> {
132132
}
133133
("install", Some(install)) => {
134134
let is_release = install.is_present("release");
135+
let no_schema = install.is_present("no-schema");
135136
let features = install
136137
.values_of("features")
137138
.map(|v| v.collect())
@@ -154,7 +155,7 @@ fn do_it() -> std::result::Result<(), std::io::Error> {
154155
},
155156
};
156157

157-
install_extension(&pg_config, is_release, None, features)
158+
install_extension(&pg_config, is_release, no_schema, None, features)
158159
}
159160
("package", Some(package)) => {
160161
let is_debug = package.is_present("debug");
@@ -181,10 +182,12 @@ fn do_it() -> std::result::Result<(), std::io::Error> {
181182
.map(|v| v.collect())
182183
.unwrap_or(vec![]);
183184
let is_release = run.is_present("release");
185+
let no_schema = run.is_present("no-schema");
184186
run_psql(
185187
Pgx::from_config()?.get(pgver)?,
186188
&dbname,
187189
is_release,
190+
no_schema,
188191
features,
189192
)
190193
}
@@ -200,6 +203,7 @@ fn do_it() -> std::result::Result<(), std::io::Error> {
200203
}
201204
("test", Some(test)) => {
202205
let is_release = test.is_present("release");
206+
let no_schema = test.is_present("no-schema");
203207
let pgver = test.value_of("pg_version").unwrap_or("all");
204208
let test_workspace = test.is_present("workspace");
205209
let features = test
@@ -212,6 +216,7 @@ fn do_it() -> std::result::Result<(), std::io::Error> {
212216
test_extension(
213217
pg_config?,
214218
is_release,
219+
no_schema,
215220
test_workspace,
216221
features.clone(),
217222
testname,

pgx-tests/src/framework.rs

+4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ pub fn client() -> (postgres::Client, String) {
228228
fn install_extension() {
229229
eprintln!("installing extension");
230230
let is_release = std::env::var("PGX_BUILD_PROFILE").unwrap_or("debug".into()) == "release";
231+
let no_schema = std::env::var("PGX_NO_SCHEMA").unwrap_or("false".into()) == "true";
231232

232233
let mut command = Command::new("cargo");
233234
command
@@ -251,6 +252,9 @@ fn install_extension() {
251252
if is_release {
252253
command.arg("--release");
253254
}
255+
if no_schema {
256+
command.arg("--no-schema");
257+
}
254258

255259
let mut child = command.spawn().unwrap();
256260
let status = child.wait().unwrap();

0 commit comments

Comments
 (0)