🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Database
This page was created by Stephanie on 2024-05-20. Last edited by Wikiadmin on 2026-07-29.

A database stores the persistent data for your MDriven application, and this page helps MDriven Designer and MDrivenServer users understand where that data fits in the application lifecycle.

What a database does

A database is an organized collection of structured data managed by a database management system (DBMS). It keeps data after an application stops and starts, and allows applications and users to read and change that data.

For example, an application may have customers, products, and orders. The database stores the customer names, product prices, and order records so that the same information is available the next time a user opens the application.

A spreadsheet is a useful small-scale comparison: each row can represent one item and each column one property. A database is designed to manage this type of structured data at larger scale and can support multiple users reading and updating it.

Databases in MDriven

In MDriven, you define the application's structure in a model. The model contains classes, attributes, and relationships. When the application uses SQL persistence, that model is stored in an SQL database according to MDriven's persistence mapping.

For example, if your model contains a Customer class with a Name attribute, and an Order class related to Customer, the database holds the records that represent customers and orders. The detailed representation of model classes in the database is described in How Your Classes are Stored in the SQL Database When Using MDriven.

Term Meaning in this context Example
Model The structure you define for the application. Customer, Order, their attributes, and their relationship.
Database schema The database structure used to store the model's data. The stored structure for customer and order data.
Data The individual values and records stored using that structure. A customer named Alex and that customer's order.
DBMS The database software that manages the schema and data. PostgreSQL, MySQL, or Microsoft SQL Server (MSSQL) in the provided production deployment options.

Choose the right documentation for your task

This page is an overview. Use the following pages when you need to perform a database-related task.

If you need to... Go to...
Understand SQL commands and their purpose Documentation:SQL
Understand how MDriven classes are represented in an SQL database Documentation:SQL Database
Change a model and update the database structure to match it Documentation:Database evolve
Tune SQL persistence mapping in MDriven Framework Documentation:Working with Code and Persistence Mapping
Download a database snapshot or upload one to replace a selected site's Admin DB Documentation:Database download and upload
Configure PostgreSQL, MySQL, or MSSQL in a production Docker deployment and connect MDrivenServer to it Documentation:Configuring Production Databases PostgreSQL MySQL MSSQL
Set up a PostgreSQL connection Documentation:PostgreSQL
Work with SQLite Documentation:SQLite

Keep the model and database aligned

When you change the model, the database may also need to change. Database evolution is the process in which MDrivenServer or MDriven Designer changes the database to match the current model.

For example, adding an attribute to a class changes the model structure. Before relying on that new attribute in persisted data, ensure that the database has been evolved for the changed model. Some changes are not handled automatically by the evolve engine. When MDriven reports that a change will not be evolved, perform the required change manually using the SQL Server you use. See Documentation:Database evolve for the process and limitations.

Production databases

Production deployment packages with a PostgreSQL, MySQL, or MSSQL option include Docker Compose configuration that sets up the selected database. On first docker compose up -d, the database schema is created from the initialization files supplied for that database type.

The database runs on the internal Docker network with MDrivenServer. To connect MDrivenServer to it, open the MDrivenServer interface, go to Running > Model, pause the app if it is running, select the matching Connection Type, and set the Alternate Connection String. Start the app after setting the connection details. Follow the exact database-specific settings in Documentation:Configuring Production Databases PostgreSQL MySQL MSSQL.

Database files are mounted to host directories so they persist across container restarts and updates. The documented directories are /postgres-data for PostgreSQL, /mysql-data for MySQL, and /mssql-data for MSSQL. Treat these persistent data locations as part of your backup planning.

Work with database data carefully

You can use SQL to query, insert, update, and delete database records, as well as create database objects and set permissions. Learn the available SQL operations in Documentation:SQL.

When inspecting or managing a production Docker database from a tool on the host machine, connect to 127.0.0.1 (or the server's public IP) and the externally exposed port from compose.yaml. Do not use Docker's internal service names such as mysql, postgres, or mssql from a host-side tool. Use the credentials configured in the relevant environment file, as described in Documentation:Configuring Production Databases PostgreSQL MySQL MSSQL.

See also