From f143560467c05f53a2890dbc5de0fbf6c1288c88 Mon Sep 17 00:00:00 2001 From: Italo Date: Wed, 17 Jul 2024 23:51:51 +0000 Subject: [PATCH 1/3] Adds opt-in seeding --- .../etc/entrypoint.d/50-laravel-automations.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/common/etc/entrypoint.d/50-laravel-automations.sh b/src/common/etc/entrypoint.d/50-laravel-automations.sh index e4358e6ab..b3fd1039b 100644 --- a/src/common/etc/entrypoint.d/50-laravel-automations.sh +++ b/src/common/etc/entrypoint.d/50-laravel-automations.sh @@ -76,7 +76,18 @@ if [ "$DISABLE_DEFAULT_CONFIG" = "false" ]; then php "$APP_BASE_DIR/artisan" migrate --force fi fi - + ############################################################################ + # artisan db:seed + ############################################################################ + if [ ! "${AUTORUN_LARAVEL_SEED:=false}" = "false" ]; then + echo "🚀 Running seeders..." + # Run the default seeder if "true", otherwise use value as custom seeder + if [ "${AUTORUN_LARAVEL_SEED}" = "true" ]; then + php ${APP_BASE_DIR}/artisan db:seed + else + php ${APP_BASE_DIR}/artisan db:seed --seeder=${AUTORUN_LARAVEL_SEED} + fi + fi ############################################################################ # artisan storage:link ############################################################################ From 24fba6600a9005259f884bcc501970baa44716c3 Mon Sep 17 00:00:00 2001 From: Jay Rogers Date: Tue, 11 Mar 2025 14:04:00 -0500 Subject: [PATCH 2/3] Updated seeders to execute correctly. Configured defaults. --- .../entrypoint.d/50-laravel-automations.sh | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/common/etc/entrypoint.d/50-laravel-automations.sh b/src/common/etc/entrypoint.d/50-laravel-automations.sh index 6312c9b59..f60af69d1 100644 --- a/src/common/etc/entrypoint.d/50-laravel-automations.sh +++ b/src/common/etc/entrypoint.d/50-laravel-automations.sh @@ -24,6 +24,9 @@ script_name="laravel-automations" : "${AUTORUN_LARAVEL_MIGRATION_ISOLATION:=false}" : "${AUTORUN_LARAVEL_MIGRATION_TIMEOUT:=30}" +# Set default values for seeders +: "${AUTORUN_LARAVEL_SEED:=false}" + # Set default values for Laravel version INSTALLED_LARAVEL_VERSION="" @@ -136,7 +139,7 @@ artisan_optimize() { [ "$AUTORUN_LARAVEL_VIEW_CACHE" = "false" ] && except="${except:+${except},}views" [ "$AUTORUN_LARAVEL_EVENT_CACHE" = "false" ] && except="${except:+${except},}events" - echo "đŸ› ī¸ Running optimizations: \"php artisan optimize ${except:+--except=${except}}\"..." + echo "🚀 Running optimizations: \"php artisan optimize ${except:+--except=${except}}\"..." if ! php "$APP_BASE_DIR/artisan" optimize ${except:+--except=${except}}; then echo "$script_name: ❌ Laravel optimize failed" return 1 @@ -175,15 +178,15 @@ artisan_optimize() { } artisan_seed(){ - if [ ! "${AUTORUN_LARAVEL_SEED:=false}" = "false" ]; then - echo "🚀 Running seeders..." - # Run the default seeder if "true", otherwise use value as custom seeder - if [ "${AUTORUN_LARAVEL_SEED}" = "true" ]; then - php ${APP_BASE_DIR}/artisan db:seed - else - php ${APP_BASE_DIR}/artisan db:seed --seeder=${AUTORUN_LARAVEL_SEED} - fi - fi + # Run the default seeder if "true", otherwise use value as custom seeder + if [ "${AUTORUN_LARAVEL_SEED}" = "true" ]; then + echo "🚀 Running default seeder: \"php artisan db:seed\"" + php "${APP_BASE_DIR}/artisan" db:seed --force + else + echo "🚀 Running custom seeder: \"php artisan db:seed --seeder=${AUTORUN_LARAVEL_SEED}\"" + echo "â„šī¸ Your application must have a seeder class named \"${AUTORUN_LARAVEL_SEED}\" or this command will fail." + php "${APP_BASE_DIR}/artisan" db:seed --seeder="${AUTORUN_LARAVEL_SEED}" + fi } get_laravel_version() { @@ -326,6 +329,10 @@ if laravel_is_installed; then artisan_migrate fi + if [ "$AUTORUN_LARAVEL_SEED" != "false" ]; then + artisan_seed + fi + if [ "$AUTORUN_LARAVEL_OPTIMIZE" = "true" ] || \ [ "$AUTORUN_LARAVEL_CONFIG_CACHE" = "true" ] || \ [ "$AUTORUN_LARAVEL_ROUTE_CACHE" = "true" ] || \ From f68670acd72c3adcb2d693ffd63a5a27a83d63ca Mon Sep 17 00:00:00 2001 From: Jay Rogers Date: Tue, 11 Mar 2025 14:07:58 -0500 Subject: [PATCH 3/3] Add documentation for Laravel db:seed automation option --- docs/content/docs/4.laravel/1.laravel-automations.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/content/docs/4.laravel/1.laravel-automations.md b/docs/content/docs/4.laravel/1.laravel-automations.md index a37ac392d..b1f7bee47 100644 --- a/docs/content/docs/4.laravel/1.laravel-automations.md +++ b/docs/content/docs/4.laravel/1.laravel-automations.md @@ -23,6 +23,7 @@ In order for this script to run,`AUTORUN_ENABLED` must be set to `true`. Once th | `AUTORUN_LARAVEL_MIGRATION_ISOLATION` | `false` | Run your migrations with the [`--isolated`](https://laravel.com/docs/12.x/migrations#running-migrations) flag.
**â„šī¸ Note:** Requires Laravel v9.38.0+ | | `AUTORUN_LARAVEL_MIGRATION_TIMEOUT` | `30` | Number of seconds to wait for database connection before timing out during migrations. | | `AUTORUN_LARAVEL_OPTIMIZE` | `true` | `php artisan optimize`: Optimizes the application. | +| `AUTORUN_LARAVEL_SEED` | `false` | `php artisan db:seed`: Runs the default seeder.
**â„šī¸ Note:** Set to `true` to run the default seeder. If you want to run a custom seeder, set this to the name of the seeder class. | | `AUTORUN_LARAVEL_ROUTE_CACHE` | `true` | `php artisan route:cache`: Caches the routes. | | `AUTORUN_LARAVEL_STORAGE_LINK` | `true` | `php artisan storage:link`: Creates a symbolic link from `public/storage` to `storage/app/public`. | | `AUTORUN_LARAVEL_VIEW_CACHE` | `true` | `php artisan view:cache`: Caches the views. | @@ -65,6 +66,11 @@ This command caches all configuration files into a single file, which can then b [Read more about configuration caching →](https://laravel.com/docs/12.x/configuration#configuration-caching) +## php artisan db:seed +This command runs the default seeder. If you want to run a custom seeder, set `AUTORUN_LARAVEL_SEED` to the name of the seeder class. + +[Read more about seeding →](https://laravel.com/docs/12.x/seeding) + ## php artisan route:cache This command caches the routes, dramatically decrease the time it takes to register all of your application's routes. After running this command, your cached routes file will be loaded on every request.