💡 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;