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

Fix spark migrate issue with -g option #7846

Closed
wants to merge 1 commit into from

Conversation

filoboss
Copy link

@filoboss filoboss commented Aug 23, 2023

Description
Supersedes #7845

When performing a spark migrate with the -g option to use a different DBgroup other than the default, and when there's no default database configured, the migration fails. This is because $this->ensureTable() is executed before $this->setGroup($group). I've simply moved $this->ensureTable() to execute after setting the group.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added GPG-Signing needed Pull requests that need GPG-Signing tests needed Pull requests that need tests labels Aug 23, 2023
@kenjis
Copy link
Member

kenjis commented Aug 23, 2023

Thank you for sending PR!

You must sign all commits with a valid GPG key.
The first commit is not signed.
The second commit is not valid.
See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md#signing

@kenjis kenjis changed the title Fix issue with -g option Fix spark migrate issue with -g option Aug 23, 2023
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good! Please address the merge blockers.

@filoboss filoboss force-pushed the develop branch 2 times, most recently from b637bbc to 13a870c Compare September 2, 2023 17:29
@filoboss
Copy link
Author

filoboss commented Sep 2, 2023

Sorry team, I was on vacation, I've removed the unsigned commit.

@datamweb
Copy link
Contributor

datamweb commented Sep 2, 2023

@filoboss Your commit is still unsigned.
Please see here.

@filoboss filoboss force-pushed the develop branch 2 times, most recently from 4ce8f5d to 3531d7b Compare September 2, 2023 18:37
@kenjis
Copy link
Member

kenjis commented Sep 2, 2023

No user is associated with the committer email.
Screeshot 2023-09-03 5 08 56

@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Sep 3, 2023
@filoboss
Copy link
Author

filoboss commented Sep 3, 2023

Ok, sorry, email author problem, this one is good.

@kenjis kenjis removed the GPG-Signing needed Pull requests that need GPG-Signing label Sep 4, 2023
@kenjis
Copy link
Member

kenjis commented Sep 4, 2023

@filoboss Thank you for signing.

When performing a spark migrate with the -g option to use a different DBgroup other than the default, and when there's no default database configured, the migration fails.

Why there's no default database configured?
If not, it seems we cannot create the migration table.

Should it fail if you don't have the default database?

@kenjis
Copy link
Member

kenjis commented Sep 4, 2023

@kenjis
Copy link
Member

kenjis commented Sep 4, 2023

when there's no default database configured

If there is no default group in Config\Database, migration does not work at all.
Even if in this PR branch.

$ php spark migrate -g test1

CodeIgniter v4.3.7 Command Line Tool - Server Time: 2023-09-04 02:08:22 UTC+00:00


[InvalidArgumentException]

default is not a valid database connection group.

at SYSTEMPATH/Database/Config.php:69

Backtrace:
  1    SYSTEMPATH/Common.php:362
       CodeIgniter\Database\Config::connect('default', true)

  2    SYSTEMPATH/Database/MigrationRunner.php:151
       db_connect(null)

  3    SYSTEMPATH/Config/Services.php:415
       CodeIgniter\Database\MigrationRunner()->__construct(null, null)

  4    SYSTEMPATH/Config/BaseService.php:252
       CodeIgniter\Config\Services::migrations(Object(Config\Migrations), null, false)

  5    SYSTEMPATH/Config/BaseService.php:193
       CodeIgniter\Config\BaseService::__callStatic('migrations', [...])

  6    SYSTEMPATH/Config/Services.php:410
       CodeIgniter\Config\BaseService::getSharedInstance('migrations', null, null)

  7    SYSTEMPATH/Config/BaseService.php:252
       CodeIgniter\Config\Services::migrations()

  8    SYSTEMPATH/Commands/Database/Migrate.php:69
       CodeIgniter\Config\BaseService::__callStatic('migrations', [])

  9    SYSTEMPATH/CLI/Commands.php:65
       CodeIgniter\Commands\Database\Migrate()->run([...])

 10    SYSTEMPATH/CLI/Console.php:37
       CodeIgniter\CLI\Commands()->run('migrate', [...])

 11    ROOTPATH/spark:97
       CodeIgniter\CLI\Console()->run()

@kenjis
Copy link
Member

kenjis commented Sep 4, 2023

I'm sure there is a bug round the -g option, but I'm not sure how to fix it.
Please see #7891.

@kenjis kenjis added the waiting for info Issues or pull requests that need further clarification from the author label Sep 5, 2023
@kenjis
Copy link
Member

kenjis commented Sep 11, 2023

We have update the description for -g. See #7894
And if you don't have the default DB group, CI4 does not work.
You must set the default DB group.

@kenjis kenjis removed the bug Verified issues on the current code behavior or pull requests that will fix them label Sep 11, 2023
@qury
Copy link
Contributor

qury commented Sep 12, 2023

Hi Guys,

I run into a this problem as well. I have multiple database connections defined. The default is a read-only DB.
When i define a migration and specify DBGroup to be a connection which is a differetn rw database then migration still failes that i can't write to the default DB.

image

For me the solution was to update the system/Commands/Database/Migrate.php file and do the below:

image

Now, i'm not sure if this is the right was to do this or if there are any other places to update, but as far as i can tell there is no other place besides the constructor in MigrationRunner where the database connection is set or where we allow to overwrite the db connection.

@kenjis
Copy link
Member

kenjis commented Sep 12, 2023

@qury Your configuration is not supported by the CI4 DB migration.
The default database group must be writable.
Please see #7891 (comment) for migration assumptions.

So you need to customize the migration for yourself.
Your change seems okay if you have only one database to write.

@github-actions github-actions bot added the stale Pull requests with conflicts label Sep 20, 2023
@kenjis kenjis removed the stale Pull requests with conflicts label Sep 20, 2023
@codeigniter4 codeigniter4 deleted a comment from github-actions bot Sep 20, 2023
@kenjis kenjis closed this Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests needed Pull requests that need tests waiting for info Issues or pull requests that need further clarification from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants