Skip to content

Add opt-int database seeding support #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 11, 2025

Conversation

DarkGhostHunter
Copy link

This adds the ability to seed the database.

Laravel can seed the database without confirmation when the application is not on production. By using this ability to confirm, the seeding can be enabled by setting AUTORUN_LARAVEL_SEED to either true or the class name of the Database Seeder.

This step runs after the migration step.

@chris0203
Copy link

This will not work in production. it got an error when APP_ENV=production

🚀 Running seeders...

                            APPLICATION IN PRODUCTION.                           

WARN  Command cancelled.

should change it to

php ${APP_BASE_DIR}/artisan db:seed --force

@DarkGhostHunter
Copy link
Author

This will not work in production. it got an error when APP_ENV=production

🚀 Running seeders...



                            APPLICATION IN PRODUCTION.                           



WARN  Command cancelled.

should change it to

php ${APP_BASE_DIR}/artisan db:seed --force

Shouldn't work on production. That's a feature. If you need seeding on production you have to do it manually.

@harrisonratcliffe
Copy link

Would really like to see this implemented @jaydrogers

@harrisonratcliffe
Copy link

This will not work in production. it got an error when APP_ENV=production

🚀 Running seeders...



                            APPLICATION IN PRODUCTION.                           



WARN  Command cancelled.

should change it to

php ${APP_BASE_DIR}/artisan db:seed --force

Shouldn't work on production. That's a feature. If you need seeding on production you have to do it manually.

Can add --force to get round that.

@DarkGhostHunter
Copy link
Author

I wouldn't. Rather, I would let the user create their own logic for seeding a production database.

This is because seeding is meant to fake records, and doing so in production can mix up real records.

This is great for staging or testing environments, tho, which is the main goal for this.

@jaydrogers
Copy link
Member

I see the use case for this now and I really like this. Let me evaluate this for v3.6 and I will keep you all posted 👍

@harrisonratcliffe
Copy link

Has this feature been released yet?

@jaydrogers jaydrogers changed the base branch from main to release/v3.6 March 11, 2025 18:45
@jaydrogers
Copy link
Member

Thanks for your contribution @DarkGhostHunter! This will be made available in v3.6: #523

@jaydrogers jaydrogers changed the title Adds opt-in seeding Add opt-int database seeding support Mar 11, 2025
@jaydrogers jaydrogers merged commit 2ffee5f into serversideup:release/v3.6 Mar 11, 2025
@github-project-automation github-project-automation bot moved this from 🤔 Evaluating to Done in serversideup/php v3.6 Mar 11, 2025
@aagjalpankaj
Copy link

@jaydrogers Just for my understanding, why seeding should be part of 50-laravel-automations.sh?

In my opinion,

  • Seeding can be a one-time activity for production and it's a very rare scenario. If someone want it, they should create a migration and call the seeder from that migration. I think that's the proper way for production.
  • 50-laravel-automations.sh will be triggerred from the entrypoint and will call the seeder everytime. That can break the deployment or may create unwanted records on production.

Though AUTORUN_LARAVEL_SEED is default false, I think seeding should not be part of the automation script. We should not make the image too extensive!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

5 participants