Applications have several tables, each linked to a specific domain.
A good practice is to organize the database by modules, aligned to these domains.
Concepts
- Modularized Database: Database divided into modules that represent specific areas of the system.
- Schema: Set of objects in a database, organized in a logical way.
- Schema Objects: Tables, views, triggers and functions that are part of the schema.
Equivalence between Module and Schema
- The appropriate option to represent modules is the use of Schemas.
- Each module is represented by a schema in the database.
- Each schema contains its own objects, such as views, tables, triggers and functions.
- When building complex queries, it is crucial to consider the schema where the table is located.
Steps to creation
- Create a database.
- Configure initial settings.
- Create the necessary schemas.
- Create tables, views, triggers and functions in each schema.
- If necessary, define specific access rules for each schema.
Initialization
- Read the SQL scripts from each directory.
- Check if scripts exist before running.
- Run the scripts in the correct order.
- Execute the scripts within a transaction.
- Start the scripts when opening the application.
- Record progress and error logs.
Advantages of Creating Schemas
- Organization
- Modularization of the Database
- Separation of Responsibilities
- Navigability
- Code Reusability
- Enhanced Security
- Improved Collaboration
Challenges
- Complexity in Consultations.
- Verbosity in the Code.
- Maintaining Consistency between modules
- Standardization and Consistency in Nomenclature.
- Team Training.
Source Code:
- https://github.com/ortizdavid/golang-modular-software
LinkedIn: https://www.linkedin.com/in/ortiz-david
The above is the detailed content of Design of a Modular Database. For more information, please follow other related articles on the PHP Chinese website!