dump --multi-file
option allows you to split your schema into modular files organized by database objects, enabling better collaboration, clearer ownership, and easier maintenance.
This approach is ideal for:
- Large schemas with hundreds of tables, views, and functions
- Teams where different developers/teams own different parts of the schema
- Schemas that need granular code review processes
Workflow
Step 1: Initialize Multi-File Structure
Set up your schema directory structure and dump your existing schema into multiple files:Step 2: Development Workflow
Use the multi-file structure to define the desired state of your schema components:Step 3: Team Collaboration
Teams work on separate branches and test independently before combining changes for production deployment:Step 4: Production Deployment
Deploy schema changes safely to production using the established multi-file workflow:File Organization Strategies
By Object Type (Default)
pgschema generates files organized by database object type:Custom Organization
You can reorganize files into any structure you prefer and update the\i
directives in main.sql
:
By Business Domain
main.sql
to match your structure:
Hybrid Approach
main.sql
file contains the correct \i
directives that match your chosen file organization.
Folder Includes
The\i
directive supports including entire folders by adding a trailing slash (/
). This automatically includes all .sql
files in the folder in alphabetical order, and recursively processes any subdirectories:
main.sql
:
- Files are processed in alphabetical order by filename
- Subdirectories are processed recursively using depth-first search
- Only
.sql
files are included; other files are ignored - Folder paths must end with
/
to be recognized as folders - Error if folder doesn’t exist or if you try to include a file as a folder
Nested Includes
The\i
directive can be nested, allowing for hierarchical file organization: