Code Monkey home page Code Monkey logo

Comments (8)

BartoszBartniczak avatar BartoszBartniczak commented on August 23, 2024

Did I do something wrong?
No, you didn't. I didn't changed the column definition in code, so basicly it creates a default datetime column. Of course, I haven't checked that, it is only my feeling. I could have check that in detail but, I don't think I could have do that in the next few days.

Additionally I think that it's worth to add a doctrine configuration section to readme, because to make microseconds work correctly you have to register a custom type in doctrine.yaml config file

I will add that in the next release.

If you will find solution of the first problem, feel free to do the Pull Request.

from doctrine-datetime-with-microseconds.

sabat24 avatar sabat24 commented on August 23, 2024

I guess I found a solution. It was indeed the getSQLDeclaration method. I will write some tests and then I can make PR. Probably tomorrow.

from doctrine-datetime-with-microseconds.

sabat24 avatar sabat24 commented on August 23, 2024
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
    {
        $parentDateTimeDeclaration = $platform->getDateTimeTypeDeclarationSQL($fieldDeclaration);
        if ($platform instanceof SqlitePlatform) {
            $precision = 3;
        } else {
            $precision = 6;
        }

        return preg_replace('/(DATETIME[2]?|TIMESTAMP)(\([0-9]{1,2}\))?/', '$1('.$precision.')', $parentDateTimeDeclaration);
    }

It's my solution above. Main idea is to use string returned by Doctrine and then just change the precision of field type. It may not work for older DB engines which don't provide support for microseconds.

I didn't create a PR as there is one more problem with it. I don't know why, but Symfony still create a following migration

ALTER TABLE table CHANGE created_date created_date DATETIME(6) NOT NULL

even if that field in my DB has got exactly that type.

from doctrine-datetime-with-microseconds.

BartoszBartniczak avatar BartoszBartniczak commented on August 23, 2024

I don't know why, but Symfony still create a following migration

ALTER TABLE table CHANGE created_date created_date DATETIME(6) NOT NULL

I don't get it. Why do you think it is a problem? What do you expect?

from doctrine-datetime-with-microseconds.

sabat24 avatar sabat24 commented on August 23, 2024

The migration is created each time you run bin/console make:migration even if there is no such need.

  1. run bin/console make:migration on empty DB or newly created field
  2. run bin/console doctrine:migrations:migrate
  3. run bin/console make:migration

In step 3 there shouldn't be anything to migrate as you updated your DB's schema in step 2.
I need to check make:migration command to verify how it compares actual DB schema with provided entity field type.

from doctrine-datetime-with-microseconds.

BartoszBartniczak avatar BartoszBartniczak commented on August 23, 2024

Ok, now I get it. Have you tried to clear cache? You did change the schema outside the doctrine, so maybe it tries to change the schema, because it doesn't see changes.

from doctrine-datetime-with-microseconds.

BartoszBartniczak avatar BartoszBartniczak commented on August 23, 2024

Just read your message again, and now I understand. There is for sure, a problem with diff mechanism. I don't know how it works either, but I think it is very interesting. Let me know if you need any help. I will try to solve it either.

from doctrine-datetime-with-microseconds.

sabat24 avatar sabat24 commented on August 23, 2024

That method have to be overridden, too.

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

Then a new migration should add a comment to the DB field with custom type name like that

COMMENT \'(DC2Type:datetime_microseconds)\'

You may take a look here

Please note that I also changed SQL declaration to $platform->getDateTimeTypeDeclarationSQL
There was DateTimeTz before but I think that datetime_microseconds shouldn't use it as it's for datetimetz field type.

from doctrine-datetime-with-microseconds.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.