craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.29k stars 638 forks source link

Craft install throws errors while trying to install with empty db and prepopulated project yamls #10523

Open jawys opened 2 years ago

jawys commented 2 years ago

Description

At our company we try to achieve the following cross developer experience:

This happened already quite often in our approach sharing development progress between different team members. Most of the time we see Exception 'craft\errors\MigrationException' with message 'An error occurred while executing the "craft\migrations\Install migration: Calling unknown method: craft\console\Request::getParam()' right before craft install is able to finish. See this for the whole console output: https://gist.github.com/jawys/51dc1fc7d773af93a94de9523d0d8b18#file-php_craft_install-log-L445

While searching for the origin of the errors trying to make a quickstart for new developers as easy as possible, we started removing plugins to mitigate issues with these. But still, we cannot achieve a frictionless install while sharing only code between devs on different machines. Do we need to share db dumps across us all as well?

Steps to reproduce

  1. Clone a craftcms git repo from your dev colleague
  2. Make sure you have a clean database
  3. Remove plugins: section from project.yaml
  4. Run craft install
  5. See this:

    [...]
    *** installed Craft successfully (time: 24.037s)
    
    2022-02-10 10:59:04 [-][-][-][error][craft\base\ApplicationTrait::getIsInstalled] There was a problem fetching the info row: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "info" does not exist
    LINE 2: FROM "info"
                ^
    The SQL being executed was: SELECT *
    FROM "info"
    WHERE "id"=1
    LIMIT 1
    2022-02-10 10:59:04 [-][-][-][error][yii\db\Exception] PDOException: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "info" does not exist
    LINE 2: FROM "info"
                ^ in /app/vendor/yiisoft/yii2/db/Command.php:1302
    Stack trace:
    #0 /app/vendor/yiisoft/yii2/db/Command.php(1302): PDOStatement->execute()
    #1 /app/vendor/yiisoft/yii2/db/Command.php(1168): yii\db\Command->internalExecute('SELECT *\nFROM "...')
    #2 /app/vendor/yiisoft/yii2/db/Command.php(424): yii\db\Command->queryInternal('fetch', NULL)
    #3 /app/vendor/yiisoft/yii2/db/Query.php(287): yii\db\Command->queryOne()
    #4 /app/vendor/craftcms/cms/src/db/Query.php(167): yii\db\Query->one(NULL)
    #5 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(671): craft\db\Query->one()
    #6 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(329): craft\console\Application->getInfo(true)
    #7 /app/vendor/craftcms/cms/src/helpers/App.php(758): craft\console\Application->getIsInstalled()
    #8 /app/vendor/craftcms/cms/src/config/app.php(245): craft\helpers\App::projectConfigConfig()
    #9 [internal function]: {closure}()
    #10 /app/vendor/yiisoft/yii2/di/Container.php(633): call_user_func_array(Object(Closure), Array)
    #11 /app/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->invoke(Object(Closure), Array)
    #12 /app/vendor/yiisoft/yii2/di/ServiceLocator.php(137): yii\BaseYii::createObject(Object(Closure))
    #13 /app/vendor/yiisoft/yii2/base/Module.php(766): yii\di\ServiceLocator->get('projectConfig', true)
    #14 /app/vendor/craftcms/cms/src/console/Application.php(158): yii\base\Module->get('projectConfig', true)
    #15 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(1322): craft\console\Application->get('projectConfig')
    #16 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(1508): craft\console\Application->getProjectConfig()
    #17 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(1464): craft\console\Application->_setTimeZone()
    #18 /app/vendor/craftcms/cms/src/console/Application.php(46): craft\console\Application->_preInit()
    #19 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\console\Application->init()
    #20 /app/vendor/yiisoft/yii2/base/Application.php(204): yii\base\BaseObject->__construct(Array)
    #21 /app/vendor/yiisoft/yii2/console/Application.php(89): yii\base\Application->__construct(Array)
    #22 [internal function]: yii\console\Application->__construct(Array)
    #23 /app/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
    #24 /app/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\console\\A...', Array, Array)
    #25 /app/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\console\\A...', Array, Array)
    #26 /app/vendor/craftcms/cms/src/Craft.php(61): yii\BaseYii::createObject(Array, Array)
    #27 /app/vendor/craftcms/cms/bootstrap/bootstrap.php(246): Craft::createObject(Array)
    #28 /app/vendor/craftcms/cms/bootstrap/console.php(51): require('/app/vendor/cra...')
    #29 /app/craft(12): require('/app/vendor/cra...')
    #30 {main}
    
    Next yii\db\Exception: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "info" does not exist
    LINE 2: FROM "info"
                ^
    The SQL being executed was: SELECT *
    FROM "info"
    WHERE "id"=1
    LIMIT 1 in /app/vendor/yiisoft/yii2/db/Schema.php:676
    Stack trace:
    #0 /app/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'SELECT *\nFROM "...')
    #1 /app/vendor/yiisoft/yii2/db/Command.php(1168): yii\db\Command->internalExecute('SELECT *\nFROM "...')
    #2 /app/vendor/yiisoft/yii2/db/Command.php(424): yii\db\Command->queryInternal('fetch', NULL)
    #3 /app/vendor/yiisoft/yii2/db/Query.php(287): yii\db\Command->queryOne()
    #4 /app/vendor/craftcms/cms/src/db/Query.php(167): yii\db\Query->one(NULL)
    #5 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(671): craft\db\Query->one()
    #6 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(329): craft\console\Application->getInfo(true)
    #7 /app/vendor/craftcms/cms/src/helpers/App.php(758): craft\console\Application->getIsInstalled()
    #8 /app/vendor/craftcms/cms/src/config/app.php(245): craft\helpers\App::projectConfigConfig()
    #9 [internal function]: {closure}()
    #10 /app/vendor/yiisoft/yii2/di/Container.php(633): call_user_func_array(Object(Closure), Array)
    #11 /app/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->invoke(Object(Closure), Array)
    #12 /app/vendor/yiisoft/yii2/di/ServiceLocator.php(137): yii\BaseYii::createObject(Object(Closure))
    #13 /app/vendor/yiisoft/yii2/base/Module.php(766): yii\di\ServiceLocator->get('projectConfig', true)
    #14 /app/vendor/craftcms/cms/src/console/Application.php(158): yii\base\Module->get('projectConfig', true)
    #15 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(1322): craft\console\Application->get('projectConfig')
    #16 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(1508): craft\console\Application->getProjectConfig()
    #17 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(1464): craft\console\Application->_setTimeZone()
    #18 /app/vendor/craftcms/cms/src/console/Application.php(46): craft\console\Application->_preInit()
    #19 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\console\Application->init()
    #20 /app/vendor/yiisoft/yii2/base/Application.php(204): yii\base\BaseObject->__construct(Array)
    #21 /app/vendor/yiisoft/yii2/console/Application.php(89): yii\base\Application->__construct(Array)
    #22 [internal function]: yii\console\Application->__construct(Array)
    #23 /app/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
    #24 /app/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\console\\A...', Array, Array)
    #25 /app/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\console\\A...', Array, Array)
    #26 /app/vendor/craftcms/cms/src/Craft.php(61): yii\BaseYii::createObject(Array, Array)
    #27 /app/vendor/craftcms/cms/bootstrap/bootstrap.php(246): Craft::createObject(Array)
    #28 /app/vendor/craftcms/cms/bootstrap/console.php(51): require('/app/vendor/cra...')
    #29 /app/craft(12): require('/app/vendor/cra...')
    #30 {main}
    Additional Information:
    Array
    (
        [0] => 42P01
        [1] => 7
        [2] => ERROR:  relation "info" does not exist
    LINE 2: FROM "info"
                ^
    )
    2022-02-10 10:59:04 [-][-][-][error][craft\base\ApplicationTrait::getIsInstalled] There was a problem fetching the info row: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "public.info" does not exist
    LINE 2: FROM public."info"
                ^
    The SQL being executed was: SELECT EXISTS(SELECT *
    FROM public."info"
    WHERE "id"=1)
    2022-02-10 10:59:04 [-][-][-][error][yii\db\Exception] PDOException: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "public.info" does not exist
    LINE 2: FROM public."info"
                ^ in /app/vendor/yiisoft/yii2/db/Command.php:1302
    Stack trace:
    #0 /app/vendor/yiisoft/yii2/db/Command.php(1302): PDOStatement->execute()
    #1 /app/vendor/yiisoft/yii2/db/Command.php(1168): yii\db\Command->internalExecute('SELECT EXISTS(S...')
    #2 /app/vendor/yiisoft/yii2/db/Command.php(436): yii\db\Command->queryInternal('fetchColumn', 0)
    #3 /app/vendor/yiisoft/yii2/db/Query.php(446): yii\db\Command->queryScalar()
    #4 /app/vendor/craftcms/cms/src/db/Query.php(213): yii\db\Query->exists(NULL)
    #5 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(325): craft\db\Query->exists()
    #6 /app/vendor/craftcms/cms/src/console/controllers/InstallController.php(104): craft\console\Application->getIsInstalled(true)
    #7 [internal function]: craft\console\controllers\InstallController->actionCraft()
    #8 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
    #9 /app/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
    #10 /app/vendor/yiisoft/yii2/console/Controller.php(182): yii\base\Controller->runAction('', Array)
    #11 /app/vendor/craftcms/cms/src/console/Controller.php(221): yii\console\Controller->runAction('', Array)
    #12 /app/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('', Array)
    #13 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('install', Array)
    #14 /app/vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction('install', Array)
    #15 /app/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('install', Array)
    #16 /app/vendor/yiisoft/yii2/base/Application.php(384): yii\console\Application->handleRequest(Object(craft\console\Request))
    #17 /app/craft(13): yii\base\Application->run()
    #18 {main}
    
    Next yii\db\Exception: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "public.info" does not exist
    LINE 2: FROM public."info"
                ^
    The SQL being executed was: SELECT EXISTS(SELECT *
    FROM public."info"
    WHERE "id"=1) in /app/vendor/yiisoft/yii2/db/Schema.php:676
    Stack trace:
    #0 /app/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'SELECT EXISTS(S...')
    #1 /app/vendor/yiisoft/yii2/db/Command.php(1168): yii\db\Command->internalExecute('SELECT EXISTS(S...')
    #2 /app/vendor/yiisoft/yii2/db/Command.php(436): yii\db\Command->queryInternal('fetchColumn', 0)
    #3 /app/vendor/yiisoft/yii2/db/Query.php(446): yii\db\Command->queryScalar()
    #4 /app/vendor/craftcms/cms/src/db/Query.php(213): yii\db\Query->exists(NULL)
    #5 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(325): craft\db\Query->exists()
    #6 /app/vendor/craftcms/cms/src/console/controllers/InstallController.php(104): craft\console\Application->getIsInstalled(true)
    #7 [internal function]: craft\console\controllers\InstallController->actionCraft()
    #8 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
    #9 /app/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
    #10 /app/vendor/yiisoft/yii2/console/Controller.php(182): yii\base\Controller->runAction('', Array)
    #11 /app/vendor/craftcms/cms/src/console/Controller.php(221): yii\console\Controller->runAction('', Array)
    #12 /app/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('', Array)
    #13 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('install', Array)
    #14 /app/vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction('install', Array)
    #15 /app/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('install', Array)
    #16 /app/vendor/yiisoft/yii2/base/Application.php(384): yii\console\Application->handleRequest(Object(craft\console\Request))
    #17 /app/craft(13): yii\base\Application->run()
    #18 {main}
    Additional Information:
    Array
    (
        [0] => 42P01
        [1] => 7
        [2] => ERROR:  relation "public.info" does not exist
    LINE 2: FROM public."info"
                ^
    )
  6. Point your browser to your local craft installation (in our case http://localhost:8080)
  7. Refresh the site if you are on the /admin/install screen
  8. Does work actually?!

Additional info

timkelty commented 2 years ago

@jawys Something is awry, your outlined workflow should work fine (Developer B should be able to craft intall with a project config and no database).

I'm also unable to reproduce…can supply a set of project config files and composer.json/lock files to reproduce this?

The Calling unknown method: craft\console\Request::getParam() error is from the SitePickerField, which is making the installation fail.

jawys commented 2 years ago

Yes I will provide some minimal example. Just have to find the time to prepare something

dlindberg commented 2 years ago

I’ve noticed a this or a similar / related issue. Plugins that were previously uninstalled (Using Craft uninstall and then Composer remove) will make Craft very angry when trying to install itself on an empty database. (Not all of them, but some early plugins that I had managed with project config I’ve seen this happen.)

It seems like at some point entries for removed plugins didn’t get full excised from project.yaml and it attempts to install and then just deactivate the plugin (which it cannot do because the plugin code no longer exists in the project) and then process crashes. If I go in and manually delete the entries for the removed plugins in project.yaml Everything appears to be happy, but just doing a rebuild on project config doesn’t excise the ghost plugins.