Skip to content

Conversation

@sitole
Copy link
Member

@sitole sitole commented Sep 2, 2025

The previous query was not run in a transaction, and when some builds were deleted/state changes were made later, filtering failed when accessing the array without builds.

Decided to use sqlc, so everything is now sql-native and the query runs in one transaction. Also, removing the additional part that was still using the deprecated ORM for accessing the database.

@sitole sitole self-assigned this Sep 2, 2025
@sitole sitole added the bug Something isn't working label Sep 2, 2025
@sitole sitole marked this pull request as ready for review September 2, 2025 13:10
@dobrac
Copy link
Contributor

dobrac commented Sep 2, 2025

can we still have the option to do migrate/down? I use it quite extensively for development

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Role and Function Creation Fails on Existing Entries

The setupAuthSchema function unconditionally attempts to create the authenticated role and auth.uid() function. Since the existence check only applies to the auth.users table, the migration can fail if the role or function already exist from a previous attempt or an inconsistent state.

packages/db/scripts/migrator.go#L124-L147

// Create authenticated user
_, err = db.Exec("CREATE ROLE authenticated;")
if err != nil {
return err
}
// Create users table
_, err = db.Exec(
`CREATE TABLE IF NOT EXISTS auth.users (id uuid NOT NULL DEFAULT gen_random_uuid(),email text NOT NULL, PRIMARY KEY (id));`)
if err != nil {
return err
}
// Create function to generate a random uuid
_, err = db.Exec(
`CREATE FUNCTION auth.uid() RETURNS uuid AS $func$
BEGIN
RETURN gen_random_uuid();
END;
$func$ LANGUAGE plpgsql;`)
if err != nil {
return err
}

Fix in Cursor Fix in Web


@jakubno jakubno merged commit a35fa93 into main Sep 2, 2025
26 checks passed
@jakubno jakubno deleted the fix/panic-when-build-not-found branch September 2, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants