In this episode, we start building the foundation for tracking CSV imports in our application. After a user uploads a file and hits import (with validation out of the way), we want to create an Import
record in the database. This record helps us keep tabs on the progress—so if you refresh the page or check back later, you can continue right where you left off.
We walk through setting up an Import
model and migration. The model stores useful info like the file path, file name, which model you're importing (e.g., customers or products), how many rows are in the CSV, how many have been processed, and when the whole import finished. We discuss why each piece of info matters, and how this structure lets us show import progress to users or support features like resuming an incomplete import.
We set up the relationship between users and imports (every user can have many imports). Then, we hop over to our import component and add logic to create an Import
record as soon as the import starts. By the end of the episode, we're able to upload a file, hit import, and see a new record appear in the database with all the right fields.
Finally, we point out some small tweaks needed—like making sure fields are fillable and casting date fields properly. At the end, we leave off with a teaser for the next episode, where we'll figure out how to automatically count the total rows in the CSV so the import record is even more useful.