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

Patch assignment #69

Merged
merged 3 commits into from
Aug 21, 2023
Merged
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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgmq"
version = "0.14.1"
version = "0.14.2"
edition = "2021"
authors = ["Tembo.io"]
description = "Postgres extension for PGMQ"
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgmq"
version = "0.16.0"
version = "0.16.1"
edition = "2021"
authors = ["Tembo.io"]
description = "A distributed message queue for Rust applications, on Postgres."
Expand Down
19 changes: 13 additions & 6 deletions core/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ pub fn assign_queue(name: CheckedName<'_>) -> Result<String, PgmqError> {
}

pub fn assign_archive(name: CheckedName<'_>) -> Result<String, PgmqError> {
Ok(assign(&format!("{name}_archive; ")))
Ok(assign(&format!("{name}_archive")))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjmiller609 this is the bug

}

pub fn unassign_queue(name: CheckedName<'_>) -> Result<String, PgmqError> {
Expand All @@ -362,14 +362,15 @@ pub fn assign(table_name: &str) -> String {
SELECT 1
FROM pg_depend
WHERE refobjid = (SELECT oid FROM pg_extension WHERE extname = 'pgmq')
AND objid = (SELECT oid FROM pg_class WHERE relname = '{TABLE_PREFIX}_{table_name}')
AND objid = (
SELECT oid
FROM pg_class
WHERE relname = '{TABLE_PREFIX}_{table_name}'
)
) THEN

EXECUTE 'ALTER EXTENSION pgmq ADD TABLE {PGMQ_SCHEMA}.{TABLE_PREFIX}_{table_name}';

END IF;

END $$;
END $$;
"
)
}
Expand Down Expand Up @@ -405,6 +406,12 @@ pub fn check_input(input: &str) -> Result<(), PgmqError> {
mod tests {
use super::*;

#[test]
fn test_assign() {
let query = assign("my_queue_archive");
assert!(query.contains("WHERE relname = 'pgmq_my_queue_archive'"));
}

#[test]
fn test_create() {
let queue_name = CheckedName::new("yolo").unwrap();
Expand Down
Empty file added sql/pgmq--0.14.1--0.14.2.sql
Empty file.
7 changes: 7 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ async fn test_lifecycle() {
.await
.expect("failed to create queue");

// creating a queue must be idempotent
// create with same name again, must be no error
let _ = sqlx::query(&format!("SELECT pgmq_create('{test_default_queue}');"))
.execute(&conn)
.await
.expect("failed to create queue");

let msg_id = sqlx::query(&format!(
"SELECT * from pgmq_send('{test_default_queue}', '{{\"hello\": \"world\"}}');"
))
Expand Down
Loading