Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

❓ How to determine if database is not yet versioned without cathing an exception #27

Open
someniatko opened this issue May 5, 2020 · 2 comments
Assignees

Comments

@someniatko
Copy link

someniatko commented May 5, 2020

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?

@byjg
Copy link
Owner

byjg commented May 5, 2020

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.

@byjg byjg self-assigned this May 5, 2020
byjg added a commit that referenced this issue May 6, 2020
@byjg
Copy link
Owner

byjg commented May 7, 2020

I implemented isDatabaseVersioned method. Until I create a new version you can use the development version 4.1.0.x-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants