Your SQL statement looks mostly correct, but there are a few potential issues to consider:
Column Name Change: You're changing file_link to file_path - make sure this is intentional and won't break any application code that references the old column name.
DEFAULT for updated_on: You're setting DEFAULT CURRENT_TIMESTAMP for updated_on. This is fine, but note that:
In MySQL, this will update to the current timestamp on every INSERT, but not on UPDATE
If you want it to update on every UPDATE as well, you should use ON UPDATE CURRENT_TIMESTAMP (though this is typically used for "last updated" timestamps)
ENUM Values: The ENUM values look reasonable, but ensure they match your application's business logic.
COMMENT Syntax: The comment syntax is correct for MySQL/MariaDB.
NULL/NOT NULL: You're making email_status NOT NULL with a DEFAULT, which is good practice.
Your Doctrine entity mapping for emailStatus looks correct and should work with the SQL ALTER TABLE statement you provided, but there are a few important considerations:
1. Type Mismatch
Your SQL defines email_status as an ENUM('not_required', 'pending', 'sent', 'failed')
That you have the necessary privileges to alter the table
That the table isn't being actively used during the alteration
That your application can handle the column name change if you're modifying file_link to file_path
Would you like me to suggest any modifications based on specific requirements?
Your Doctrine entity uses Types::STRING with an enum class
This is actually fine because Doctrine will handle the enum-to-string conversion, but you should ensure:
The enum class values match exactly with the SQL enum values (case-sensitive)
The default value in Doctrine (InvoiceDocumentEmailStatus::NOT_REQUIRED) matches the SQL default ('not_required')
2. Initial Value Conflict
Your SQL sets DEFAULT 'not_required'
Your PHP property initializes with InvoiceDocumentEmailStatus::PENDING
This is a potential inconsistency. The database will use 'not_required' as default, but your PHP code initializes to PENDING. You should decide which one should be the true default.
3. Recommended Adjustments
For the SQL:
ALTER TABLE invoice_document
ADD email_sent_at DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime_immutable)',
ADD email_status ENUM('not_required', 'pending', 'sent', 'failed') DEFAULT 'not_required' NOT NULL,
CHANGE updated_on updated_on DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '(DC2Type:datetime_immutable)',
CHANGE file_link file_path VARCHAR(255) NOT NULL;
For the Doctrine Entity:
#[ORM\Column(
type: Types::STRING,
length: 255,
enumType: InvoiceDocumentEmailStatus::class,
options: [
'default' => InvoiceDocumentEmailStatus::NOT_REQUIRED->value // Use value if it's a backed enum
]
)]
private InvoiceDocumentEmailStatus $emailStatus = InvoiceDocumentEmailStatus::NOT_REQUIRED;
4. Additional Recommendations
If using PHP 8.1+, consider using backed enums for better type safety
Ensure your InvoiceDocumentEmailStatus enum has all the same values as the SQL enum
Consider adding a migration to handle existing data if this is an existing table
The setup should work, but you'll want to ensure consistency between your database schema and Doctrine entity configuration.
Both use the same default value, preventing inconsistencies
Initialization:
The property is initialized with InvoiceDocumentEmailStatus::NOT_REQUIRED
This matches both the SQL default and Doctrine default
String Type:
Using Types::STRING is appropriate for enum storage in the database
Doctrine will handle the conversion between enum and string values
Recommendations:
Enum Class Definition:
Ensure your InvoiceDocumentEmailStatus enum is properly defined:
enum InvoiceDocumentEmailStatus: string
{
case NOT_REQUIRED = 'not_required';
case PENDING = 'pending';
case SENT = 'sent';
case FAILED = 'failed';
}
Database Migration:
If this is a new column, the migration will work as expected
If this is modifying an existing column, ensure the enum values match exactly
Type Safety:
The combination of enum type and string storage provides good type safety
Consider adding validation in your entity to ensure only valid enum values are set
This configuration provides a clean mapping between your database schema and your PHP entity, with proper type safety and consistent default values. The setup should work well for both database operations and application logic.