Skip to content

Conversation

@Yopi
Copy link
Contributor

@Yopi Yopi commented Oct 21, 2025

📋 Summary

Related Issue: Fixes #6994

Switch to a Polar global invoice sequence instead of a per organization invoice sequence.

By utilizing postgres SEQUENCE we can ensure that we will get a forever incrementing sequence for invoice numbers, that can be used by all organizations.

During a rollback the number will not get reused, but as long as each organization has a strictly increasing number sequence it should be legally OK.

🎯 What

  • Adds a SEQUENCE for invoice numbers
  • Uses the sequence for get_next_invoice_number.

🤔 Why

To avoid leaking volume information for a specific merchant, we want to have another invoice identifier.

🔧 How

🧪 Testing

  • I have tested these changes locally
  • All existing tests pass (uv run task test for backend, pnpm test for frontend)
  • I have added new tests for new functionality
  • I have run linting and type checking (uv run task lint && uv run task lint_types for backend)

Test Instructions

🖼️ Screenshots/Recordings

📝 Additional Notes

✅ Pre-submission Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code where necessary
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have updated the relevant tests
  • All tests pass locally
  • AI/LLM Policy: If I used AI assistance, I have tested and executed the code locally (not just "vibe-coded")

By utilizing postgres SEQUENCE we can ensure that we will get a forever incrementing
sequence for invoice numbers, that can be used by all organizations.

During a rollback the number will not get reused, but as long as each organization
has a strictly increasing number sequence it should be legally OK.
@vercel
Copy link

vercel bot commented Oct 21, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
polar Ignored Ignored Oct 21, 2025 2:05pm
polar-sandbox Ignored Ignored Oct 21, 2025 2:05pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

f"""
SELECT setval('invoice_number_seq',
COALESCE(
(SELECT MAX(CAST(SPLIT_PART(invoice_number, '-', 2) AS INTEGER))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could just do SELECT COUNT(*) FROM orders and start there?

@Yopi Yopi closed this Oct 24, 2025
@Yopi
Copy link
Contributor Author

Yopi commented Oct 24, 2025

Alternative approach: #7460

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.

Randomize the invoice order number

3 participants