Closed jordikroon closed 5 years ago
@jordikroon can you provide an example of where a migration is failing? That would help in fixing the issue.
We use Amazon S3 for storing our images. Our settings are stored in the .env file. Same can be applied for the (default) local image adapter.
The screenshot above generates this migration. Where as you can see the variables behave like normal PHP variables.
<?php
namespace craft\contentmigrations;
use craft\db\Migration;
//use craft\db\MigrationManager;
//use craft\helpers\MigrationHelper;
use firstborn\migrationmanager\MigrationManager;
/**
* Generated migration
*/
class m190221_104420_migration_assetVolume_default extends Migration
{
/**
Migration manifest:
ASSETVOLUME
- default
*/
private $json = <<<JSON
{"settings":{"dependencies":{"assetVolumes":[{"name":"Default","handle":"default","type":"craft\\\\awss3\\\\Volume","sortOrder":null,"typesettings":{"subfolder":"","keyId":"$AWS_ACCESS_KEY_ID","secret":"$AWS_ACCESS_KEY_TOKEN","bucket":"racingnews-v2-dev","region":"eu-west-1","expires":"","storageClass":"","cfDistributionId":"","autoFocalPoint":""},"hasUrls":1,"url":"$S3_BASE_URL"}]},"elements":{"assetVolumes":[{"name":"Default","handle":"default","type":"craft\\\\awss3\\\\Volume","sortOrder":null,"typesettings":{"subfolder":"","keyId":"$AWS_ACCESS_KEY_ID","secret":"$AWS_ACCESS_KEY_TOKEN","bucket":"racingnews-v2-dev","region":"eu-west-1","expires":"","storageClass":"","cfDistributionId":"","autoFocalPoint":""},"hasUrls":1,"url":"$S3_BASE_URL","fieldLayout":{"Content":["subTitle"]}}]}}}
JSON;
/**
* Any migration code in here is wrapped inside of a transaction.
* Returning false will rollback the migration
*
* @return bool
*/
public function safeUp()
{
return MigrationManager::getInstance()->migrations->import($this->json); }
public function safeDown()
{
echo "m190221_104420_migration_assetVolume_default cannot be reverted.\n";
return false;
}
}
@jordikroon fixed in latest release
Execution of migrations fails when using environment variables. This is because they behave like PHP variables when surrounded with double quotes.
Possible solutions are to use single quotes instead, or escape variables with a backslash (
\
)