I must be missing something or not understanding something.

I'm trying to build a module for an install, and I'd like to run the initial migration. So the module initial install migration for the DB lives in /modules/moduleName/migrations/Install.php.

Nothing I run from the CLI seems to work:

./craft migrate/up

Only sees what is in the root /migrations/ folder; seems counter-intuitive to have a migrations folder in my module if I have to manually move them.

./craft migrate/up --plugin=everyVariationOfAPossibleHandleItMightFind

Doesn't work ever, as the module is installed and works, but it isn't a plugin so I guess it doesn't see it somehow (looking in the wrong place in the file system I would bet).

./craft migrate/up migrationPath=@app/modules/moduleName

Craft CLI doesn't seem carry that Yii CLI param, so I can't specify a path.

What am I missing? How do others handle custom module migrations in Craft 3?

up vote 2 down vote accepted

Per the Modules vs. Plugins docs, only plugins get their own migration track. Modules are considered part of the project (like templates and config files), so if there are any DB changes that need to be made for the module to run, those changes should be made via content migrations.

If the module is meant to be reused across multiple projects and does require DB migrations, then it will be better off as a plugin.

  • That makes sense. I just like the idea of keeping module specific migration files silo'd to my module, so to separate it from non-module specific migration files. – jrothafer Aug 4 at 23:45

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.