Skip to content

Updated dependencies and fixed compactibilty issues with nest js, also fixing Spatial Indexing#159

Open
relativity-codes wants to merge 2 commits into
cockroachdb:masterfrom
relativity-codes:master
Open

Updated dependencies and fixed compactibilty issues with nest js, also fixing Spatial Indexing#159
relativity-codes wants to merge 2 commits into
cockroachdb:masterfrom
relativity-codes:master

Conversation

@relativity-codes
Copy link
Copy Markdown

Here is a comprehensive summary of all the fixes and improvements implemented in the sequelize-cockroachdb:

1. Symlink and Require Interception (setTypeParser crash)

  • Problem: When developing/symlinking the package locally, multiple conflicting instances of Sequelize and pg were loaded, resulting in a Cannot read properties of undefined (reading 'setTypeParser') crash.
  • Fix: Added a global require interceptor hook at the top of source/index.js to ensure the same sequelize instance is shared from the parent application context, and added a robust fallback to require 'pg' directly if pg.types is missing.

2. Dependency Upgrades

  • Fix: Upgraded peer dependencies and dev dependencies in package.json to match the host application's versions (sequelize@^6.37.8 and pg@^8.21.0), ensuring complete compatibility with the latest version 6 of Sequelize.

3. Dynamic Database Engine Auto-Detection

  • Problem: Static configuration assumed the target database was always CockroachDB, breaking compatibility with standard PostgreSQL when running local development or test suites.
  • Fix: Implemented connection-time database type detection using SELECT version() AS version to dynamically check if the host contains CockroachDB. Standard PostgreSQL connection properties (like EXCEPTION support and lock modes) are now dynamically restored when not connected to a CockroachDB engine.

4. Enum Creation Patch (pgEnum)

  • Problem: ENUM creation queries crashed on CockroachDB due to unsupported standard Postgres DO ... EXCEPTION WHEN duplicate_object syntax.
  • Fix: Patched the query generator pgEnum method to dynamically output CREATE TYPE IF NOT EXISTS when connected to CockroachDB, while preserving the original DO ... EXCEPTION block when connected to PostgreSQL.

5. Spatial Index Mapping (addIndexQuery)

  • Problem: Defining indexes with type: 'SPATIAL' on spatial (GEOMETRY/GEOGRAPHY) columns generated default B-tree index queries which are rejected by both CockroachDB and PostgreSQL.
  • Fix: Patched QueryGenerator.prototype.addIndexQuery to intercept index definitions using type: 'SPATIAL' (or type: 'spatial') and automatically map them to using: 'gist' (GIST index) while omitting the unsupported type parameter.

6. Test Suite Environment Configuration

  • Problem: Test connection instances in the package's test suite hardcoded localhost credentials, meaning that running npm test completely ignored database environment variables.
  • Fix: Updated all connection helpers across the package's test suite files (tests/support.js, tests/sequelize_query_test.js, tests/dialects_query_test.js, and tests/belongs_to_many_test.js) to dynamically respect and map database environment variables (DB_NAME, DB_USER, DB_PASS, DB_HOST, DB_PORT, DB_SSL, CA_CERT_PATH), making it fully compatible with custom test databases (such as CockroachDB Cloud) while preserving default fallbacks for GitHub CI workflow.

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