One migration owner for several applications

One Doctrine Migrations executor, two MySQL readers and 17 checks of schema, privileges and replay in one Symfony Demo.

A shared source needs a defined owner of change.

Several applications can share a database while doing different jobs. One edits articles, another presents them to readers, and a third returns an API response. Shared tables do not automatically mean that every process should change their structure independently. A coherent history needs an explicit place where accepted migrations come together and their execution order is defined.

Permissions are only part of the problem. Two processes can have sufficient privileges and individually correct SQL files while holding different ideas about the current schema. I therefore separate the author of a schema change, its migration executor and the consumer of the resulting data. A new teaching catalog with one owner and two readers makes these responsibilities concrete.

Three responsibilities around one schema

The author of a change understands why a table or column is needed, what data it stores and which earlier changes it depends on. In a modular product, this can be the package that owns the relevant tables. That package does not also need to own the server, credentials or the entire release process.

The executor brings the required migrations into one agreed sequence for a particular database. Its database identity receives the authority to change the schema. A reader uses a defined data contract and does not create an alternative history for the same table.

Role in the example Responsibility Outside its task
Teaching schema owner Keeps two migrations and their order Serving public lists
Single executor Applies migrations and maintains their history Continuously serving reader requests
Two readers Retrieve a card from the prepared table Changing data, schema or migration history
Fixture initializer Creates the disposable database and accounts Acting as an application identity

In this small example, the author and executor live in the same Symfony application. The simplification makes the boundary visible. A larger product may distribute the files across several packages while retaining a single execution point. Here, “one migration owner” means coordinated control over a particular database transition, rather than a requirement to place the entire domain model in one repository.

One execution history

Doctrine Migrations discovers classes through configured namespaces and paths, and records executed versions in metadata storage. The behavior is described in the Doctrine configuration documentation. The teaching owner uses this configuration:

$configuration = [
    'migrations_paths' => ['App\MigrationOwnership\Migrations' => __DIR__.'/Migrations'],
    'table_storage' => ['table_name' => 'migration_demo_versions'],
    'all_or_nothing' => false,
    'transactional' => false,
];

A second reader installation does not add its own migration path or copy the history into another table. That would produce two independent accounts of the same physical transition. Having migration classes among the dependencies does not authorize every application to execute them.

The history answers which versions the executor has recorded as applied. By itself, it does not lock out concurrent deployments or prove that an old SQL file has remained unchanged. An applied migration should not be rewritten as though its new contents had already run. The next change needs a new version.

Two readers with testable privileges

The example extends one Symfony 8.1 Demo: the owner command and two readers use its canonical autoload and a separate disposable MySQL 8.4.10. The experiment uses Doctrine Migrations 3.9.8 and DBAL 4.5.1, requiring PHP 8.4.1+. The official Symfony guide describes this branch’s requirements.

The readers need SELECT access to the rehearsal database. After creating the synthetic users separately, the fixture grants them these privileges:

GRANT SELECT ON migrationrehearsal.* TO 'read_a'@'%';
GRANT SELECT ON migrationrehearsal.* TO 'read_b'@'%';

MySQL distinguishes permission to read data, modify rows and change structure; the precise operations appear in its privilege reference. Calling an account read_a does not make the process safe. The check must open a connection with that identity and exercise both permitted and prohibited behavior.

The reader should therefore retrieve a card successfully, while its UPDATE, CREATE TABLE and attempt to change migration history must be rejected. The boundary does not depend on a hidden interface button or an agreement to avoid a command. At the same time, SELECT across the entire teaching database is not a universal production policy: the appropriate scope depends on specific tables and needs.

A transition that preserves the visible contract

The first migration creates migration_demo_note with id and title. The second adds visibility with a default value of public and an index for that column. The existing columns remain. This gives us a concrete addition to discuss without renaming all fields at the same time.

Ordering matters: a reader that queries visibility must start after the column exists. An older query that explicitly selects id and title does not require the new field. That reasoning alone cannot establish a continuous release, however. Actual old and new consumers, lock duration and switching order still need separate verification.

The two migrations should not be treated as one reversible transaction. MySQL has DDL statements that cause implicit commits. Doctrine also explains this boundary. The example therefore disables transactional and all_or_nothing. This describes the chosen execution mode honestly; it does not provide automatic recovery from a partly completed change.

What the rehearsal should establish

The prepared scenario starts with an empty disposable database. The owner runs both migrations, and the checks compare the exact history versions, columns and index. A synthetic card with id=7 is then inserted. Both readers should return the same title and visibility while remaining unable to change them.

A second sequential owner run should finish without applying new migrations. The check compares the history before and after and confirms that the card has not changed. There are 17 prepared checks. Their scope covers these two transitions and the defined permissions, not concurrent releases, restoration of backups or crash resilience.

The experiment ran successfully: all 17 checks passed. Both migrations ran; exact history, columns and index matched expectations. Both readers returned the card; UPDATE, CREATE TABLE and history changes were denied with MySQL 1142. Replay added no migrations and left the card unchanged. The disposable container and volume were removed. This does not test concurrent releases or crash recovery.

A boundary that helps with the next change

A useful rule for a shared database starts by identifying who can accept and execute its next transition. The answer should lead to defined files, an execution order, a history and an executor identity. Consumers receive a reading contract and their own compatibility checks.

That responsibility map also makes failures easier to investigate. A missing column directs attention to the owner's history and delivery order. Excessive reader privileges point to its identity and grants. Partly applied DDL requires inspection of the actual state and the agreed recovery procedure. Giving a transition one responsible execution point does not remove every risk, but it creates a specific place where the next change can be understood and checked.

  1. Databases Four database access roles for one product
  2. Data & Infrastructure MySQL 8.4: an owned server with separate migrator and runtime access
  3. Architecture Shared model, different use cases: public reading and editorial writes