Skip to content

fix(db/auth): resolve migration syntax errors and refactor initialization#716

Merged
CodeWithCJ merged 2 commits intomainfrom
dev
Feb 22, 2026
Merged

fix(db/auth): resolve migration syntax errors and refactor initialization#716
CodeWithCJ merged 2 commits intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
Owner

  • Fix "zero-length delimited identifier" error by correctly quoting database identifiers.
  • Defer Better Auth SSO provider sync until after migrations and RLS policies are applied to prevent race conditions.
  • Ensure stable server startup sequence by resolving scoping issues in SparkyFitnessServer.js.
  • Add comprehensive documentation for external PostgreSQL setup, including security hardening and maintainer disclaimers.

…tion order

- Fix "zero-length delimited identifier" error by correctly quoting database identifiers.
- Defer Better Auth SSO provider sync until after migrations and RLS policies are applied to prevent race conditions.
- Ensure stable server startup sequence by resolving scoping issues in SparkyFitnessServer.js.
- Add comprehensive documentation for external PostgreSQL setup, including security hardening and maintainer disclaimers.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @CodeWithCJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the robustness and clarity of the application's database and authentication initialization. It addresses critical issues related to database identifier handling and the timing of SSO provider synchronization, which previously led to startup failures and race conditions. Additionally, it provides essential guidance for users deploying the application with external PostgreSQL instances, improving the overall maintainability and deployability of the system.

Highlights

  • Database Identifier Quoting Fix: Resolved 'zero-length delimited identifier' errors by ensuring database identifiers are correctly quoted in SQL queries, particularly for application user roles.
  • Deferred SSO Provider Synchronization: Modified the server startup sequence to defer the synchronization of Better Auth SSO providers until after all database migrations and Row Level Security (RLS) policies have been successfully applied, preventing potential race conditions.
  • Refactored Server Initialization Logic: Adjusted the SparkyFitnessServer.js file to correctly scope and manage the syncTrustedProviders function, ensuring a more stable and predictable server startup process.
  • External PostgreSQL Documentation: Added detailed documentation for setting up and configuring an external PostgreSQL database, including steps for user creation, extension installation, RLS considerations, and security hardening best practices.
Changelog
  • SparkyFitnessServer/SparkyFitnessServer.js
    • Extracted syncTrustedProviders from the auth module and assigned it to a globally scoped variable to allow deferred execution.
    • Modified the applyMigrations promise chain to call syncTrustedProviders after applyRlsPolicies, ensuring SSO providers are synced only after the database is fully prepared.
  • SparkyFitnessServer/auth.js
    • Commented out the immediate invocation of syncTrustedProviders on startup, deferring its execution to the main server initialization flow.
    • Applied minor formatting adjustments (indentation) to the authPool configuration and cleanupSessions function for consistency.
  • SparkyFitnessServer/db/grantPermissions.js
    • Updated SQL queries to correctly handle and quote the application database user, resolving potential 'zero-length delimited identifier' errors.
  • SparkyFitnessServer/utils/dbMigrations.js
    • Refactored the handling of the application user role during creation, using separate raw and quoted variables to ensure correct SQL syntax.
    • Moved the grantPermissions() call to execute after all database migrations are applied, ensuring permissions are set on a fully established schema.
  • docs/content/1.install/5.external-database.md
    • Added a new documentation file detailing the setup process for external PostgreSQL databases, covering user/database creation, extension requirements, RLS, environment configuration, and security hardening.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves critical database migration and application startup issues. The fixes for SQL identifier quoting in grantPermissions.js and dbMigrations.js are correct and address the "zero-length delimited identifier" error. Refactoring the startup sequence to defer the SSO provider sync in SparkyFitnessServer.js is a solid improvement that prevents race conditions. Additionally, the new documentation for external PostgreSQL setup is comprehensive and a valuable addition for users. While reviewing the changes, I identified a pre-existing critical issue in auth.js where duplicate configuration keys would cause session settings to be ignored, and I've provided a comment with a suggested fix. Overall, these changes significantly improve the robustness and stability of the application's initialization process.

@CodeWithCJ CodeWithCJ merged commit e764cc1 into main Feb 22, 2026
7 checks passed
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.

1 participant