Zend Migration

What is Doctrine Migration?

Doctrine Migrations allow tracking, versioning, and updating your database schema. Think of it like Git for your database.


Why Use Migrations?

Feature

Explanation

Version Control

Track schema changes with version numbers.

Rollbacks

Revert unwanted changes easily.

Deployment

Sync production DBs with codebase changes safely.


Installing Doctrine ORM and Migrations

Doctrine installation setup link


Create Entity Example

Create User.php in (module\Application\src\Entity\User.php)

namespace Application\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User
{
  /** @ORM\Id @ORM\GeneratedValue @ORM\Column(type="integer") */
  private $id;

  /** @ORM\Column(type="string", length=255) */
  private $email;

  /** @ORM\Column(type="string", length=255) */
  private $password;
}

Generate Migration

php vendor/bin/doctrine-migrations diff


This creates a file like:

public function up(Schema $schema): void
{
  $this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(255), password VARCHAR(255), PRIMARY KEY(id))');
}

Run Migration

php vendor/bin/doctrine-migrations migrate

Rollback

To rollback the previous change:

php vendor\bin\doctrine-migrations migrate prev

Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.