https://github.com/rvkulikov/pg-deps-management
Perfectionism through suffering
https://github.com/rvkulikov/pg-deps-management
postgresql
Last synced: 3 months ago
JSON representation
Perfectionism through suffering
- Host: GitHub
- URL: https://github.com/rvkulikov/pg-deps-management
- Owner: rvkulikov
- License: mit
- Created: 2020-12-30T23:35:28.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-08-28T19:56:49.000Z (11 months ago)
- Last Synced: 2025-08-29T01:37:58.496Z (11 months ago)
- Topics: postgresql
- Language: PLpgSQL
- Homepage:
- Size: 93.8 KB
- Stars: 72
- Watchers: 8
- Forks: 17
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# First time?
* Wanna move column in a table 'cause it hurts your inner perfectionist?
* You new CTO/DBA decided that your current table layout must be optimized by 4 bytes per row or business will fail?
* Your code standards changed and all inner joins must be rewritten with where again?
* Uhm, why not to add some other columns for our primary table?
* Simple grep in your migration directory for view definition give you 20 results?
* You look at your migration and see copy-pasted 1000 sloc of other migrations. And the same for rollback?!

## What is this
Complex enhancement/refactoring of https://gist.github.com/mateuszwenus/11187288
See related topics https://wiki.postgresql.org/wiki/Todo#Views_and_Rules
Recursively backup all dependent views, then modify base tables, then recreate all backuped views
## Supported features
| Feature | View | Materialized View | Comment |
|--------------------------------|------|-------------------|----------------------------------------|
| Create view | Yes | Yes | With reloptions, tablespace, (no) data |
| Create index | N/A | Yes | |
| Alter owner to | Yes | Yes | |
| Create rule | Yes | Yes | |
| Comment on view | Yes | Yes | |
| Comment on view column | Yes | Yes | |
| Grant privilege on view | Yes | Yes | With grant options |
| Grant privilege on view column | Yes | Yes | With grant options |
| Create policy | N/A | N/A | |
## Usage
```postgresql
select public.deps_save_and_drop_dependencies(
'public',
'my_table',
'{
"dry_run": true,
"verbose": false,
"populate_materialized_view": false
}'
);
-- alter my_table...
select public.deps_restore_dependencies(
'public',
'my_table',
'{
"dry_run": true,
"verbose": false
}'
);
```
## Options
* deps_save_and_drop_dependencies
* `dry_run` Run without actually dropping dependencies
* `verbose` Show debug log
* `populate_materialized_view` Enable or disable materialized view refresh-on-create via `WITH [NO] DATA` flag
* deps_restore_dependencies
* `dry_run` Run without actually executing ddl statements
* `verbose` Show debug log