Skip to content
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

move init() into create extension #28

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pg_later"
version = "0.0.9"
version = "0.0.10"
edition = "2021"
publish = false

Expand All @@ -18,7 +18,7 @@ pg_test = []
anyhow = "1.0.72"
chrono = {version = "0.4.26", features = ["serde"] }
log = "0.4.19"
pgmq = "0.14.4"
pgmq = "0.15.1"
pgrx = "=0.9.8"
serde = "1.0.164"
serde_json = "1.0.99"
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ Initialize the extension's backend:

```sql
CREATE EXTENSION pg_later CASCADE;

SELECT pglater.init();
```

Execute a SQL query now:
Expand Down
3 changes: 3 additions & 0 deletions sql/pgmq.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- todo: these will become schema qualified when pgmq is moved to its own schema
select pgmq_create_non_partitioned('pg_later_jobs');
select pgmq_create_non_partitioned('pg_later_results');
17 changes: 0 additions & 17 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
use pgrx::prelude::*;
use pgrx::spi::SpiTupleTable;

#[pg_extern]
fn init() -> Result<bool, spi::Error> {
let setup_queries = [
"select pgmq_create_non_partitioned('pg_later_jobs')",
"select pgmq_create_non_partitioned('pg_later_results')",
];
for q in setup_queries {
let ran: Result<_, spi::Error> = Spi::connect(|mut c| {
let _ = c.update(q, None, None)?;
Ok(())
});

ran?
}
Ok(true)
}

/// send a query to be executed by the next available worker
#[pg_extern]
pub fn exec(query: &str) -> Result<i64, spi::Error> {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ mod clf;
mod executor;
mod util;

extension_sql_file!("../sql/pgmq.sql");

/// This module is required by `cargo pgrx test` invocations.
/// It must be visible at the root of your extension crate.
#[cfg(test)]
Expand Down
5 changes: 0 additions & 5 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ async fn test_lifecycle() {
.await
.expect("failed to create");

let _ = sqlx::query("SELECT pglater.init()")
.execute(&conn)
.await
.expect("failed to init");

// simple select case
let q0 = sqlx::query("SELECT pglater.exec('select 1')")
.fetch_one(&conn)
Expand Down