Skip to content

Clean up pg_dump output in schema and rollup#10

Merged
pksunkara merged 1 commit into
masterfrom
clean-pg-dump-output-17102444846717328940
Jan 17, 2026
Merged

Clean up pg_dump output in schema and rollup#10
pksunkara merged 1 commit into
masterfrom
clean-pg-dump-output-17102444846717328940

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

This change automates the cleanup of pg_dump output in crude. It introduces a clean_pg_dump_output function in src/db/postgres.rs that uses regex to filter out environment-specific lines (like version headers and the new \restrict security wrappers introduced in recent PostgreSQL versions). This logic is applied to PostgresAdapter::dump_schema and also to the manual pg_dump calls in src/commands/rollup.rs, ensuring that all schema and data dumps produced by the tool are consistent and diff-friendly. Unit tests have been added to verify the filtering logic.


PR created automatically by Jules for task 17102444846717328940 started by @pksunkara

@google-labs-jules
Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@pksunkara pksunkara marked this pull request as ready for review January 17, 2026 01:56
Automatically remove version headers and psql meta-commands (\restrict,
\unrestrict) from pg_dump output to ensure consistency across
environments and CI.

The following lines are now removed:
- Lines starting with '-- Dumped by pg_dump version'
- Lines starting with '\restrict <key>' and the line immediately following it
- Lines starting with '\unrestrict <key>' and the line immediately following it

This matches the behavior of the following sed command:
sed -i -e '/^-- Dumped by pg_dump version/d' -e '/^\\restrict [^[:space:]]\+/{N;d;}' -e '/^\\unrestrict [^[:space:]]\+/{N;d;}' db/schema.sql

The implementation uses a static method `PostgresAdapter::clean_pg_dump_output`
to filter the output using iterators. This method is used in both
`PostgresAdapter::dump_schema` and the `rollup` command.

Refactor database dumping logic and clean pg_dump output

1. Updated `DatabaseAdapter` trait with `dump_schema` and `dump_data`
   methods, both taking an `exclude_migrations` boolean parameter.
2. Implemented these methods for `PostgresAdapter` and `SqliteAdapter`.
3. In `PostgresAdapter`, added automatic filtering of `pg_dump` output
   to remove environment-specific headers and `\restrict`/`\unrestrict`
   commands, ensuring consistency across environments and CI.
4. Simplified `rollup` command by using the new `DatabaseAdapter`
   methods, removing manual CLI calls and conditional logic for
   different databases.
5. Added unit tests for the Postgres dump cleaning logic.
@pksunkara pksunkara force-pushed the clean-pg-dump-output-17102444846717328940 branch from aeb1958 to 8a9ca67 Compare January 17, 2026 02:20
@pksunkara pksunkara merged commit 621067d into master Jan 17, 2026
13 checks passed
@pksunkara pksunkara deleted the clean-pg-dump-output-17102444846717328940 branch January 17, 2026 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant