graphql-engine/scripts/edit-pg-dump/README.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
665 B
Markdown
Raw Normal View History

add script and now.sh function to edit pg_dump output (close #1861) (#1884) <!-- Thank you for submitting this PR! :) --> <!-- Provide a general summary of your changes in the Title above ^, end with (close #<issue-no>) or (fix #<issue-no>) --> ### Description <!-- The title might not be enough to convey how this change affects the user. --> <!-- Describe the changes from a user's perspective --> This PR adds a bash script and a serverless function to clean up the output of `pg_dump` so that it can be used as a migration file for Hasura. This can be later integrated with the CLI so that the cleanup is handled by CLI. ### Affected components <!-- Remove non-affected components from the list --> - Scripts ### Related Issues <!-- Please make sure you have an issue associated with this Pull Request --> <!-- And then add `(close #<issue-no>)` to the pull request title --> <!-- Add the issue number below (e.g. #234) --> #1861 ### Solution and Design <!-- How is this issue solved/fixed? What is the design? --> <!-- It's better if we elaborate --> - A serverless function written in Go gets the SQL content though HTTP POST. - A set of pre-defined lines are removed from this SQL string. - SQL comments are removed using regex matching. - Postgres triggers created by Hasura for use with event triggers are removed with regex matching. - Empty newlines are removed by regex matching. - Resulting string is returned in the HTTP response. ### Steps to test and verify <!-- If this is a feature, what are the steps to try them out? --> <!-- If this is a bug-fix, how do we verify the fix? --> ```bash curl --data-binary @filename.sql https://hasura-edit-pg-dump.now.sh > newfile.sql ``` ### Limitations, known bugs & workarounds <!-- Limitations of the PR, known bugs and suggested workarounds --> NA <!-- Feel free to delete these comment lines -->
2019-03-27 19:06:58 +03:00
# hasura-edit-pg-dump
This is a serverless function written in Go and deployed onto now.sh which can
take the SQL output from `pg_dump` and clean it up so that it can be used as a
add script and now.sh function to edit pg_dump output (close #1861) (#1884) <!-- Thank you for submitting this PR! :) --> <!-- Provide a general summary of your changes in the Title above ^, end with (close #<issue-no>) or (fix #<issue-no>) --> ### Description <!-- The title might not be enough to convey how this change affects the user. --> <!-- Describe the changes from a user's perspective --> This PR adds a bash script and a serverless function to clean up the output of `pg_dump` so that it can be used as a migration file for Hasura. This can be later integrated with the CLI so that the cleanup is handled by CLI. ### Affected components <!-- Remove non-affected components from the list --> - Scripts ### Related Issues <!-- Please make sure you have an issue associated with this Pull Request --> <!-- And then add `(close #<issue-no>)` to the pull request title --> <!-- Add the issue number below (e.g. #234) --> #1861 ### Solution and Design <!-- How is this issue solved/fixed? What is the design? --> <!-- It's better if we elaborate --> - A serverless function written in Go gets the SQL content though HTTP POST. - A set of pre-defined lines are removed from this SQL string. - SQL comments are removed using regex matching. - Postgres triggers created by Hasura for use with event triggers are removed with regex matching. - Empty newlines are removed by regex matching. - Resulting string is returned in the HTTP response. ### Steps to test and verify <!-- If this is a feature, what are the steps to try them out? --> <!-- If this is a bug-fix, how do we verify the fix? --> ```bash curl --data-binary @filename.sql https://hasura-edit-pg-dump.now.sh > newfile.sql ``` ### Limitations, known bugs & workarounds <!-- Limitations of the PR, known bugs and suggested workarounds --> NA <!-- Feel free to delete these comment lines -->
2019-03-27 19:06:58 +03:00
migration file with Hasura.
1. SQL front matter, like `SET` statements are removed.
2. `CREATE SCHEMA public` is removed.
3. Comments (`--`) and empty newlines are removed.
4. Postgres triggers created by Hasura for event triggers are removed.
add script and now.sh function to edit pg_dump output (close #1861) (#1884) <!-- Thank you for submitting this PR! :) --> <!-- Provide a general summary of your changes in the Title above ^, end with (close #<issue-no>) or (fix #<issue-no>) --> ### Description <!-- The title might not be enough to convey how this change affects the user. --> <!-- Describe the changes from a user's perspective --> This PR adds a bash script and a serverless function to clean up the output of `pg_dump` so that it can be used as a migration file for Hasura. This can be later integrated with the CLI so that the cleanup is handled by CLI. ### Affected components <!-- Remove non-affected components from the list --> - Scripts ### Related Issues <!-- Please make sure you have an issue associated with this Pull Request --> <!-- And then add `(close #<issue-no>)` to the pull request title --> <!-- Add the issue number below (e.g. #234) --> #1861 ### Solution and Design <!-- How is this issue solved/fixed? What is the design? --> <!-- It's better if we elaborate --> - A serverless function written in Go gets the SQL content though HTTP POST. - A set of pre-defined lines are removed from this SQL string. - SQL comments are removed using regex matching. - Postgres triggers created by Hasura for use with event triggers are removed with regex matching. - Empty newlines are removed by regex matching. - Resulting string is returned in the HTTP response. ### Steps to test and verify <!-- If this is a feature, what are the steps to try them out? --> <!-- If this is a bug-fix, how do we verify the fix? --> ```bash curl --data-binary @filename.sql https://hasura-edit-pg-dump.now.sh > newfile.sql ``` ### Limitations, known bugs & workarounds <!-- Limitations of the PR, known bugs and suggested workarounds --> NA <!-- Feel free to delete these comment lines -->
2019-03-27 19:06:58 +03:00
This app is available at https://hasura-edit-pg-dump.now.sh
Usage:
```bash
curl --data-binary @file.sql https://hasura-edit-pg-dump.now.sh > cleaned.sql
```
A bash version is also available:
```bash
./edit-pg-dump.sh filename.sql
```