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

Changing magento install criteria, when running DB import #70

Closed
aleksandrsm opened this issue Mar 2, 2022 · 2 comments
Closed

Changing magento install criteria, when running DB import #70

aleksandrsm opened this issue Mar 2, 2022 · 2 comments

Comments

@aleksandrsm
Copy link

aleksandrsm commented Mar 2, 2022

Currently, migrate-db.js, which is executed under any setupMagento run (both for import-db and regular start)

It runs setup:db:status, and when the resulting code is 1, the following is triggered:

case 1: {
            if (options.onlyInstallMagento) {
                return task.newListr(
                    installMagento()
                );
            }

            return task.newListr([
                installMagento(),
                setupPersistedQuery(),
                upgradeMagento(),
                magentoTask('cache:enable'),
                configureElasticsearch()
            ], {
                concurrent: false,
                exitOnError: true,
                ctx
            });
        }

This install is largely unnecessary, and in case of imported db, would delete the just-imported database, replacing it with a blank DB.

It should be enough to just run magento's setup:install, when the tables in DB do not exist at all. Alternatively, when env.php does not exist.

Db status code 1, means that's there's some version mismatch on the modules. That's generally resolved by running composer install + setup:upgrade.
An actual setup:install will drop existing tables and replace them with empty. In case of DB import, this occurs after the dump was imported, so the imported data is lost.

The version mismatch can occur for many reasons, e.g. the dump was pulled from an environment on one branch, but a local at the moment is on another branch with different composer modules - that would already result in such a code status. It doen't require new reinstall.

I'd structure the db import like this:

  1. check if env.php / db exists. If not, run a setup:install to generate env.php and get blank DB.
  2. import db
  3. setup:upgrade / (composer install as necessary, before that)

Similarly for a regular start.
I've had reports of CMA npm start resulting in database being overwritten with brand new Magento DB, when a migartion script had exceptions during setup:upgrade, for example(because someone committed a broken patch, etc)

Overall, setup:install should only run if there's nothing in the db / env.php is missing. It is not a fix for DB status 1.

The actual fix for that, is composer install / setup:upgrade / in some rare cases, manual fix of module versions in setup_module table in DB.

Example of version conflict - this can occur when the module version in the DB is higher than what is installed by composer, for example when module was upgraded at some point, and after that the module was rolled back - Magento doesn't fix its setup_module automatically, and keeps the high version in the DB table. However, deleting and reinstalling entire database to deal with such an issue is overkill.
A discrepancy in module versions will simply result in an exception when accessing the website in the browser, which will actually display which versions are off, and then it can be up to developer / team lead to fix the issue with DB.

@aleksandrsm
Copy link
Author

On another note, isDbEmpty flag in installMagento seems to only affect the output line. Install is run no matter what...

ejnshtein added a commit that referenced this issue Jun 9, 2022
…and add check to skip magento setup if env.php or config.php are present or database is not empty
@ejnshtein
Copy link
Collaborator

You can try changes that are released in 1.15.7!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants