Skip to content

Support database specific DDL in migrations #19649

@bx80

Description

@bx80

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementFor new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions