Skip to content

Create schemas, tables and indexes without "if not exists"#259

Open
pinodeca wants to merge 1 commit into
mainfrom
if-not-exists
Open

Create schemas, tables and indexes without "if not exists"#259
pinodeca wants to merge 1 commit into
mainfrom
if-not-exists

Conversation

@pinodeca

@pinodeca pinodeca commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Eliminates silent schema adoption and IF NOT EXISTS from the install path, following the pg_cron anti-squatting model.

  • Control file now uses schema = pg_catalog; the df and _duroxide schemas are created in a pgrx bootstrap block with plain CREATE SCHEMA (no IF NOT EXISTS). A pre-existing/squatted df schema now makes CREATE EXTENSION fail loudly (duplicate_schema) instead of being silently adopted.
  • df.duroxide_schema() moved into the bootstrap block; the separate create_duroxide_schema block is removed.
  • Removed IF NOT EXISTS from install-script tables (df.nodes, df.instances, df.vars, df._worker_epoch) and indexes so install fails loud on conflicts.
  • #[pg_schema] mod df {} retained (required so #[pg_extern(schema = "df")] functions resolve). Its redundant CREATE SCHEMA IF NOT EXISTS df is now a no-op after bootstrap; the pgspot PS010 allowlist entry stays with an updated explanatory comment.

Why not drop the PS010 exception?

pgrx's #[pg_schema] unconditionally emits CREATE SCHEMA IF NOT EXISTS df into the generated install SQL, and that string isn't configurable from source. Removing it would require post-processing the generated SQL, so the (now no-op) line and its single-line PS010 allowlist entry remain.

Testing

  • Unit: 183 passed
  • E2E suite: 33 passed, 0 failed (incl. 12_extension_lifecycle anti-squat Test 2)
  • Upgrade tests: 36 passed (B1 backward-compat vs v0.2.2/v0.2.3 schemas, B2 data-compat, Scenario A schema comparison)
  • cargo fmt --check, cargo clippy: clean
  • pgspot gate: PASS (install SQL 0 errors / 0 warnings)

Switch the control file to schema = pg_catalog and create the df and
_duroxide schemas in a pgrx bootstrap block using plain CREATE SCHEMA
(no IF NOT EXISTS), so a pre-existing/squatted df schema makes CREATE
EXTENSION fail loudly instead of being silently adopted.

- Move df.duroxide_schema() into the bootstrap block alongside the
  CREATE SCHEMA statements and drop the separate create_duroxide_schema
  block.
- Remove IF NOT EXISTS from the install-script tables (df.nodes,
  df.instances, df.vars, df._worker_epoch) and indexes so install fails
  loud on conflicts.
- Keep #[pg_schema] mod df {} (required for df-qualified externs); its
  redundant CREATE SCHEMA IF NOT EXISTS df is now a no-op. Update the
  pgspot PS010 allowlist comment to explain why it remains.

Tests: unit (183), 12_extension_lifecycle anti-squat, fmt, clippy,
pgspot gate all pass.
@pinodeca pinodeca changed the title Anchor extension to pg_catalog; create df via fail-loud bootstrap Install script creates schema, tables and indexes without "if not exists" Jun 19, 2026
@pinodeca pinodeca changed the title Install script creates schema, tables and indexes without "if not exists" Create schemas, tables and indexes without "if not exists" Jun 19, 2026
Comment thread src/lib.rs
extension_sql!(
r#"
CREATE SCHEMA df;
CREATE SCHEMA _duroxide;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a little confused, this runs even for an upgrade and then we'll have both duroxide and _duroxide schemas? (I guess this is preexisting behavior, but still seems weird...) But it's kind of hard to tell what the final .sql scripts look like.

Followup: WDYT about checking in the generated install/upgrade scripts to make confirming this kind of thing easier?

Comment thread pg_durable.control
# present explicitly (they are otherwise PostgreSQL defaults).
relocatable = false
superuser = true
trusted = false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you mean to get rid of the trusted line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants