TASVideos / tasvideos

The code for the live TASVideos website
https://tasvideos.org/
GNU General Public License v3.0
63 stars 29 forks source link

Run Migration after Sample Data Generation #1788

Closed Masterjun3 closed 4 months ago

Masterjun3 commented 4 months ago

For Sample Data Generation, if the code base is on a later migration than the sample data, loading the data gives an error. This is because we first migrate the sample db to the latest schema with no data, and then try to add the sample data.

This PR changes the code, so that the DB is created without schema, then the schema+data is added from the sample data, and then finally we migrate if necessary.

This also means the schema needs to be exported with the sample data, and the __EFMigrationsHistory table needs to stay.

Masterjun3 commented 4 months ago

@adelikat I tested everything for this PR: having the sample data on a previous migration, or up-to-date, everything works fine. Still, I do use the IRelationalDatabaseCreator, to which the docs say:

It is generally not used in application code.

But this is the only way to properly create the DB without the schema. The official EnsureCreated() and Migrate() methods both use this same IRelationalDatabaseCreator, but afterwards they also create a prefilled schema, making the sample data insertion fail.

If this is unwanted, you can close the PR.