php-migration
php-migration copied to clipboard
❓ How to determine if database is not yet versioned without cathing an exception
First I want to thank you for this wonderful library. This is exactly what I was looking for: no query builders, heavy set of dependencies, and especially I want to thank you that symfony/console
integration is put in a separate package, unlike the doctrine/migrations
and phinx
. My use-case is a separate library for domain objects, which I do re-use in my high-level app package, so no dependencies on CLI tools is great. 💗
Here is my question: I want to implement fully automatic database migration, whether it is first deployment or just an update. I use it like so:
$migrator = new Migration(
$this->psr7Uri,
self::MIGRATIONS_DIR
);
foreach (self::SUPPORTED_SCHEMES as $scheme => $className) {
$migrator->registerDatabase($scheme, $className);
}
$migrator->update(); // might throw DatabaseNotVersionedException
For now I have to catch the DatabaseNotVersionedException
and call $migrator->createVersion()
when appropriate. However, I would like to not depend on exception catching and just be able to check if DB is already versioned via some convenience method, like $migrator->isDatabaseVersioned()
. Is it not possible for now, or do I miss something?
Thank you for your comment :) It makes me feel like I'm on the right track.
Right now I dont have a single method to check if exists migration. I have a method getVersion()
but it rely on SELECT ... FROM MIGRATION_TABLE
is sucessful or dont.
That feature is interesting. The implementation will take sometime because I have to query the metadata and it implementation is specific per database.
I have a new release in development 4.1.0
, probably I'll include there.
I have another feature I want to implement is a checksum from the SQL. This way the system wont apply the change if any previous SQL is different from when it was applied.
I implemented isDatabaseVersioned
method. Until I create a new version you can use the development version 4.1.0.x-dev