Work with the database
The API keeps its data in a SQLite file called movie-reviews.db. With dotnet run it sits next to the app. In the container it’s at /app/data/movie-reviews.db, on the movie-reviews-data volume, so it survives a restart and a rebuild. Nothing to install, nothing to provision, nothing to forget the password for.
When the database is created
Section titled “When the database is created”Every time the API starts, it applies any pending Entity Framework Core migrations. If Database:SeedSampleData is true and the database is empty, it also seeds the sample movies, authors and reviews. It’s on in appsettings.local.json and appsettings.docker.json, and off everywhere else, so a deployed copy never starts life full of fake reviews.
The sample data uses a fixed seed, so every machine gets the same 15 authors, the same movies and the same ids. That’s why the examples in these docs can name a movie id and expect it to exist on your laptop too.
Start again
Section titled “Start again”Delete movie-reviews.db, or drop the volume:
docker compose down -vThe next start builds a fresh database and seeds it again.
Use a different connection string
Section titled “Use a different connection string”Set ConnectionStrings__MovieReviews. To keep everything in memory, which is what the tests do:
docker run --rm -p 7340:7340 -e DOTNET_ENVIRONMENT=docker \ -e ConnectionStrings__MovieReviews="Data Source=MovieReviews;Mode=Memory;Cache=Shared" \ worksonmymachine-movies:localAdd a migration
Section titled “Add a migration”After you change the data model in src/Infrastructure:
dotnet tool install --global dotnet-efdotnet ef migrations add AddDirectors \ --project ./src/Infrastructure \ --output-dir Databases/MovieReviews/Migrations \ --namespace WorksOnMyMachine.Movies.Infrastructure.Databases.MovieReviews.Migrationssed -i '1s/^\xEF\xBB\xBF//' src/Infrastructure/Databases/MovieReviews/Migrations/*.csWithout --namespace the migration lands in a namespace of its own, and the sed strips the byte order mark the tool adds. On macOS, use sed -i ''. Then make // <auto-generated /> the first line of the new <timestamp>_AddDirectors.cs, as it is in the other migrations, so the analysers and dotnet format leave it alone. Swap WorksOnMyMachine.Movies for your solution’s name.
The next start applies it, and Make it yours adds a whole entity this way.
Swap SQLite for something real
Section titled “Swap SQLite for something real”Everything database-shaped lives in Infrastructure, and every class there but DependencyInjection is internal. To move to PostgreSQL, SQL Server or anything else, implement the repository interfaces from Application (IMoviesRepository, IAuthorsRepository and IReviewsRepository) against the new store and register them in Infrastructure/DependencyInjection.cs. Application and Presentation don’t need to know it happened. That’s the whole sales pitch of Clean Architecture in one paragraph.