A collection of database schemas designed for various business domains and services. This repository provides standardized, documented database implementations that can be used as starting points for different types of applications.
This repository contains a library of database schemas, each tailored for specific business domains and services. Each database implementation includes:
- SQL DDL scripts (tables | optional: views, indexes, functions, procedures, triggers)
- Documentation (discribe abot business logical and analyze database).
- Database diagrams (text and visual formats).
- Production features (including audit trails, security measures, and performance optimizations)
- Standardized conventions (ensuring consistency across all implementations)
database-libraries/
├── databases/ # Database implementations
│ ├── [future_service_1]/ # Each database can serve a service
│ ├── [future_service_2]/
│ └── [future_service_N]/
├── documents/ # Documentation and conventions
│ └── convention.md # Coding standards and conventions
├── tools/ # Database utilities and tools
└── README.md # This file
- PostgreSQL 13+ (recommended: PostgreSQL 15+)
- Required Extensions:
uuid-ossp- For UUID generationpgcrypto- For password hashing and encryption
-
Clone the repository
git clone https://github.com/TrongAJTT/postgres-database-library.git cd database-libraries -
Create a new database
CREATE DATABASE your_service_name;
-
Enable required extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE EXTENSION IF NOT EXISTS "pgcrypto";
-
Run the SQL scripts in order
# For Digital Comic Business (example) psql -d your_database -f databases/digital_comic_business/1_TABLES.sql psql -d your_database -f databases/digital_comic_business/2_VIEWS.sql psql -d your_database -f databases/digital_comic_business/3_INDEXES.sql psql -d your_database -f databases/digital_comic_business/4_FUNCTIONS.sql psql -d your_database -f databases/digital_comic_business/5_PROCEDURES.sql psql -d your_database -f databases/digital_comic_business/6_TRIGGERS.sql
-- Connect to your database
\c your_database
-- Enable extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
-- Run all scripts for Digital Comic Business
\i databases/digital_comic_business/1_TABLES.sql
\i databases/digital_comic_business/2_VIEWS.sql
\i databases/digital_comic_business/3_INDEXES.sql
\i databases/digital_comic_business/4_FUNCTIONS.sql
\i databases/digital_comic_business/5_PROCEDURES.sql
\i databases/digital_comic_business/6_TRIGGERS.sqlEach database implementation follows a consistent architecture:
- Core schemas - Standard schemas (
core,legal,audit) for common functionality - Business-specific schemas - Domain-specific schemas tailored to each business type
- UUID primary keys - Scalable and secure identifier system
- Comprehensive indexing - Optimized for common query patterns
- Audit trails - Complete activity logging and change tracking
- Security measures - Password hashing, access controls, and data protection
All implementations include these core schemas:
core- User management, authentication, and roleslegal- Document management and complianceaudit- Activity logging and audit trails
- Review the existing implementation that best matches your needs
- Modify the schema structure to fit your specific requirements
- Update table names and relationships to match your domain
- Customize business logic in functions and procedures
- Adjust security policies for your specific use case
To add a new database implementation:
- Create a new directory in
databases/with descriptive name - Follow the file naming convention (1_TABLES.sql, 2_VIEWS.sql, etc.)
- Implement the standard schemas (core, content, commerce, etc.)
- Add comprehensive documentation (README_en.md, README_vi.md)
- Create database diagrams (DIAGRAM.md, DIAGRAM.svg)
- Update this README with the new service information
README_en.md- English documentation with setup instructionsREADME_vi.md- Vietnamese documentation (optional)DIAGRAM.md- Text-based database schema diagramDIAGRAM.png- Visual database schema diagram
documents/convention.md- Coding standards and conventionsREADME.md- This overview file
We welcome contributions to expand the database library! Here's how you can help:
- Choose a business domain that's not yet covered
- Follow the established conventions (see
documents/convention.md) - Create comprehensive documentation in both English and Vietnamese
- Include database diagrams for visual understanding (using mermaid graph or export diagram via Postgres's ERD tool)
- Test with sample data and common use cases
- Identify areas for improvement (performance, security, features)
- Follow the existing patterns and conventions
- Update documentation to reflect changes
- Test thoroughly to ensure no regressions
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This repository is designed to be a living library that grows with the needs of the development community. Each implementation is thoroughly tested and follows industry best practices for database design and security.