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 -g option #7894

Merged
merged 8 commits into from
Sep 9, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Sep 4, 2023

Description
See #7891

  • fix description for -g in spark migrate, migrate:refresh, and migrate:status
  • remove -g option in spark migrate:rollback because it does not work (and should not work)

The current behavior

migrage:rollback:

$ php spark migrate:status

CodeIgniter v4.4.0 Command Line Tool - Server Time: 2023-09-04 06:10:28 UTC+00:00

+-----------+-------------------+----------------+---------+---------------------+-------+
| Namespace | Version           | Filename       | Group   | Migrated On         | Batch |
+-----------+-------------------+----------------+---------+---------------------+-------+
| App       | 2023-09-04-013453 | DefaultAddBlog | default | 2023-09-04 06:10:26 | 1     |
| App       | 2023-09-04-013454 | Test1AddBlog   | test1   | 2023-09-04 06:10:26 | 1     |
| App       | 2023-09-04-013455 | Test2AddBlog   | test2   | 2023-09-04 06:10:26 | 1     |
+-----------+-------------------+----------------+---------+---------------------+-------+

$ php spark migrate:rollback -g default

CodeIgniter v4.4.0 Command Line Tool - Server Time: 2023-09-04 06:10:37 UTC+00:00

Rolling back migrations to batch:  0
        Rolling back: (App) 2023-09-04-013455_App\Database\Migrations\Test2AddBlog
        Rolling back: (App) 2023-09-04-013454_App\Database\Migrations\Test1AddBlog
        Rolling back: (App) 2023-09-04-013453_App\Database\Migrations\DefaultAddBlog
Done rolling back migrations.

$ php spark migrate:status

CodeIgniter v4.4.0 Command Line Tool - Server Time: 2023-09-04 06:10:39 UTC+00:00

+-----------+-------------------+----------------+-------+-------------+-------+
| Namespace | Version           | Filename       | Group | Migrated On | Batch |
+-----------+-------------------+----------------+-------+-------------+-------+
| App       | 2023-09-04-013453 | DefaultAddBlog | ---   | ---         | ---   |
| App       | 2023-09-04-013454 | Test1AddBlog   | ---   | ---         | ---   |
| App       | 2023-09-04-013455 | Test2AddBlog   | ---   | ---         | ---   |
+-----------+-------------------+----------------+-------+-------------+-------+

migrate:status:

$ php spark migrate:status

CodeIgniter v4.4.0 Command Line Tool - Server Time: 2023-09-04 07:15:42 UTC+00:00

+-----------+-------------------+----------------+---------+---------------------+-------+
| Namespace | Version           | Filename       | Group   | Migrated On         | Batch |
+-----------+-------------------+----------------+---------+---------------------+-------+
| App       | 2023-09-04-013453 | DefaultAddBlog | default | 2023-09-04 06:22:19 | 1     |
| App       | 2023-09-04-013454 | Test1AddBlog   | test1   | 2023-09-04 06:22:19 | 1     |
| App       | 2023-09-04-013455 | Test2AddBlog   | test2   | 2023-09-04 06:22:19 | 1     |
+-----------+-------------------+----------------+---------+---------------------+-------+

$ php spark migrate:status -g default

CodeIgniter v4.4.0 Command Line Tool - Server Time: 2023-09-04 07:15:48 UTC+00:00

+-----------+-------------------+----------------+---------+---------------------+-------+
| Namespace | Version           | Filename       | Group   | Migrated On         | Batch |
+-----------+-------------------+----------------+---------+---------------------+-------+
| App       | 2023-09-04-013453 | DefaultAddBlog | default | 2023-09-04 06:22:19 | 1     |
| App       | 2023-09-04-013454 | Test1AddBlog   | ---     | ---                 | ---   |
| App       | 2023-09-04-013455 | Test2AddBlog   | ---     | ---                 | ---   |
+-----------+-------------------+----------------+---------+---------------------+-------+

$ php spark migrate:status -g test2

CodeIgniter v4.4.0 Command Line Tool - Server Time: 2023-09-04 07:15:52 UTC+00:00

+-----------+-------------------+----------------+-------+---------------------+-------+
| Namespace | Version           | Filename       | Group | Migrated On         | Batch |
+-----------+-------------------+----------------+-------+---------------------+-------+
| App       | 2023-09-04-013453 | DefaultAddBlog | ---   | ---                 | ---   |
| App       | 2023-09-04-013454 | Test1AddBlog   | ---   | ---                 | ---   |
| App       | 2023-09-04-013455 | Test2AddBlog   | test2 | 2023-09-04 06:22:19 | 1     |
+-----------+-------------------+----------------+-------+---------------------+-------+

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 bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer labels Sep 4, 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.

Does this need a changelog note?

@kenjis
Copy link
Member Author

kenjis commented Sep 5, 2023

@MGatner Rebased and added changelog.

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.

Thanks! Looks good.

@kenjis kenjis merged commit 1ff3e6e into codeigniter4:develop Sep 9, 2023
53 checks passed
@kenjis kenjis deleted the fix-migration-db-group branch September 9, 2023 12:06
@xonipatino
Copy link

Hello everyone, I have had the same recent problem with version 4.4.1 having the CI_ENVIRONMENT in "development", review the code of the file \system\Database\MigrationRunner.php and comment the following lines (849 - 855):

if (ENVIRONMENT !== 'testing' && $group === 'tests' && $this->groupFilter !== 'tests') {
    // @codeCoverageIgnoreStart
    $this->groupSkip = true;

    return true;
    // @codeCoverageIgnoreEnd
}

this solved my problem.

It should be allowed that regardless of whether your CI_ENVIRONMENT is "production", "testing" or "development" you can rollback without any problem.

@xonipatino
Copy link

xonipatino commented Oct 10, 2023

Hello everyone, I have had the same recent problem with version 4.4.1 having the CI_ENVIRONMENT in "development", review the code of the file \system\Database\MigrationRunner.php and comment the following lines (849 - 855):

if (ENVIRONMENT !== 'testing' && $group === 'tests' && $this->groupFilter !== 'tests') {
    // @codeCoverageIgnoreStart
    $this->groupSkip = true;

    return true;
    // @codeCoverageIgnoreEnd
}

this solved my problem.

It should be allowed that regardless of whether your CI_ENVIRONMENT is "production", "testing" or "development" you can rollback without any problem.

Hello, I found a better way to solve and modify these two files:

In \system\Commands\Database\MigrateRollback.php

lines 84-86 and 93:

/*if (is_string($group)) {
    $runner->setGroup($group);
}*/
$group = is_string($group) ? $group : null;
...
...
...
if (! $runner->regress($batch, $group)) {  //added second parameter

In \system\Database\MigrationRunner.php

lines 236-240:

// Set database group if not null
if ($group !== null) {
    $this->groupFilter = $group; // add this lines
    $this->setGroup($group);
}

@kenjis
Copy link
Member Author

kenjis commented Oct 11, 2023

Your customization is yours, no problem.

But the specifications of the CI4 migration are:

If you find any behavior against the spec, feel free to create an issue or send a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants