- How do I install and set up `seeds-from-sql` in my Laravel project?
- Run `composer require christian-schoenefeld/seeds-from-sql`, then register the `SQLSeeder` class in your `DatabaseSeeder`'s `run()` method. No additional configuration is needed unless you customize the SQL file path.
- Can I use this package to seed a production database with large SQL dumps?
- Yes, but test performance first. The package uses `DB::unprepared()` for raw SQL execution, which may impact speed or memory usage. Consider batching large imports or running them outside peak hours.
- Does this package support Laravel 10+ and PHP 8.1+?
- Yes, the package is compatible with Laravel 10 and PHP 8.1+. It leverages Laravel’s built-in `DB` facade, which is fully supported in these versions. Always check the package’s `composer.json` for minor version constraints.
- Is there a risk of SQL injection when using `DB::unprepared()`?
- Yes, raw SQL execution via `DB::unprepared()` is vulnerable to injection if the SQL file contains user-provided or untrusted input. Only use this for trusted, static SQL files or sanitize inputs rigorously.
- How do I run only the SQL seeder without executing all seeders?
- Use the Artisan command `php artisan db:seed --class=SQLSeeder`. This bypasses other seeders and executes only the SQL seeder defined in the package.
- Can I customize the path or name of the SQL file used for seeding?
- Currently, the package defaults to a predefined SQL file path. To customize it, you’d need to extend the `SQLSeeder` class or modify the package’s source code directly, as there’s no built-in configuration option.
- Will this package work with PostgreSQL, MySQL, or SQLite?
- The package should work with any database Laravel supports, but raw SQL syntax (e.g., `ENGINE=InnoDB`) may not be portable. Test your SQL file across target databases to ensure compatibility.
- Are there alternatives to this package for seeding from SQL files?
- Yes, alternatives include manually using `DB::statement()` or `DB::unprepared()` in a custom seeder, or packages like `laravel-seed-dump` for generating seeders from existing databases. This package simplifies the process by providing a dedicated seeder class.
- How do I handle transactions or rollbacks when seeding with SQL?
- The package doesn’t automatically wrap SQL execution in transactions. For rollback support, wrap the `SQLSeeder` call in a transaction block in your `DatabaseSeeder` using `DB::transaction()`.
- Does this package trigger Laravel model events (e.g., `created`, `saved`) during SQL imports?
- No, raw SQL execution via `DB::unprepared()` bypasses Eloquent’s event system. If you rely on model events, consider using Eloquent-based seeders or factories instead.