Let's do a quick AI-coding session and take an idea from concept to launch!
We'll use the IMDB dataset to build a movie ratings website.
Our AI tools:
- Replit - for the initial prototype
- Cursor - as our AI coding agent
- Postgres Pro - to give Cursor a Postgres expert
What we did:
- Create the initial app on Replit - it's slow!
- Fixed performance - including ORM queries, indexing, and caching
- Fixed an empty movie details pages
- Improved the sort for top-rated movies
Full Video
(play-by-play walkthrough is below)
https://github.com/user-attachments/assets/24e05745-65e9-4998-b877-a368f1eadc13
Let's get started...
1) Create the initial app on Replit
We prompt Replit with:
Create a web app based on flask, python and SQAlchemy ORM
It's website that uses the schema from the public IMDB dataset . Assume I've imported the IMDB dataset as-is and add to that. I want people to be able to browse a mobile-friendly page for each movie, with all the IMDB data related to that movie. Additionally, people can rate each movie 1-5 and view top rated movies. The community and these ratings are one of the primary uses cases for the website.
Boom! We have a fully functional website with ratings, search, browse, auth -- in under an hour. What!! So cool.
But it's slooooow...
The AI agent created a bunch of ORM code and what looked like reasonable indexes, but clearly it got it wrong.
|
 |
2) Fix query performance
Our website looks decent, but it's too slow to ship.
Let's switch to Cursor w/ Postgres Pro to get the app ready for launch.
Our prompt:
My app is slow!
- Look for opportunities to speed up by improving queries, indexes or caching.
- For db changes use migration scripts I can apply later.
Let's see what all the AI agent did.
- Explored the schema and code to identify potential problem queries
- Used Postgres Pro to diagnose by calling
get_top_queries, analyze_db_health, and analyze_query_indexes
- Added multiple indexes to improve query performance
- Remove unused and bloated indexes to reclaim space
- Added caching for expensive queries and image loading
- Created a migration script to apply the changes
That was amazing! The agent was able to connect the dots between the database analysis and the code to create a comprehensive PR in 2.5 minutes.
It summarized the expected impact:
- Text searches will be 10-100x faster
- Page loads will be 2-5x faster
- Database load will be significantly reduced
- External API calls will be reduced by ~90%
|
 |
3) Fix empty movie details pages
The movie details looks empty. Let's investigate.
The movie details page looks awful.
- no cast/crew. Are we missing the data or is the query wrong?
- The ratings looks misplaced. move it closer to the title
- Do we have additional data we can include like a description? Check the schema.
The result?
- It used Postgres Pro to inspect the schema and compare it against the code.
- It fixed the query in the route to join with
name_basics.
- It identified additional data in
title_basics
to create a new About section with genre, runtime, and release years.
Let's ask:
Am I missing any data?
The AI Agent runs the sql queries and figures out we are indeed missing the cast/crew data. It writes a script to import it in a more reliable way.
(it turned out my original script aborted on errors)
|
|
4) Improve the sort for top-rated movies
The top-rated page is showing the classics like "Sisters of the Shrink 4" and "Zhuchok", etc. Something is wrong!
How are the top-rated sorted? It seems random.
Do we have data in those tables? Is the query it uses working?
The Agent checks the data and code dentifies that the issue is there is no minimum on the num_votes
So I ask:
help me find a good minimum of reviews
The AI Agent gets the distribution of data and some sample results to determine that a 10K vote minimum would give the best results. It's great seeing the results are grounded in reality and not just some hallucination.
|
|