C
C#3mo ago
{sus}

✅ Migration-independent Database Seeding

Curious if EF has some sort of independent database seeding potential? I am kinda hoping to see a similar functionality to Laravel's Database Seeder where you can write the seed in a file which you can run at any time, regardless of whether or not your migrations are already ran. I find the HasData fucntiuonality inherently counterproductive as I don't want to re-run all migrations over and over just so I can work with my seed data. Laravel Seeding: https://laravel.com/docs/11.x/seeding
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
35 Replies
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
Which is exactly my problem with it
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
I already have finalized the schema Actually
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
And have the migrations for it, already ran, which means that the schema is now in the database and the tables are already generated
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
At which point, I started working with seeding hte database
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
I am pointing out what you can do with database seeding in Laravel, which you can actually run without running the migrations Which can work with existing database schemas.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
In laravel, migrations and seeders are independent of each other. YOu can write migrations without seeders, and you can write seeders without migrations.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
it just throws an error
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
Just tells you that there's a problem when running the seed
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
It knows because it would try to run the SQL statement
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
just try it and see. Anyhow, going back to the topic
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
Hmmm interesting. Is it possible to run this from a dotnet ef XXX context? sorta like dotnet ef <New seed command> MySeeder
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
Just wrapping my head around this EFCore thing coming from a Laravel background I find it weird
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
But I have to for ease of use.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
I think it's nice to define DDLs on code
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
{sus}
{sus}OP3mo ago
and make it easier for other folks working with me to understand what's happening all the while being able to use dotnet tooling
Pobiega
Pobiega3mo ago
you could make your own seed program as an alterantive start project. so instead of dotnet run path/to/webapi youd do dotnet run path/to/seeder/
{sus}
{sus}OP3mo ago
Ooooh. So it's basically a new project inside my existing solution*?
Pobiega
Pobiega3mo ago
yes another alternative is to have your seeder run at startup of the web api, but check if it has already seeded
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX3mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server