Managing the database
Throughout this part of the book, the SportsStore application has been configured to automatically recreate and seed the database each time the server is started. I generally like this approach for my own projects, but it is especially useful for book examples because it ensures that the reader is always working with clean data and removes one potential cause of problems, where the code changes and becomes out of sync with the database schema.
In production, the database should not be reset every time the server starts, but it is still important to ensure that the database is created and seeded during the initial deployment. To extend the administration tool so that the database can be reset and reseeded, add a file named database_routes.ts
to the src/routes/admin
folder, with the content shown in Listing 21.3.
Listing 21.3: The contents of the database_routes.ts file in the src/routes/admin folder
import { Router } from "express";
import...