New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add Cockroachdb support without transactions #16394
Open
divye11
wants to merge
124
commits into
sequelize:main
Choose a base branch
from
divye11:cockroachdb-support-without-transactions
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
124 commits
Select commit
Hold shift + click to select a range
458bf3a
initial commit
divye11 2fbdddd
updated docker compose to build a single cluster with proper exposed …
divye11 a6cee3a
Merge branch 'sequelize:main' into main
divye11 ad7f647
Merge branch 'sequelize:main' into main
divye11 28c7c1a
updated data types, connection manager, and query generator to inheri…
divye11 7589ecd
Merge branch 'main' of github.com:divye11/sequelize-cockroachdb
divye11 5719cb3
Merge branch 'sequelize:main' into main
divye11 9686cdb
updated query, query generator, types, query interface and added supp…
divye11 203e3ca
Merge branch 'main' of https://github.com/sequelize/sequelize
divye11 e05df1f
Merge branch 'sequelize:main' into main
divye11 3187642
changed file structure
divye11 8eee4a4
Merge branch 'sequelize:main' into main
divye11 b0ca8d5
removed outdated files. removed .d.ts files, migrated to TS for each …
divye11 5432da2
Merge branch 'main' of github.com:divye11/sequelize-cockroachdb
divye11 a0a02e5
linter fix
divye11 d32dda7
Merge branch 'sequelize:main' into main
divye11 5caa5f4
linter fix
divye11 335ddfe
added config variables
divye11 aa92184
Merge branch 'sequelize:main' into main
divye11 848beb7
merged main from upstream
divye11 fb69929
Merge branch 'sequelize:main' into main
divye11 4131a92
improved overrides, imports, exports. added a linter rule in inner es…
divye11 5f1c3ce
removed linting fixes
divye11 0969c83
merged main into divye11:main
divye11 bb1c975
updated few test configs to add crdb ports, reverted a import/order c…
divye11 63a72f0
Merge branch 'main' of github.com:sequelize/sequelize
divye11 379d476
Merge branch 'main' of github.com:sequelize/sequelize
divye11 415c5ea
reverted a few changes, removed array definition for crdb data type
divye11 eaac9d6
linter fix
divye11 4a24e83
build fix
divye11 d2f6923
Merge branch 'main' of github.com:sequelize/sequelize
divye11 b54c111
updated some tests to include cockroachdb as a dialect
divye11 38019d2
Merge branch 'main' of github.com:sequelize/sequelize
divye11 77dcedf
fix failing tests and updated expectations for unit tests
divye11 383f60b
Merge branch 'main' of github.com:sequelize/sequelize
divye11 df562f1
fixed a few unit tests, added query and connection manager definition…
divye11 4cc3361
fix failing tests
divye11 e20918e
added CI tests for cockraochdb, modified a few parameters, organized …
divye11 edbc389
fixed tests
divye11 9e2f03e
fixed linting errors
divye11 62658e9
Merge branch 'sequelize:main' into main
divye11 23fd4c1
fixed test failing for postgres due to previous change
divye11 25cce0d
fix failing tests
divye11 9f8c776
fix failing tests
divye11 973a465
removed container modifications
divye11 ec9016a
modified docker container
divye11 7dd6975
added integration tests to CI for CRDB
divye11 c561916
Merge branch 'main' of https://github.com/sequelize/sequelize
divye11 3ae9812
removing linter issues from source files
divye11 9bafaad
altered data types
divye11 fb5fd15
addressed a few review comments by reusing code
divye11 6adc4c7
removed connection manager
divye11 873c01d
addressed a few review comments and added the latest as well as oldes…
divye11 6e60f12
removed a file
divye11 daaffb1
changed a few tests, modified a few files, added query definition for…
divye11 820291c
merged main from upstream and modified mixin tests
divye11 486912c
added a few comments, uncommented and modified a few tests to work wi…
divye11 6ae87a9
Merge branch 'main' of https://github.com/sequelize/sequelize
divye11 9c813bb
commented a test since oly top orderby are considered
divye11 bc5a0ed
modified failing test
divye11 44444df
Revert "modified failing test"
divye11 05751c8
modified failing test
divye11 7e22c83
fixed a few linting issues
divye11 5320c56
fixed a failing test
divye11 0af35e6
meta: updated with main, and changed index queries to accomodate new …
divye11 18cb576
Merge branch 'main' of github.com:sequelize/sequelize
divye11 7adf597
removed test file
divye11 2da7559
meta: merged upstream main
divye11 60434cd
fix: imported individual methods from lodash
divye11 cbec4c2
Merge branch 'main' of github.com:sequelize/sequelize
divye11 38ae69a
fix: failing tests for cockroachdb:latest
divye11 cec92a7
fix: failing timestamp test for cockroachdb
divye11 1db9cc9
Merge branch 'main' of github.com:sequelize/sequelize
divye11 d1a5446
Merge branch 'main' into main
divye11 dbb5b09
Merge branch 'main' of github.com:divye11/sequelize-cockroachdb
divye11 8c94ddc
fix: reverted yarn lock changes
divye11 28a8578
Merge branch 'main' of github.com:sequelize/sequelize
divye11 5180503
fix: updated query to parse fields properly, skipped a test which doe…
divye11 d5e7895
Merge branch 'main' of github.com:sequelize/sequelize
divye11 bc04f94
fix: added a fix for cockroachdb expectations
divye11 c4221fd
meta: merged main into fork
divye11 805ad93
fix: updated latest and oldest versions for Cockroachdb tests
divye11 dfddbde
Merge branch 'main' into main
divye11 bdf9d55
Merge branch 'main' into main
divye11 aa8c069
fix: lint fixes
divye11 fe01a8f
Merge branch 'main' of github.com:sequelize/sequelize
divye11 e3f13e1
Merge branch 'main' of github.com:sequelize/sequelize
divye11 a11833e
fix: mysql failing test
divye11 9ed6c83
fix: failing tests for postgres
divye11 7ab1100
fix: failing postgres tests
divye11 0ff0ad9
fix: failing cockroachdb tests
divye11 d165fa2
Merge branch 'main' into main
divye11 d19a8f6
fix: failing cockroachdb tests
divye11 a7fe539
fix: versioning in CRDB test
divye11 6d71fb6
Merge branch 'main' into main
divye11 06599a5
Merge branch 'main' into main
divye11 7d0d22e
meta: updated the contributing docs
divye11 4349c9e
fix: empty commit to reset nx cache
divye11 7e7b109
Merge branch 'main' into main
divye11 53d776f
meta: fixed docs and rese4t nx cache
divye11 b3179a0
Merge branch 'main' of github.com:divye11/sequelize-cockroachdb
divye11 678f110
Merge branch 'main' into main
divye11 3bdbaf7
Merge branch 'main' of github.com:sequelize/sequelize into cockroachd…
divye11 fd3692e
fix: turned off transactions for Cockroachdb to make a smaller PR
divye11 e663bc0
meta: changed comment
divye11 1ec03e4
meta: changed comment
divye11 e2beef3
meta: updated nx cache
divye11 fcd8b9b
added a comment for the unique parsing for int8 in cockroachdb
divye11 abf412b
fix: resolve wsay fixes for review comments
divye11 7db6d8b
meta: merged upstream mai
divye11 c26e6ab
fix: fixed conflicts
divye11 39dd7a7
Merge branch 'main' into cockroachdb-support-without-transactions
divye11 adee21f
Merge branch 'main' of github.com:sequelize/sequelize into cockroachd…
divye11 23d33e8
changed enum storage procedure
divye11 1f78847
Merge branch 'cockroachdb-support-without-transactions' of github.com…
divye11 f669df1
Merge branch 'main' into cockroachdb-support-without-transactions
divye11 e022e64
fix: merged upstream main and resolved conflicts
divye11 2b1003f
Merge branch 'cockroachdb-support-without-transactions' of github.com…
divye11 f7a8507
fix: merged upstream main and resolved conflicts
divye11 5226fe8
Merge branch 'main' into cockroachdb-support-without-transactions
divye11 6eb1b18
fix: UT fix for uuid
divye11 5255738
merged upstream main into origin main
divye11 66dea65
Merge branch 'main' into cockroachdb-support-without-transactions
divye11 ef9a12b
Merge branch 'main' into cockroachdb-support-without-transactions
divye11 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,5 +36,6 @@ jobs: | |
snowflake | ||
sqlite | ||
types | ||
cockroachdb | ||
ignoreLabels: | | ||
ignore-semantic-pull-request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
services: | ||
cockroachdb-latest: | ||
container_name: sequelize-cockroachdb-latest | ||
image: cockroachdb/cockroach:v23.1.14 | ||
ports: | ||
- 26257:26257 | ||
- 8080:8080 | ||
command: start-single-node --cluster-name=cockroach-sequelize-example --advertise-addr='localhost' --insecure | ||
environment: | ||
COCKROACH_DATABASE: public | ||
volumes: | ||
- cockroach-single:/cockroach/cockroach-data | ||
- ~/init-scripts:/docker-entrypoint-initdb.d | ||
healthcheck: | ||
test: curl --fail http://localhost:8080 || exit 1 | ||
interval: 3s | ||
timeout: 1s | ||
retries: 10 | ||
networks: | ||
default: | ||
name: sequelize-cockroachdb-latest-network | ||
volumes: | ||
cockroach-single: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||||||
#!/usr/bin/env bash | ||||||||||
set -Eeuxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ | ||||||||||
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" # https://stackoverflow.com/a/17744637 | ||||||||||
|
||||||||||
docker compose -p sequelize-cockroachdb-latest down --remove-orphans | ||||||||||
docker compose -p sequelize-cockroachdb-latest up -d | ||||||||||
|
||||||||||
./../../wait-until-healthy.sh sequelize-cockroachdb-latest | ||||||||||
|
||||||||||
# Optimising the single node cluster | ||||||||||
# Read more here https://cockroachlabs.com/docs/stable/local-testing.html#use-a-local-single-node-cluster-with-in-memory-storage | ||||||||||
docker exec sequelize-cockroachdb-latest ./cockroach sql --insecure --execute=" | ||||||||||
SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = true; | ||||||||||
SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms'; | ||||||||||
SET CLUSTER SETTING jobs.registry.interval.gc = '30s'; | ||||||||||
SET CLUSTER SETTING jobs.registry.interval.cancel = '180s'; | ||||||||||
SET CLUSTER SETTING jobs.retention_time = '15s'; | ||||||||||
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false; | ||||||||||
SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s'; | ||||||||||
ALTER RANGE default CONFIGURE ZONE USING "gc.ttlseconds" = 600; | ||||||||||
ALTER DATABASE system CONFIGURE ZONE USING "gc.ttlseconds" = 600; | ||||||||||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
DROP DATABASE IF EXISTS sequelize_test; | ||||||||||
CREATE DATABASE IF NOT EXISTS sequelize_test; | ||||||||||
CREATE USER IF NOT EXISTS sequelize_test; | ||||||||||
GRANT admin TO sequelize_test;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ | ||
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" # https://stackoverflow.com/a/17744637 | ||
|
||
docker compose -p sequelize-cockroachdb-latest down --remove-orphans | ||
|
||
echo "Cockroach db cluster stopped" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
services: | ||
cockroachdb-oldest: | ||
container_name: sequelize-cockroachdb-oldest | ||
image: cockroachdb/cockroach:v22.2.0 | ||
ports: | ||
- 26257:26257 | ||
- 8080:8080 | ||
command: start-single-node --cluster-name=cockroach-sequelize-example --advertise-addr='localhost' --insecure | ||
environment: | ||
COCKROACH_DATABASE: public | ||
volumes: | ||
- cockroach-single:/cockroach/cockroach-data-oldest | ||
- ~/init-scripts:/docker-entrypoint-initdb.d | ||
healthcheck: | ||
test: curl --fail http://localhost:8080 || exit 1 | ||
interval: 3s | ||
timeout: 1s | ||
retries: 10 | ||
networks: | ||
default: | ||
name: sequelize-cockroachdb-oldest-network | ||
volumes: | ||
cockroach-single: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||||||
#!/usr/bin/env bash | ||||||||||
set -Eeuxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ | ||||||||||
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" # https://stackoverflow.com/a/17744637 | ||||||||||
|
||||||||||
docker compose -p sequelize-cockroachdb-oldest down --remove-orphans | ||||||||||
docker compose -p sequelize-cockroachdb-oldest up -d | ||||||||||
|
||||||||||
./../../wait-until-healthy.sh sequelize-cockroachdb-oldest | ||||||||||
|
||||||||||
# Optimising the single node cluster | ||||||||||
# Read more here https://cockroachlabs.com/docs/stable/local-testing.html#use-a-local-single-node-cluster-with-in-memory-storage | ||||||||||
docker exec sequelize-cockroachdb-oldest ./cockroach sql --insecure --execute=" | ||||||||||
SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = true; | ||||||||||
SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms'; | ||||||||||
SET CLUSTER SETTING jobs.registry.interval.gc = '30s'; | ||||||||||
SET CLUSTER SETTING jobs.registry.interval.cancel = '180s'; | ||||||||||
SET CLUSTER SETTING jobs.retention_time = '15s'; | ||||||||||
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false; | ||||||||||
SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s'; | ||||||||||
ALTER RANGE default CONFIGURE ZONE USING "gc.ttlseconds" = 600; | ||||||||||
ALTER DATABASE system CONFIGURE ZONE USING "gc.ttlseconds" = 600; | ||||||||||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
DROP DATABASE IF EXISTS sequelize_test; | ||||||||||
CREATE DATABASE IF NOT EXISTS sequelize_test; | ||||||||||
CREATE USER IF NOT EXISTS sequelize_test; | ||||||||||
GRANT admin TO sequelize_test;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ | ||
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" # https://stackoverflow.com/a/17744637 | ||
|
||
docker compose -p sequelize-cockroachdb-oldest down --remove-orphans | ||
|
||
echo "Cockroach db cluster stopped" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PostgresConnectionManager } from '../postgres/connection-manager'; | ||
|
||
export class CockroachdbConnectionManager extends PostgresConnectionManager {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import assert from 'node:assert'; | ||
import wkx from 'wkx'; | ||
import * as BaseTypes from '../abstract/data-types'; | ||
import { getDataTypeParser } from '../abstract/data-types-utils'; | ||
import { buildRangeParser } from '../postgres/range'; | ||
import type { CockroachDbDialect } from './index'; | ||
|
||
export function registerCockroachDbDataTypeParsers(dialect: CockroachDbDialect) { | ||
// dateonly | ||
dialect.registerDataTypeParser(['date'], (value: unknown) => { | ||
return value; | ||
}); | ||
|
||
dialect.registerDataTypeParser(['timestamptz', 'timestamp'], (value: unknown) => { | ||
// override default parser to prevent returning a Date object (which is the default behavior in pg). | ||
// return dates as string, not Date objects. Different implementations could be used instead (such as Temporal, dayjs) | ||
return value; | ||
}); | ||
|
||
dialect.registerDataTypeParser(['decimal', 'numeric'], (value: string) => { | ||
if (value === null) { | ||
return null; | ||
} | ||
|
||
if (value === 'NaN') { | ||
return Number.NaN; | ||
} | ||
|
||
return value; | ||
}); | ||
|
||
/** | ||
* Cockroachdb's ALIAS for INTEGER and BIGINT defaults to int(64-bit value). So while retreiving the values from the database both values are | ||
* returned as int8. While parsing them we cannot be sure if the expected behavior is of INTEGER or BIGINT so we make sure if the number is | ||
* < than Number.MAX_SAFE_INTEGER --> Parse it as a number | ||
* > than Number.MAX_SAFE_INTEGER --> Parse it as a string | ||
* Note: Storing INTEGERS as INT4 and BIGINT as int8 would result in an anti-pattern since Cockroachdb uses unique_row_id() to generate a unique ID for | ||
* each row by default to ensure global uniqueness, reseliency and consistency. | ||
*/ | ||
dialect.registerDataTypeParser(['int8'], (value: string) => { | ||
if (value === null) { | ||
return null; | ||
} | ||
|
||
const parsedValue = BigInt(value); | ||
|
||
if (parsedValue > Number.MAX_SAFE_INTEGER || parsedValue < Number.MIN_SAFE_INTEGER) { | ||
return String(value); | ||
} else if (Number(value) >= Number.MIN_SAFE_INTEGER) { | ||
return Number(value); | ||
} | ||
|
||
return String(value); | ||
|
||
}); | ||
|
||
dialect.registerDataTypeParser(['geography'], (value: unknown) => { | ||
assert(typeof value === 'string', 'Expected geography value to be a string'); | ||
|
||
const b = Buffer.from(value, 'hex'); | ||
|
||
return wkx.Geometry.parse(b).toGeoJSON({ shortCrs: true }); | ||
}); | ||
|
||
dialect.registerDataTypeParser(['geometry'], (value: unknown) => { | ||
assert(typeof value === 'string', 'Expected geometry value to be a string'); | ||
|
||
const b = Buffer.from(value, 'hex'); | ||
|
||
return wkx.Geometry.parse(b).toGeoJSON({ shortCrs: true }); | ||
}); | ||
|
||
const parseInteger = getDataTypeParser(dialect, BaseTypes.INTEGER); | ||
dialect.registerDataTypeParser(['int4range'], buildRangeParser(parseInteger)); | ||
|
||
const parseBigInt = getDataTypeParser(dialect, BaseTypes.BIGINT); | ||
dialect.registerDataTypeParser(['int8range'], buildRangeParser(parseBigInt)); | ||
|
||
const parseDecimal = getDataTypeParser(dialect, BaseTypes.DECIMAL); | ||
dialect.registerDataTypeParser(['numrange'], buildRangeParser(parseDecimal)); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be added to the scopes in .github/workflows/pr-title.yml as well