Skip to content

[Bug]: migrations does not works if driver option withDatetimeMicroseconds is ture #66

Description

@ddrv

Describe the bug

If driver option withDatetimeMicroseconds equals a true, \Cycle\Migrations\Migrator can not resolve executed migrations and attempt to apply them again.

This is because the migrator does not know that a more precise time format should be used, and the driver saves the file with the precise time.

Is this a regression?

No response

To Reproduce

Save this code into issue.php

<?php

use Cycle\Database\Config\DatabaseConfig;
use Cycle\Database\Config\SQLite\FileConnectionConfig;
use Cycle\Database\Config\SQLiteDriverConfig;
use Cycle\Database\DatabaseManager;
use Cycle\Migrations\Config\MigrationConfig;
use Cycle\Migrations\FileRepository;
use Cycle\Migrations\Migrator;

require __DIR__ . '/vendor/autoload.php';

$dbal = new DatabaseManager(new DatabaseConfig([
    'default' => 'main',
    'databases' => [
        'main' => [
            'connection' => 'main',
        ],
    ],
    'connections' => [
        'main' => new SQLiteDriverConfig(
            connection: new FileConnectionConfig(__DIR__ . '/issue.sqlite'),
            options: [
                'withDatetimeMicroseconds' => true,
            ],
        ),
    ],
]));

$config = new MigrationConfig([
    'directory' => __DIR__ . '/migrations',
    'vendorDirectories' => [],
    'table' => 'migrations',
    'namespace' => 'Migration',
    'safe' => false,
]);

$repository = new FileRepository($config);

$migrator = new Migrator($config, $dbal, $repository);


if (!$migrator->isConfigured()) {
    $migrator->configure();
}

do {
    $migration = $migrator->run();
} while (!is_null($migration));

create directory migrations and create new migration (for example, copy from documentation)

run

php issue.php

script failed =(

Expected behaviour

I expect the migration to be successful

Media prove

No response

Database

No response

Your environment

  • OS: Linux Mint
  • PHP: 8.3.6
  • Package version: 4.2.6

Additional context

Ideally, you should be able to determine the value of the withDatetimeMicroseconds option from the driver. However, adding a method to the driver interface will break backward compatibility (if someone is using a custom driver).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions