Skip to content

Feature/239 request sequence generators#244

Open
Uday-Polineni wants to merge 6 commits into
testfrom
feature/239-request-sequence-generators
Open

Feature/239 request sequence generators#244
Uday-Polineni wants to merge 6 commits into
testfrom
feature/239-request-sequence-generators

Conversation

@Uday-Polineni

Copy link
Copy Markdown

Summary

This PR implements regional request ID sequence generators for Virginia and Ireland (#239). It introduces a band-from-sequence format REQ-{band}-XXX-XXX-XXX-XXX, with each region assigned a non-overlapping sequence range so IDs stay globally unique.

Problem

The existing generate_request_id() function had the following issues:

  • Used INT for seq_id, limiting scale for Ireland’s trillion-scale range
  • No sequence bounds (NO MINVALUE, NO MAXVALUE) — ranges were not partitioned per region
  • Ireland used an unqualified nextval('request_id_seq') instead of the schema-qualified sequence name
  • No way to assign ~1 trillion IDs per region without collisions across Virginia and Ireland

Approach

New ID format:
REQ-{band}-XXX-XXX-XXX-XXX (2-digit band + four 3-digit groups)

Sequence range partitioning:

Region Band Sequence range Example first ID
Virginia 00 1999,999,999,999 REQ-00-000-000-000-001
Ireland 01 1,000,000,000,0001,999,999,999,999 REQ-01-000-000-000-000

Band-from-sequence (same function in both regions):

  • Band is derived from the sequence value: FLOOR(seq_id / 1,000,000,000,000)
  • Virginia seq_id = 1 → band 00; Ireland seq_id = 1T → band 01
  • No region-specific branching in the function — only the sequence start/range differs per region

Future-proofing (new regions / exhausted ranges):

  • Each band is a 1 trillion ID block: band NN maps to sequence values NN × 1T through (NN + 1) × 1T − 1
  • Virginia uses band 00 (01T − 1); Ireland uses band 01 (1T2T − 1)
  • If a new region is added, assign the next band — e.g. band 02 with sequence START 2,000,000,000,000, MAXVALUE 2,999,999,999,999 → IDs like REQ-02-...
  • If an existing region exhausts its range, move it to the next free band using the same pattern (033T to 4T − 1, and so on)
  • The same generate_request_id() logic applies everywhere — band is always derived from FLOOR(seq_id / 1T); only the sequence START / MINVALUE / MAXVALUE changes per region

Files changed

File Purpose
ddl/Tables/ddl_request.sql Virginia create script — sequence bounds + generate_request_id()
ddl/Tables/Scripts/ireland_dev_saayam_rdbms.sql Ireland create script — sequence bounds + generate_request_id()
ddl/ddl_changes/ddl_alter_virginia_sequence_generator.sql Virginia function change — CREATE OR REPLACE FUNCTION
ddl/ddl_changes/ddl_alter_ireland_sequence_generator.sql Ireland function change — CREATE OR REPLACE FUNCTION
script-library/tests/test_virginia_generate_request_id.sql Virginia smoke test (REQ-00-...)
script-library/tests/test_ireland_generate_request_id.sql Ireland smoke test (REQ-01-...)

Test plan

  • Deploy Virginia DDL on a test DB; run test_virginia_generate_request_id.sql — all checks return OK:
  • Deploy Ireland DDL on a test DB; run test_ireland_generate_request_id.sql — all checks return OK:
  • Smoke tests use BEGIN / ROLLBACK

Closes #239

@Uday-Polineni Uday-Polineni self-assigned this Jul 2, 2026
@Uday-Polineni
Uday-Polineni force-pushed the feature/239-request-sequence-generators branch 2 times, most recently from d1479c1 to 087851a Compare July 2, 2026 22:20
@Uday-Polineni
Uday-Polineni force-pushed the feature/239-request-sequence-generators branch from 087851a to d7f35ad Compare July 2, 2026 22:23
@Uday-Polineni
Uday-Polineni force-pushed the feature/239-request-sequence-generators branch from d7f35ad to cc22c6e Compare July 2, 2026 22:25
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