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

Add DatabaseMigrationsRealpath Trait #123

Closed
wants to merge 2 commits into from
Closed

Conversation

loren138
Copy link
Contributor

@loren138 loren138 commented Aug 16, 2016

This closes #121.

As it turns out migrate:rollback does not need a realpath attribute so I did not do that. Since the DatabaseMigrations trait was already pulled in from Laravel, I created a new trait call DatabaseMigartionsRealpath. To use this trait the user must create a function like the one below

protected function getMigrationsRealpath()
{
    return realpath(__DIR__.'/migrations');
}

Also, please merge this into 3.3. I did not include this for 3.1 since that branch did not have any of the standard laravel traits enabled yet. I can create a separate pull for 3.1 if that is desired.

@coveralls
Copy link

Coverage Status

Coverage increased (+2.4%) to 84.0% when pulling 89c9c23 on loren138:3.2 into 8b953d3 on orchestral:3.2.

@crynobone
Copy link
Member

As it turns out migrate:rollback does not need a realpath attribute so I did not do that.

So therefore there no real need to have this PR?

Also, please merge this into 3.3

Laravel 5.3 introduce ServiceProvider::loadMigrationsFrom() helpers. The --realpath would no longer be needed from now forward.

@crynobone crynobone closed this Aug 16, 2016
@crynobone
Copy link
Member

crynobone commented Aug 16, 2016

I'm okay if we want to look at adding something such as

$this->loadMigrationsFrom($path);

and have the following method:

    /**
     * Define hooks to migrate the database before and after each test.
     *
     * @param  string  $realpah
     * @return void
     */
    protected function loadMigrationsFrom($realpath)
    {
        $this->artisan('migrate', [
            '--realpath' => $realpath,
        ]);

        $this->beforeApplicationDestroyed(function () {
            $this->artisan('migrate:rollback');
        });
    }

There no reason to have a Trait and then have to manually override a method, plus this can be PRed to 3.1

@loren138
Copy link
Contributor Author

Ah, I like that code. I really didn't like the override, but since it was a function their was no way to use it from an env var.

I'll make a new PR.

@loren138
Copy link
Contributor Author

The one downside to that is that the override function can be done in TestCase.php in the project. Then any files the need migrations would be given the trait and would have migrations run. In this method, you'd need to override setup in each test class that needs migrations and either include the migrations path there or call a similar function in the parent testcase.

This method is cleaner for new adopters though.

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

Successfully merging this pull request may close these issues.

None yet

3 participants