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

Same migrations on different databases #95

Closed
aik099 opened this issue Jan 19, 2016 · 3 comments
Closed

Same migrations on different databases #95

aik099 opened this issue Jan 19, 2016 · 3 comments

Comments

@aik099
Copy link

aik099 commented Jan 19, 2016

In a project of mine I'm planning to:

  • store VCS revision info (commit_id, files changed, etc.) in an SQLite database
  • there would be separate SQLite database per repository (easier, than having to add "repository_id" column to each table)
  • have single set of migration scripts (via this library)

What I'm struggling at is how to make it all work considering, that:

  • I don't know SQLite database location at the moment, when PHPMig library is initialized and therefore:
    • I can't use PHPMig CLI to create new migrations easily
    • I can't specify any DB in PHPMig config to create "migration" table in

Here is how I plan this to work: I call a method in my code like this ...->getDatabase('/path/to/db1.sqlite'); and will:

  • if database is missing, then:
    • create an empty file
    • populate it with proper empty tables
    • return PDO class object
  • if file is present, then:
    • open it
    • execute missing migrations (if any)
    • return PDO class object
@aik099
Copy link
Author

aik099 commented Jan 22, 2016

Any suggestions?

@davedevelopment
Copy link
Owner

Heya, nothing off the top of my head, except for a wrapper script that writes the correct info out to a phpmig bootstrap file and then invokes phpmig with that file.

This lib is currently heavily coupled to the bootstrap file, which makes this awkward, as mentioned in #75

@aik099
Copy link
Author

aik099 commented May 10, 2016

What I turned up doing is:

  • writing minimalistic solution that does exactly what's needed
  • a MigrationManager class, that:
    • is initialized (constructor) with path to a folder containing migrations
    • has createMigration method that creates migration with a given name & type
    • has run method that accepts a context, which consists of database, container and whatever is needed
  • separate runner classes for different migration types (e.g. php and sql)

Very simple stuff, but does what it's supposed to do.

You can see actual implementation at https://github.com/console-helpers/svn-buddy/tree/master/src/SVNBuddy/Database/Migration

@aik099 aik099 closed this as completed May 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants