CodeIgniter Forums

Full Version: Migration group issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

i'm trying to apply my migrations to my test database by using the -g option for groups

php spark migrate:latest -g tests

but the command still try to target my main database (db.local) AND my test database (db.test) at the same time.

My .env database setup is

database.default.database = db.local
database.tests.database = db.test

is that a bug or am i doing something wrong?

Thank you for any help
Well your database is db.test and your using -g tests should it not be -g test?
(06-22-2019, 04:31 AM)InsiteFX Wrote: [ -> ]Well your database is db.test and your using -g tests should it not be -g test?

Thanks for your comment but in fact, db.test is the name of the database itself. The name of the group is the middle part of

database.tests.database = db.test

like it is for default group

database.default.database = db.local

but i tried it anyway Tongue doesn't work
Hmm that's odd. Can you try it with `-all` and see if it has the same behavior? Also try it from a non-CLI context:
```
$runner = Services::migrations();
$result = $runner->latest(null, 'tests');
var_dump($result);
```
:/ Doesn't work either, command line or scripts. It it still trying to target my main db and never the "tests" one. I also tried  to setup db config in the according file in App\Config with no success. The groups seems totay ignored.

ps: Thanks your for the code example  as i was going to need it..by the way, do you have any idea how to use the rollback() method from a script ? it seems not present in the migrations service.
Okay I recommend you submit a bug report on GitHub and someone will take a look at it.

For rollback you can just call `version` with "0": $runner->version(0); - though I should note that migrations are being reworked right now so I'd recommend against writing a lot of code around the current implementation in case things change (https://github.com/codeigniter4/CodeIgniter4/pull/2065).
(06-22-2019, 06:35 PM)MGatner Wrote: [ -> ]Okay I recommend you submit a bug report on GitHub and someone will take a look at it.

Ok. I will.

For rollback you can just call `version` with "0": $runner->version(0); - though I should note that migrations are being reworked right now so I'd recommend against writing a lot of code around the current implementation in case things change (https://github.com/codeigniter4/CodeIgniter4/pull/2065).

thank you very much Smile
I guess i have found the problem: In the migrationRunner, the database is selected in the constructor only. The setGroup method is called in latest(), it can change the group but the database is never reconnected.