diff options
Diffstat (limited to 'docs/central/Database.md')
-rw-r--r-- | docs/central/Database.md | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/docs/central/Database.md b/docs/central/Database.md index bfe014b..2120243 100644 --- a/docs/central/Database.md +++ b/docs/central/Database.md @@ -1,9 +1,36 @@ # Database -A MySQL database is required for dn42peering central to work. Before installing the central program, make sure you have a proper database with tables setup. +A MySQL database is required for dn42peering central to work. Before installing the central program, make sure you have a proper database with necessary privileges setup. -Here is the SQL used to setup a production database: +Create a database and user, then grant it with all data and structure privileges. The server will automatically create tables and upgrade schema in the future. -See [0-init.sql](sql/0-init.sql) for creating initial schema. +## Auto Migration -Note that the SQL script will update with schema updates. Please follow the docs/sql/ with the latest version.
\ No newline at end of file +The server will migrate database schema before starts. All migration SQL files can be found in the resources. + +In case migration fails, the server will return an exception with instructions and exit. + +Follow the instructions and combine it with the SQL files to solve the problem yourself. + +For example, a duplicated column name may be caused by duplicated SQL statements. In this case, delete the column may fix the problem. + +After manually inspection, change the migration action to `repair`. In this mode, the server automatically rolls back the history and becomes ready to retry. + +The server will never fix database errors itself. Repair mode only rolls back history and version state. + +### Migrate modes + +```json +{ + "database": { + "migrate": "auto" + } +} +``` + +Case-insensitive. + +* **auto**: Default mode. The server will automatically upgrades the schema. +* **auto_no_baseline**: Similar to `auto`, but will not set the version to 3 (which is the last schema version before implementing migration) if the database is not empty but does not have a history record. In this case, it will fail. +* **disabled**: Not recommended. Disable all migration and start silently. This may led to schema errors. +* **repair**: Repair the history record after incomplete migrations. The server will only roll back history state and exit. Use this as an oneshot action after manually fixing database structure. Good luck!
\ No newline at end of file |