Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes invoice table re-ordering results on render and pagination due to order being random #531

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

esadler44
Copy link

Adds a unique value to the ORDER BY statement so that SQL behaves in a stable manner

This was causing unstable issues with pagination repeating data as you might get the same invoices on multiple pages with a non-unique ordering

Copy link

vercel bot commented Dec 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-learn-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 28, 2023 11:45pm
next-seo-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 28, 2023 11:45pm

Copy link

vercel bot commented Dec 28, 2023

@esadler44 is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@RomanFausek
Copy link

RomanFausek commented Feb 21, 2024

This fixes the issue of random order but breaks chapter 12 "You should see the new invoice at the top of the table." since the id is an auto-generated string.

I believe that this part of the code should be changed so it also includes time in the DB:
const date = new Date().toISOString().split('T')[0];
But I was not investigating it more deeply

@RomanFausek
Copy link

RomanFausek commented Feb 21, 2024

After some investigation, I believe that here it should be:

const date = new Date().toISOString().replace('T', ' ').slice(0, 19);

and for creating the schema we could utilize this:

date TIMESTAMP NOT NULL

The idea is to store the time too. So you would be doing something like this:

INSERT INTO invoices (customer_id, amount, status, date) 
VALUES 
  ('cc27c14a-0acf-4f4a-a6c9-d45682c144b9', 100, 'paid', '2024-02-21 15:19:18'),
  ('cc27c14a-0acf-4f4a-a6c9-d45682c144b9', 100, 'paid', '2024-02-22 16:30:00'),
  ('cc27c14a-0acf-4f4a-a6c9-d45682c144b9', 100, 'paid', '2024-02-23 14:45:30');

WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants