Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Extends database support from MySQL-only to PostgreSQL and SQLite while maintaining full backward compatibility. Implements a driver abstraction layer allowing users to switch databases via configuration.

Implementation

Driver Abstraction

  • BaseSqlDriver: Interface defining common operations (connect, query, findUser, etc.)
  • SqlDriverFactory: Creates appropriate driver based on SQL_DRIVER config
  • Automatic placeholder conversion (?$1, $2 for PostgreSQL)
  • Custom query support via SQL_QUERY_* environment variables

Drivers

  • MySQLDriver: Refactored existing implementation to extend base class
  • PostgreSQLDriver: JSONB support with ? operator for array membership
  • SQLiteDriver: JSON1 extension for JSON operations

Generic Backends

  • sql.auth.js / sql.directory.js: Dialect-agnostic backends using factory pattern
  • Legacy mysql.auth.js / mysql.directory.js unchanged for rollback safety

Configuration

# New unified configuration
SQL_DRIVER=postgresql          # mysql | postgresql | sqlite
SQL_HOST=localhost
SQL_PORT=5432
SQL_DATABASE=ldap_db

# Legacy MYSQL_* variables still work
MYSQL_HOST=localhost           # Backward compatible

Migration

Existing deployments continue working unchanged. To use new backend:

- AUTH_BACKENDS=mysql
+ AUTH_BACKENDS=sql
+ SQL_DRIVER=mysql
  MYSQL_HOST=localhost          # Still supported

Rollback requires only reverting backend name.

Schema

Identical logical schema across all dialects. Initialization scripts provided for each:

  • MySQL: docker/sql/init.sql
  • PostgreSQL: docker/sql/init-postgresql.sql
  • SQLite: docker/sql/init-sqlite.sql

Testing

  • 29 unit tests covering driver abstraction and factory
  • 3 integration tests for connectivity
  • CodeQL: 0 vulnerabilities
Original prompt

This section details on the original issue you should resolve

<issue_title>Support Multiple SQL Dialects</issue_title>
<issue_description>We are looking to support SQLite3 and PostgreSQL in addition to MySQL. I would like to accomplish this by refitting the MySQL Directory and Authentication backends to be more generically named SQL (ie. SQL_HOST, SQL_USER, SQL_DATABASE, SQL_PASSWORD, SQL_SCHEMA etc). We then need an abstraction layer to select the right database driver for the configured SQL_DRIVER. The user could then supply the required SQL queries as additional configuration parameters.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 6 commits November 18, 2025 19:32
Co-authored-by: runleveldev <44057501+runleveldev@users.noreply.github.com>
Co-authored-by: runleveldev <44057501+runleveldev@users.noreply.github.com>
Co-authored-by: runleveldev <44057501+runleveldev@users.noreply.github.com>
Co-authored-by: runleveldev <44057501+runleveldev@users.noreply.github.com>
Co-authored-by: runleveldev <44057501+runleveldev@users.noreply.github.com>
Copilot AI changed the title [WIP] Support multiple SQL dialects including SQLite3 and PostgreSQL Add PostgreSQL and SQLite support via unified SQL backend Nov 18, 2025
Copilot AI requested a review from runleveldev November 18, 2025 19:52
@runleveldev
Copy link
Contributor

implemented in #104

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.

Support Multiple SQL Dialects

2 participants