Aerendir Aerendir - 19 days ago 4
MySQL Question

Doctrine: always tells me the database isn't in sync after using two custom mapping types

I've created two custom mapping types: one for a Money value object and one for an Email value object

Now, each time I run

app/console doctrine:schema:validate
Doctrine tells me the database is not in sync.

Dumping the
app/console doctrine:schema:update --dump-sql
it wants each time to update the same fields in the same way:

ALTER TABLE invoices CHANGE total total VARCHAR(255) NOT NULL;
ALTER TABLE subscriptions CHANGE next_payment_amount next_payment_amount VARCHAR(255) NOT NULL;
ALTER TABLE stripe_charges CHANGE amount amount VARCHAR(200) NOT NULL, CHANGE receipt_email receipt_email VARCHAR(255) DEFAULT NULL;
ALTER TABLE stripe_customers CHANGE email email VARCHAR(255) DEFAULT NULL;

Each time it tries to update these tables setting them in the exact same state they already are. Is a fault of mine or is a Doctrine's one?

Here the code for the two types:

GitHub/Doctrine Issue here.


Doctrine is seeing each of the columns on your database as strings but thinking you want them to be money/email so it's deciding that you need to migrate each time.

The way to sort this is by adding the requiresSQLCommentHint so that it adds some text in your column comment to show that it actually is the correct customer type. You do this by just adding..

 * {@inheritdoc}
public function requiresSQLCommentHint(AbstractPlatform $platform)
    return true;

.. to your custom types and Doctrine will handle the rest.