π‘ The plan is to add a new column lastname
, write in both from the codebase
:bulb: Populate the new columns lastname
with column name
π‘ Add the new column nullable π‘ Make the property nullable π‘ Make the column to rename nullable π‘ Replace older setter/getter by the setter/getter in the codebase
// Model
class User
{
+ /**
+ * @ORM\Column(type="int", nullable=true)
+ */
+ private ?string $lastname = null;
+ public setLastname(string $lastname){};
+ public getLastname(): string
+ {
+ return $this->$lastname ?? $this->$name;
+ }
- public setName(string $name){};
- public getName(): string {};
}
// FooHandler.php
- $user->setName("Smaone");
+ $user->setLastname("Smaone");
- $user->getName();
+ $user->getLastname();
// SQL Migration
+ ALTER TABLE user ADD lastname int DEFAULT NULL
+ ALTER TABLE user ALTER name drop NOT NULL
π‘ Update all null rows, make the column not NULL π‘ Make the property and the getter not null π‘ remove the old column
// Model
class User
{
/**
- * @ORM\Column(type="int", nullable=true)
+ * @ORM\Column(type="int", nullable=false)
+ */
- private ?string $lastname = null;
+ private string $lastname;
public setLastname(string $lastname){};
public getLastname(): string
{
- return $this->$lastname ?? $this->$name;
+ return $this->$lastname;
}
}
// SQL Migration
+ UPDATE user set lastname = name WHERE lastname IS NULL;
+ ALTER TABLE user DROP name;
+ ALTER TABLE user ALTER lastname DROP NOT NULL;