Skip to content

[Database] Add Custom Database Migrations for Operators#4892

Merged
Akkadius merged 3 commits intomasterfrom
akkadius/custom-database-migrations
May 16, 2025
Merged

[Database] Add Custom Database Migrations for Operators#4892
Akkadius merged 3 commits intomasterfrom
akkadius/custom-database-migrations

Conversation

@Akkadius
Copy link
Copy Markdown
Contributor

@Akkadius Akkadius commented May 16, 2025

Description

This PR adds the ability for operators to be able to add their own database migrations if they maintain their own fork with custom changes. It allows them to keep their DDL as code in their codebase so their team can automatically stay up to date.

This is an optional feature.

It works by setting CUSTOM_BINARY_DATABASE_VERSION in version.h to a value greater than 1

The custom manifest is located common/database/database_update_manifest_custom.cpp

The rest works as you'd expect from the rest of the system.

Type of change

  • New feature (non-breaking change which adds functionality)

Testing

 World |    Info    | CheckVersionsUpToDate ---------------------------------------------------------------------- 
 World |    Info    | CheckVersionsUpToDate   Server | database [9323] binary [9323] up to date 
 World |    Info    | CheckVersionsUpToDate   Custom | database [1] binary [1] up to date 
 World |    Info    | CheckVersionsUpToDate   Config | [server.auto_database_updates] [true] 
 World |    Info    | CheckVersionsUpToDate ---------------------------------------------------------------------- 
 World |   Query    | QueryDatabase SHOW TABLES LIKE 'new_table' -- (0 rows affected) (0.000281s)
 World |    Info    | UpdateManifest [1]  [missing] | [2025_05_16_new_database_check_test] 
 World |    Info    | UpdateManifest ---------------------------------------------------------------------- 
 World |    Info    | UpdateManifest Automatically backing up database before applying updates 
 World |    Info    | UpdateManifest ---------------------------------------------------------------------- 
 World |    Info    | DatabaseDump MySQL installed [mysql  Ver 15.1 Distrib 10.11.11-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper] 
 World |    Info    | DatabaseDump Database [peq] Host [mariadb] Username [eqemu] 
 World |    Info    | DatabaseDump Backing up database [mysqldump --defaults-extra-file=login.my.cnf peq --allow-keywords --extended-insert --max-allowed-packet=1G --net-buffer-length=32704 --skip-lock-tables   > backups/peq-2025-05-16.sql] 
 World |    Info    | DatabaseDump This can take a few minutes depending on the size of your database 
 World |    Info    | DatabaseDump LOADING... PLEASE WAIT... 
 World |    Info    | DatabaseDump Database dump created at [backups/peq-2025-05-16.sql] 
 World |    Info    | DatabaseDump Compression requested. Compressing dump [backups/peq-2025-05-16.sql] 
 World |    Info    | DatabaseDump Compressed dump created at [backups/peq-2025-05-16.tar.gz] 
 World |    Info    | UpdateManifest ---------------------------------------------------------------------- 
 World |    Info    | UpdateManifest Running database migrations. Please wait... 
 World |    Info    | UpdateManifest ---------------------------------------------------------------------- 
 World |    Info    | UpdateManifest [1] [2025_05_16_new_database_check_test] [ok] 
 World |    Info    | UpdateManifest ---------------------------------------------------------------------- 
 World |    Info    | CheckDbUpdates Updates ran successfully, setting database version to [1] from [0] 

You can see the new table being created correctly

MariaDB [peq]> show tables like '%new_table%';
+-----------------------------+
| Tables_in_peq (%new_table%) |
+-----------------------------+
| new_table                   |
+-----------------------------+
1 row in set (0.000 sec)

MariaDB [peq]> show create table new_table;
+-----------+---------------------------------------------------------------------------------------------------------------------------------+
| Table     | Create Table                                                                                                                    |
+-----------+---------------------------------------------------------------------------------------------------------------------------------+
| new_table | CREATE TABLE `new_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-----------+---------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

Checklist

  • I have tested my changes
  • I have performed a self-review of my code. Ensuring variables, functions and methods are named in a human-readable way, comments are added only where naming of variables, functions and methods can't give enough context.
  • I own the changes of my code and take responsibility for the potential issues that occur

@Akkadius Akkadius merged commit 276b7e2 into master May 16, 2025
2 checks passed
@Akkadius Akkadius deleted the akkadius/custom-database-migrations branch May 16, 2025 18:38
Akkadius pushed a commit that referenced this pull request May 18, 2025
* Add custom database version output to CLI from #4892

* Spacing alignment
@Akkadius Akkadius mentioned this pull request May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants