Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support database specific DDL in migrations #19649

Open
bx80 opened this issue Aug 19, 2022 · 0 comments
Open

Support database specific DDL in migrations #19649

bx80 opened this issue Aug 19, 2022 · 0 comments
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.

Comments

@bx80
Copy link
Contributor

bx80 commented Aug 19, 2022

Migration scripts run during Matomo updates often contain MySQL specific DDL statements. Migrations are also run as part of the test suite setup. Alternative databases commonly have minor differences in schema structure and DDL statements, in order to support them we need an option for migration scripts to provide DDL statements for multiple databases if required.

Suggested Approach

  • Extend the core/Updates and core/Updater classes to allow each migration in the migrations array to be optionally associated with a specific database type.
// Current:
return [
    $this->migration->db->sql('UPDATE ' . $table . ' SET hash_algo = "sha512" where hash_algo is null')
];

// After rework:
return [
    'Mysql' => $this->migration->db->sql('UPDATE ' . $table . ' SET hash_algo = "sha512" where hash_algo is null'),
    'TiDB' =>  $this->migration->db->sql('UPDATE ' . $table . ' SET hash_algo = "twofish" where hash_algo is null'),
];

// Works for all types:
return [
    'all' => $this->migration->db->sql('UPDATE ' . $table . ' SET hash_algo = "sha512" where hash_algo is null')
];
  • If 'all' is specified then the migration will run for any PDO adapter, if a database type is specified then the migration will only run if that PDO adapter is being used.

  • The Update files in core/Updates/ may then provide different schema changes for different db types if needed.

  • Rework all existing migrations to use the new format.

  • As old migrations are re-run during integration tests, future database support may involve retrospectively adding database specific DDL to existing migrations as required.

@bx80 bx80 added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

No branches or pull requests

2 participants