Skip to content

Commit bfb00cd

Browse files
committed
Enhance Laravel automation scripts with new migration options and improved error handling. Added support for multiple databases, migration modes, and seeding. Updated documentation to reflect these changes and added a new script for testing database connections.
1 parent 3f1f527 commit bfb00cd

File tree

4 files changed

+412
-148
lines changed

4 files changed

+412
-148
lines changed

docs/content/docs/4.laravel/1.laravel-automations.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ In order for this script to run,`AUTORUN_ENABLED` must be set to `true`. Once th
2020
| `AUTORUN_LARAVEL_CONFIG_CACHE` | `true` | `php artisan config:cache`: Caches the configuration files into a single file. |
2121
| `AUTORUN_LARAVEL_EVENT_CACHE` | `true` | `php artisan event:cache`: Creates a manifest of all your application's events and listeners. |
2222
| `AUTORUN_LARAVEL_MIGRATION` | `true` | `php artisan migrate`: Runs migrations. |
23-
| `AUTORUN_LARAVEL_MIGRATION_ISOLATION` | `false` | Run your migrations with the [`--isolated`](https://laravel.com/docs/12.x/migrations#running-migrations) flag. <br> **ℹ️ Note:** Requires Laravel v9.38.0+ |
23+
| `AUTORUN_LARAVEL_MIGRATION_DATABASE` | `null` | Run migrations on a specific database. In the rare case you need to use multiple databases, you can provide a comma-delimited list of connection names (e.g., "mysql,pgsql"). If `null`, it will use the default database connection. |
24+
| `AUTORUN_LARAVEL_MIGRATION_FORCE` | `true` | Force migrations to run in production without confirmation. Set to `false` to disable the `--force` flag. |
25+
| `AUTORUN_LARAVEL_MIGRATION_ISOLATION` | `false` | Run your migrations with the [`--isolated`](https://laravel.com/docs/12.x/migrations#running-migrations) flag. <br> **ℹ️ Note:** Requires Laravel v9.38.0+. Only works with `default` migration mode. |
26+
| `AUTORUN_LARAVEL_MIGRATION_MODE` | `default` | Migration mode: `default`, `fresh`, or `refresh`. <br> **⚠️ Warning:** `fresh` and `refresh` drop all tables. |
27+
| `AUTORUN_LARAVEL_MIGRATION_SEED` | `false` | Automatically seed the database after migrations using the `--seed` flag. |
28+
| `AUTORUN_LARAVEL_MIGRATION_SKIP_DB_CHECK` | `false` | Skip the database connection check before running migrations. |
2429
| `AUTORUN_LARAVEL_MIGRATION_TIMEOUT` | `30` | Number of seconds to wait for database connection before timing out during migrations. |
2530
| `AUTORUN_LARAVEL_OPTIMIZE` | `true` | `php artisan optimize`: Optimizes the application. |
26-
| `AUTORUN_LARAVEL_SEED` | `false` | `php artisan db:seed`: Runs the default seeder. <br> **ℹ️ 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. |
2731
| `AUTORUN_LARAVEL_ROUTE_CACHE` | `true` | `php artisan route:cache`: Caches the routes. |
2832
| `AUTORUN_LARAVEL_STORAGE_LINK` | `true` | `php artisan storage:link`: Creates a symbolic link from `public/storage` to `storage/app/public`. |
2933
| `AUTORUN_LARAVEL_VIEW_CACHE` | `true` | `php artisan view:cache`: Caches the views. |
@@ -42,10 +46,41 @@ Creates a symbolic link from `public/storage` to `storage/app/public`.
4246
## php artisan migrate
4347
Before running migrations, we ensure the database is online and ready to accept connections. By default, we will wait 30 seconds before timing out.
4448

49+
### Migration Modes
50+
You can control how migrations run using `AUTORUN_LARAVEL_MIGRATION_MODE`:
51+
- `default` (default): Runs `php artisan migrate` - standard forward migrations
52+
- `fresh`: Runs `php artisan migrate:fresh` - drops all tables and re-runs migrations
53+
- `refresh`: Runs `php artisan migrate:refresh` - rolls back and re-runs migrations
54+
55+
::note
56+
**⚠️ Warning:** Using `fresh` or `refresh` modes will **drop all tables** in your database. Only use these in development or testing environments.
57+
::
58+
59+
### Force Flag
60+
By default, migrations run with the `--force` flag to bypass production warnings. You can disable this by setting `AUTORUN_LARAVEL_MIGRATION_FORCE` to `false`.
61+
62+
### Seeding
63+
You can automatically seed your database after migrations by setting `AUTORUN_LARAVEL_MIGRATION_SEED` to `true`. This adds the `--seed` flag to your migration command.
64+
65+
### Specific Database Migrations
66+
If you need to specify the exact database connection to use for migrations, you can set `AUTORUN_LARAVEL_MIGRATION_DATABASE` to the name of the database connection you want to use.
67+
68+
```bash
69+
AUTORUN_LARAVEL_MIGRATION_DATABASE=mysql
70+
```
71+
72+
In the rare case you need to use multiple databases, you can provide a comma-delimited list of connection names (e.g., "mysql,pgsql").
73+
74+
```bash
75+
AUTORUN_LARAVEL_MIGRATION_DATABASE=mysql,pgsql
76+
```
77+
78+
### Isolated Migrations
4579
You can enable the [`--isolated`](https://laravel.com/docs/12.x/migrations#running-migrations) flag by setting `AUTORUN_LARAVEL_MIGRATION_ISOLATION` to `true`, which will ensure no other containers are running a migration.
4680

4781
**Special Notes for Isolated Migrations:**
4882
- Requires Laravel v9.38.0+
83+
- Only works with `default` migration mode (not compatible with `fresh` or `refresh`)
4984
- Your application must be using the memcached, redis, dynamodb, database, file, or array cache driver as your application's default cache driver. In addition, all servers must be communicating with the same central cache server.
5085

5186
[Read more about migrations →](https://laravel.com/docs/12.x/migrations#running-migrations)
@@ -66,11 +101,6 @@ This command caches all configuration files into a single file, which can then b
66101

67102
[Read more about configuration caching →](https://laravel.com/docs/12.x/configuration#configuration-caching)
68103

69-
## php artisan db:seed
70-
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.
71-
72-
[Read more about seeding →](https://laravel.com/docs/12.x/seeding)
73-
74104
## php artisan route:cache
75105
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.
76106

docs/content/docs/7.reference/1.environment-variable-specification.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ We like to customize our images on a per app basis using environment variables.
2626
`AUTORUN_LARAVEL_CONFIG_CACHE`<br />*Default: "true"*|Automatically run "php artisan config:cache" on container start. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
2727
`AUTORUN_LARAVEL_EVENT_CACHE`<br />*Default: "true"*|Automatically run "php artisan event:cache" on container start. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
2828
`AUTORUN_LARAVEL_MIGRATION`<br />*Default: "true"*|Automatically run `php artisan migrate --force` on container start. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
29-
`AUTORUN_LARAVEL_MIGRATION_ISOLATION`<br />*Default: "false"*|Requires Laravel v9.38.0 or higher and a database that supports table locks. Automatically run `php artisan migrate --force --isolated` on container start. <br /><br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.<br />ℹ️ Does not work with SQLite.| all
29+
`AUTORUN_LARAVEL_MIGRATION_DATABASE`<br />*Default: null*| Run migrations on a specific database. In the rare case you need to use multiple databases, you can provide a comma-delimited list of connection names (e.g., "mysql,pgsql"). If `null`, it will use the default database connection. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
30+
`AUTORUN_LARAVEL_MIGRATION_FORCE`<br />*Default: "true"*|Force migrations to run in production without confirmation. Set to `false` to disable the `--force` flag. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
31+
`AUTORUN_LARAVEL_MIGRATION_ISOLATION`<br />*Default: "false"*|Requires Laravel v9.38.0 or higher and a database that supports table locks. Automatically run `php artisan migrate --force --isolated` on container start. <br /><br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.<br />ℹ️ Does not work with SQLite.<br />ℹ️ Only works with `AUTORUN_LARAVEL_MIGRATION_MODE = default`.| all
32+
`AUTORUN_LARAVEL_MIGRATION_MODE`<br />*Default: "default"*|Set the migration mode. Valid options: `default` (runs `php artisan migrate`), `fresh` (runs `php artisan migrate:fresh`), or `refresh` (runs `php artisan migrate:refresh`). <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.<br />⚠️ WARNING:`fresh` and `refresh` are destructive and will drop all tables. Only use these in development or testing environments.| all
33+
`AUTORUN_LARAVEL_MIGRATION_SEED`<br />*Default: "false"*|Automatically seed the database after migrations by adding the `--seed` flag. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
3034
`AUTORUN_LARAVEL_MIGRATION_SKIP_DB_CHECK`<br />*Default: "false"*|Skip the database connection check before running migrations. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
3135
`AUTORUN_LARAVEL_MIGRATION_TIMEOUT`<br />*Default: "30"*|The number of seconds to wait for the database to come online before attempting `php artisan migrate`.. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
3236
`AUTORUN_LARAVEL_ROUTE_CACHE`<br />*Default: "true"*|Automatically run "php artisan route:cache" on container start. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
33-
`AUTORUN_LARAVEL_SEED`<br />*Default: "false"*|Automatically run database seeder on container start. Set to `true` to run the default seeder (`php artisan db:seed --force`), or provide a custom seeder class name (e.g., `DatabaseSeeder`) to run a specific seeder (`php artisan db:seed --seeder=DatabaseSeeder`). <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
3437
`AUTORUN_LARAVEL_STORAGE_LINK`<br />*Default: "true"*|Automatically run "php artisan storage:link" on container start. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
3538
`AUTORUN_LARAVEL_VIEW_CACHE`<br />*Default: "true"*|Automatically run "php artisan view:cache" on container start. <br />ℹ️ Requires `AUTORUN_ENABLED = true` to run.| all
3639
`CADDY_ADMIN`<br />*Default: "off"*|Enable Caddy admin interface. (<a target="_blank" href="https://caddyserver.com/docs/caddyfile/options#admin">Official docs</a>)|frankenphp

0 commit comments

Comments
 (0)