ThePoet444's avatar

Prevent specific migration during test

I have a couple of migrations that basically import data from our old DB that is horribly constructed to a new DB that is slightly less horrible. Probably should be a seeder now that I think about it.. but anyway. I don't need these migrations to run during my tests, the others I need. Is there a command, or a flag I can set somewhere that will prevent certain migrations from run during tests? I've googled a bit and haven't found anything useful.

I understand if this isn't really a needed thing. If this isn't possible I'll try and rewrite them as seeders.

0 likes
2 replies
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

You could add an if statement in your migrations, until you find better solution

    public function up()
    {
        if(app()->environment('testing')) { return; }

    // code
    }


    public function down()
    {
        if(app()->environment('testing')) { return; }
    
    // code
    }
ThePoet444's avatar

I forgot I could check the environment. Thank you. For some reason it didn't like that code.. I had to wrap the entire migration in if(!App::environment('testing')) {} Still it got me where I needed to go. Thank you!

Please or to participate in this conversation.