Skip to content

fix: change flowsheet.play_order from serial to integer#192

Closed
jakebromberg wants to merge 4 commits intomainfrom
fix/19-play-order-type
Closed

fix: change flowsheet.play_order from serial to integer#192
jakebromberg wants to merge 4 commits intomainfrom
fix/19-play-order-type

Conversation

@jakebromberg
Copy link
Member

@jakebromberg jakebromberg commented Feb 21, 2026

Summary

  • Changed flowsheet.play_order column type from serial to integer in the Drizzle schema
  • play_order is manually managed by reorder operations and should not auto-increment; the serial type wasted a PostgreSQL sequence and could collide with manually assigned values
  • Added a schema assertion test (tests/unit/database/schema.flowsheet.test.ts) that guards against regression

Test plan

  • Schema assertion test fails before the fix (confirms serial('play_order') detected)
  • Schema assertion test passes after the fix
  • Verify existing flowsheet reorder operations still work correctly
  • No migration generated — column type change only affects the ORM layer (existing DB column is already integer with a sequence that can be dropped separately)

Fixes #19

Made with Cursor

Note: This fix is consolidated in #199 (coordinated schema migration batch). Consider closing in favor of #199.

play_order is manually managed by reorder operations and should not
auto-increment. The serial type wasted a sequence and could collide
with manually assigned values.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jakebromberg jakebromberg force-pushed the fix/19-play-order-type branch from 220a205 to 8133555 Compare February 27, 2026 05:56
Jake Bromberg added 3 commits February 27, 2026 10:46
play_order changed from serial to integer, requiring explicit values.
Add getNextPlayOrder() helper that computes max(play_order)+1 per show.
Use it in addTrack, startShow, endShow, and DJ join/leave notifications.
getNextPlayOrder() was scoped per-show (WHERE show_id = X), making
play_order values non-globally-unique. Queries use ORDER BY play_order
DESC globally, so the sequence must be monotonically increasing across
all shows to preserve correct ordering.
};

export const addTrack = async (entry: NewFSEntry): Promise<FSEntry> => {
export const addTrack = async (entry: Omit<NewFSEntry, 'play_order'> & { play_order?: number }): Promise<FSEntry> => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is unnecessary. play_order is already of type number | undefined which is equivalent to what is being created here.

@AyBruno
Copy link
Collaborator

AyBruno commented Mar 9, 2026

I'd like to discuss this one. I don't really see the need for it. Sequences are not an expensive or limited resource in our db so I don't see a "waste". It seems like we've re-implemented serial with extra network overhead here.

@jakebromberg
Copy link
Member Author

jakebromberg commented Mar 10, 2026

Closing in favor of #199 (coordinated schema migration batch), which includes this change. You're right, the max()+1 approach re-implements serial with worse concurrency semantics.

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.

Posting a new flowsheet entry results in a postgres error

2 participants