phpmig icon indicating copy to clipboard operation
phpmig copied to clipboard

Submodule migrations

Open Petah opened this issue 14 years ago • 6 comments

This is more of a feature idea.

My projects are made up of a bunch of modules. It would be good if each module could keep its own migrations, but run them as part of an application.

For example I have this directory structure:

    project
    ¦   phpmig.php
    +---migrations
    +---modules
    ¦   +---cms
    ¦   ¦   +---migrations
    ¦   +---email
    ¦       +---migrations
    +---public
        ¦   index.php
        +---images
                etc...

Running phpmig on the project directory should run all migrations, including ones in sub modules.

There would be of course problems with the current logging format and DI containers. The logging of migrations that have been run would need to be stored in the project log file/DB. And each sub module would have to have a compatible DI object for accessing the database.

The log file (I haven't used DB logging) could be adapted like so:

    20111100133144
    20111100721245
    modules/cms/2011110054613
    modules/cms/2011110014658
    modules/email/2011110016455

I'm happy to implement this, what are you thoughts?

Petah avatar Nov 08 '11 00:11 Petah

I've kinda started something along these lines, my thoughts were that if you wanted a separate log for each migration sets, you'd have to provide phpmig with an adapter and an array of migrations for each set:


<?php 
$container['phpmig.sets']['cms'] = array(
    'adapter' => new Phpmig_Adapter_Flat_File(__DIR__ . '/modules/cms/migrations/.migrations.log'),
    'migrations' => glob(__DIR__ . '/modules/cms/migrations/*.php'),
);

That way, each database can have their own migrations table etc.

If you're not bothered about having separate logging, I'd just use the globbing e.g. glob(DIR . '/modules//migrations/.php'). In the unlikely event you have a name clash, I'd just change the timestamp on one of the migrations

davedevelopment avatar Nov 08 '11 08:11 davedevelopment

[deleted]

reenl avatar Aug 02 '13 14:08 reenl

@reenl was that meant for a different issue?

davedevelopment avatar Aug 02 '13 14:08 davedevelopment

Sorry see #45

reenl avatar Aug 02 '13 14:08 reenl

how do you setup that phpmig.sets item, I keep getting Identifier "phpmig.sets" is not defined. when I do it the way described on this post.

eman1986 avatar Jan 21 '16 03:01 eman1986

seems to be a bug, I forked your code and looking to fix it

eman1986 avatar Jan 22 '16 03:01 eman1986