没有不值得去解决的问题,也没有不值得去学习的技术!

Publish Database Migrations for Modules in Laravel 6

However, with a large number of modules, it is impractical to frequently add migration commands for each corresponding module in the startup script. Reference: module:publish-migration, to publish the module's database migration files.

1. In the Docker container’s startup script, to force the migration command to run without prompts, use the –force parameter.

Bash

php artisan migrate --force

2. Currently, there are modules developed based on LARAVEL MODULES that contain migration files, for example: /Modules/ThemeStoreDB/Database/Migrations. See Figure 1.

Currently, there are modules developed based on LARAVEL MODULES that contain migration files, for example: /Modules/ThemeStoreDB/Database/Migrations
Figure 1

3. In the local development environment, to execute the migration files under a module, you typically run the command: php artisan module:migrate ThemeStoreDB. See Figure 2.

In the local development environment, to execute the migration files under a module, you typically run the command: php artisan module:migrate ThemeStoreDB
Figure 2
Plaintext

PS E:\wwwroot\object> php artisan module:migrate ThemeStoreDB
Migrating: 2021_12_06_133918_create_theme_asset_table
Migrated:  2021_12_06_133918_create_theme_asset_table (0.11 seconds)
Migrating: 2021_12_13_145303_create_theme_asset_version_table
Migrated:  2021_12_13_145303_create_theme_asset_version_table (0.1 seconds)
Migrating: 2022_05_16_105847_create_theme_installation_table
Migrated:  2022_05_16_105847_create_theme_installation_table (0.07 seconds)
Migrating: 2022_05_16_134353_create_theme_installation_version_preset_table
Migrated:  2022_05_16_134353_create_theme_installation_version_preset_table (0.21 seconds)
Migrating: 2022_05_16_172815_create_theme_installation_task_table
Migrated:  2022_05_16_172815_create_theme_installation_task_table (0.12 seconds)

4. However, with a large number of modules, it is impractical to frequently add migration commands for each corresponding module in the startup script. Reference: module:publish-migration, to publish the module’s database migration files. See Figure 3.

However, with a large number of modules, it is impractical to frequently add migration commands for each corresponding module in the startup script. Reference: module:publish-migration, to publish the module's database migration files.
Figure 3
Plaintext

PS E:\wwwroot\object> php artisan module:publish-migration ThemeStoreDB

5. The files in the directory: /Modules/ThemeStoreDB/Database/Migrations have been copied to the directory: /database/migrations. See Figure 4.

The files in the directory: /Modules/ThemeStoreDB/Database/Migrations have been copied to the directory: /database/migrations
Figure 4

6. This way, the command to execute migrations in the startup script only needs to be: php artisan migrate –force, without requiring any changes. When executed in the local environment, there are no migrations to run, which is as expected.

Plaintext

PS E:\wwwroot\object> php artisan migrate
Nothing to migrate.
PS E:\wwwroot\object>

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系