Skip to content

Feat: Migration lock at the start of migration in CodeIgniter 4 #9646

@climmmm

Description

@climmmm

PHP Version

8.4

CodeIgniter4 Version

4.6.1

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

SQLServer 2019

What happened?

When running migrations with CodeIgniter 4, the framework does not place a lock at the beginning of the migration process. Instead, it only inserts a record into the migrations table at the end of each migration. This means that if multiple processes (for example, multiple pods in Kubernetes) start migrations at the same time, there is a risk that the same migration will be executed concurrently, which can cause conflicts or race conditions.

Steps to Reproduce

  1. Deploy your CodeIgniter 4 application in an environment where multiple instances (pods/containers) can start at the same time.
  2. Configure each instance to run migrations automatically on startup (e.g., via an initContainer or entrypoint script).
  3. Start multiple instances simultaneously.

Expected Output

Only one instance should be able to run the migration at a time. The framework should place a lock at the beginning of the migration process to prevent concurrent execution, similar to how Doctrine Migrations (Symfony) works. This would avoid race conditions and ensure that migrations are applied safely, even in distributed environments.

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions