Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 28 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ on: [push, pull_request]
jobs:
test:
# Execute our own tests
name: Main - CRDB ${{ matrix.cockroachdb-docker-version }}, Sequelize v${{ matrix.sequelize-version }}
name: Main - CRDB ${{ matrix.cockroachdb-docker-version }}
strategy:
matrix:
# TODO(richardjcai): Re-enable tests for v5 after we get v6 suite passing.
# Focus on getting tests passing for v6 test suite.
sequelize-version: [5, 6]
cockroachdb-docker-version: ["cockroachdb/cockroach:v21.2.4", "cockroachdb/cockroach:v21.1.13"]
# Test the regular (non-innovation) releases that are still supported.
cockroachdb-docker-version:
- "cockroachdb/cockroach:latest-v24.3"
- "cockroachdb/cockroach:latest-v25.2"
- "cockroachdb/cockroach:latest-v25.4"
- "cockroachdb/cockroach:latest-v26.2"
fail-fast: false
runs-on: ubuntu-latest
steps:
Expand All @@ -34,44 +36,34 @@ jobs:
run: |
echo $CONTAINER_ENTRYPOINT
docker pull ${{ matrix.cockroachdb-docker-version }}
docker run -d --name roach --hostname roach -p 26257:26257 -p 8080:8080 ${{ matrix.cockroachdb-docker-version }} start-single-node --insecure
docker run -d --name roach --hostname roach -p 26257:26257 -p 8080:8080 ${{ matrix.cockroachdb-docker-version }} start-single-node --insecure --store=type=mem,size=2GiB
sudo apt update && sudo apt install wait-for-it -y
wait-for-it -h localhost -p 26257
docker exec roach bash -c "echo 'CREATE DATABASE sequelize_test;' | $CONTAINER_ENTRYPOINT sql --insecure"
docker exec roach $CONTAINER_ENTRYPOINT sql --insecure -e "SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false" -e "SET CLUSTER SETTING kv.range_merge.queue.enabled = false" -e "SET CLUSTER SETTING diagnostics.reporting.enabled = false" -e "CREATE DATABASE sequelize_test"

- name: Checkout the repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Node.js 12.x
uses: actions/setup-node@v1
- name: Setup Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 12.x
node-version: 22.x

- name: Install dependencies
run: npm install

- name: Install Sequelize v${{ matrix.sequelize-version }}
run: npm install --save sequelize@^${{ matrix.sequelize-version }}

- name: Run tests
run: npm test --crdb_version=${{ matrix.cockroachdb-docker-version }}

sequelize-postgres-integration-tests:
# Execute Sequelize integration tests for postgres
# This one will spawn 219 jobs
# This one will spawn 110 jobs
if: ${{ !endsWith(github.event.head_commit.message, '[[skip sequelize integration tests]]') }}
name: (${{ matrix.sequelize-branch }}) ${{ matrix.test-path }}
strategy:
matrix:
# TODO(richardjcai): Re-enable tests for v5 after we get v6 suite passing.
# Focus on getting tests passing for v6 test suite.
sequelize-branch: [v5, v6]
test-path: [associations/alias, associations/belongs-to-many, associations/belongs-to, associations/has-many, associations/has-one, associations/multiple-level-filters, associations/scope, associations/self, cls, configuration, data-types, dialects/abstract/connection-manager, dialects/postgres/associations, dialects/postgres/connection-manager, dialects/postgres/dao, dialects/postgres/data-types, dialects/postgres/error, dialects/postgres/hstore, dialects/postgres/query-interface, dialects/postgres/query, dialects/postgres/range, dialects/postgres/regressions, error, hooks/associations, hooks/bulkOperation, hooks/count, hooks/create, hooks/destroy, hooks/find, hooks/hooks, hooks/restore, hooks/updateAttributes, hooks/upsert, hooks/validate, include/findAll, include/findAndCountAll, include/findOne, include/limit, include/paranoid, include/schema, include/separate, include, instance/decrement, instance/destroy, instance/increment, instance/reload, instance/save, instance/to-json, instance/update, instance/values, instance, instance.validations, json, model/attributes/field, model/attributes/types, model/attributes, model/bulk-create/include, model/bulk-create, model/count, model/create/include, model/create, model/findAll/group, model/findAll/groupedLimit, model/findAll/order, model/findAll/separate, model/findAll, model/findOne, model/findOrBuild, model/geography, model/geometry, model/increment, model/json, model/optimistic_locking, model/paranoid, model/schema, model/scope/aggregate, model/scope/associations, model/scope/count, model/scope/destroy, model/scope/find, model/scope/findAndCountAll, model/scope/merge, model/scope/update, model/scope, model/searchPath, model/sum, model/sync, model/update, model/upsert, model, operators, pool, query-interface/changeColumn, query-interface/createTable, query-interface/describeTable, query-interface/dropEnum, query-interface/removeColumn, query-interface, replication, schema, sequelize/deferrable, sequelize/log, sequelize, sequelize.transaction, timezone, transaction, trigger, utils, vectors]
include:
-
# Luckily the test files are the same in v5 and v6, except for one extra file in v6:
sequelize-branch: v6
test-path: sequelize/query
sequelize-branch: [v6]
test-path: [associations/alias, associations/belongs-to-many, associations/belongs-to, associations/has-many, associations/has-one, associations/multiple-level-filters, associations/scope, associations/self, cls, configuration, data-types, dialects/abstract/connection-manager, dialects/postgres/associations, dialects/postgres/connection-manager, dialects/postgres/dao, dialects/postgres/data-types, dialects/postgres/error, dialects/postgres/hstore, dialects/postgres/query-interface, dialects/postgres/query, dialects/postgres/range, dialects/postgres/regressions, error, hooks/associations, hooks/bulkOperation, hooks/count, hooks/create, hooks/destroy, hooks/find, hooks/hooks, hooks/restore, hooks/updateAttributes, hooks/upsert, hooks/validate, include/findAll, include/findAndCountAll, include/findOne, include/limit, include/paranoid, include/schema, include/separate, include, instance/decrement, instance/destroy, instance/increment, instance/reload, instance/save, instance/to-json, instance/update, instance/values, instance, instance.validations, json, model/attributes/field, model/attributes/types, model/attributes, model/bulk-create/include, model/bulk-create, model/count, model/create/include, model/create, model/findAll/group, model/findAll/groupedLimit, model/findAll/order, model/findAll/separate, model/findAll, model/findOne, model/findOrBuild, model/geography, model/geometry, model/increment, model/json, model/optimistic_locking, model/paranoid, model/schema, model/scope/aggregate, model/scope/associations, model/scope/count, model/scope/destroy, model/scope/find, model/scope/findAndCountAll, model/scope/merge, model/scope/update, model/scope, model/searchPath, model/sum, model/sync, model/update, model/upsert, model, operators, pool, query-interface/changeColumn, query-interface/createTable, query-interface/describeTable, query-interface/dropEnum, query-interface/removeColumn, query-interface, replication, schema, sequelize/deferrable, sequelize/log, sequelize, sequelize.transaction, sequelize/query, timezone, transaction, trigger, utils, vectors]
fail-fast: false
runs-on: ubuntu-latest
env:
Expand All @@ -81,21 +73,21 @@ jobs:
SEQ_PW: ''
SEQ_DB: sequelize_test
steps:
- name: Start a single CockroachDB instance (v21.2.4) with docker
- name: Start a single CockroachDB instance (latest-v26.2) with docker
run: |
docker pull cockroachdb/cockroach:v21.2.4
docker run -d --name roach --hostname roach -p 26257:26257 -p 8080:8080 cockroachdb/cockroach:v21.2.4 start-single-node --insecure
docker pull cockroachdb/cockroach:latest-v26.2
docker run -d --name roach --hostname roach -p 26257:26257 -p 8080:8080 cockroachdb/cockroach:latest-v26.2 start-single-node --insecure --store=type=mem,size=2GiB
sudo apt update && sudo apt install wait-for-it -y
wait-for-it -h localhost -p 26257
docker exec roach bash -c 'echo "CREATE DATABASE sequelize_test;" | cockroach sql --insecure'
docker exec roach cockroach sql --insecure -e "SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false" -e "SET CLUSTER SETTING kv.range_merge.queue.enabled = false" -e "SET CLUSTER SETTING diagnostics.reporting.enabled = false" -e "CREATE DATABASE sequelize_test"

- name: Checkout `sequelize-cockroachdb` repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Node.js 12.x
uses: actions/setup-node@v1
- name: Setup Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 12.x
node-version: 22.x

- name: Install `sequelize-cockroachdb` dependencies
run: npm install
Expand All @@ -107,9 +99,11 @@ jobs:
mv temp-unzip-out/* .downloaded-sequelize
rmdir temp-unzip-out

- name: Install Sequelize dependencies
- name: Install Sequelize dependencies and build Sequelize
working-directory: ./.downloaded-sequelize
run: npm install --ignore-scripts
run: |
npm install --ignore-scripts
node build.js

- name: Provide the `sequelize-cockroachdb` patches
# This script needs `fs-jetpack` as an extra dependency
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ignore_tests/shared/dialects_query.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
should throw due to alias being truncated
reuses connection after statement timeout
1 change: 1 addition & 0 deletions .github/workflows/ignore_tests/shared/has_many.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
supports schemas
should fetch associations for multiple instances with limit and order and a belongsTo relation
should ignore group from ancestor on deep separated query
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
should make the auto incremented values available on the returned instances
should make the auto incremented values available on the returned instances with custom fields
should return auto increment primary key values
should upsert existing memberships
1 change: 1 addition & 0 deletions .github/workflows/ignore_tests/shared/sync.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
should change a column if it exists in the model but is different in the database
updates the deferrable property of a foreign key
2 changes: 2 additions & 0 deletions .github/workflows/ignore_tests/shared/telemetry.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
custom logging with benchmarking has correct CLS context
executes a query with global benchmarking option and custom logger
1 change: 1 addition & 0 deletions .github/workflows/ignore_tests/shared/transactions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ supports transactions
does not try to rollback a transaction that failed upon committing with SERIALIZABLE isolation level \(#3689\)
should read the most recent committed rows when using the READ COMMITTED isolation level
supports for share \(i.e. `SELECT ... LOCK IN SHARE MODE`\)
returns a promise that resolves once the transaction has been rolled back
1 change: 0 additions & 1 deletion .github/workflows/ignore_tests/v5/create.txt

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/ignore_tests/v5/transactions.txt

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/ignore_tests/v5/upsert.txt

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.downloaded-sequelize
31 changes: 29 additions & 2 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ const PostgresDialect = require('sequelize/lib/dialects/postgres/index');
PostgresDialect.prototype.supports.EXCEPTION = false;

//// [2.1] Disable lock features support
// lockOuterJoinFailure is not supported.
PostgresDialect.prototype.supports.lockOuterJoinFailure = false;
// skipLocked is not supported.
PostgresDialect.prototype.supports.skipLocked = false;
// lockKey is not supported.
Expand Down Expand Up @@ -303,6 +301,35 @@ DataTypes.postgres.GEOGRAPHY.prototype.bindParam = (value, options) => {
return `ST_GeomFromGeoJSON(${options.bindParam(value)}::json)::geography`;
}

// [8] ENUM creation
// Newer versions of Sequelize v6 create ENUM types inside a
// `DO ... EXCEPTION WHEN duplicate_object` block to ignore types that already
// exist. CockroachDB does not support CREATE TYPE inside a function body, so
// use CREATE TYPE IF NOT EXISTS instead.
QueryGenerator.prototype.pgEnum = function (
tableName,
attr,
dataType,
options
) {
const enumName = this.pgEnumName(tableName, attr, options);
let values;

if (dataType.values) {
values = `ENUM(${dataType.values
.map(value => this.escape(value))
.join(', ')})`;
} else {
values = dataType.toString().match(/^ENUM\(.+\)/)[0];
}

let sql = `CREATE TYPE IF NOT EXISTS ${enumName} AS ${values};`;
if (!!options && options.force === true) {
sql = this.pgEnumDrop(tableName, attr) + sql;
}
return sql;
};

//// Done!

Sequelize.supportsCockroachDB = true;
Expand Down
14 changes: 14 additions & 0 deletions tests/enum_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ describe('Enum', function () {
'"C" is not a valid choice in ["A","B"]'
);
});

it('does not fail if the enum type already exists', async function () {
const queryInterface = this.sequelize.getQueryInterface();
// Sequelize v5 calls this QueryGenerator.
const queryGenerator =
queryInterface.queryGenerator || queryInterface.QueryGenerator;
const createEnum = queryGenerator.pgEnum(
'bars',
'enum',
DataTypes.ENUM('A', 'B')
);
expect(createEnum).to.include('CREATE TYPE IF NOT EXISTS');
await this.sequelize.query(createEnum);
});
});
13 changes: 0 additions & 13 deletions tests/run_tests/getTestsToIgnore.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const fs = require('fs'),
path = require('path'),
readline = require('readline');
const version_helper = require ('../../source/version_helper.js')
const semver = require('semver');

const sharedIgnoredTestsPath = './../.github/workflows/ignore_tests/shared';

Expand All @@ -28,17 +26,6 @@ function getTestNames() {
return path.join(sharedIgnoredTestsPath, f);
});

const sequelizeVersion = version_helper.GetSequelizeVersion()
if (semver.satisfies(sequelizeVersion, '<=5')) {
const v5IgnoredTestsPath = './../.github/workflows/ignore_tests/v5';
var v5files = fs.readdirSync(v5IgnoredTestsPath)
files = files.concat(
v5files.map(f => {
return path.join(v5IgnoredTestsPath, f);
})
);
}

return Promise.all(parseFilesForTests(files)).then(arr => arr.flat().join('|'))
}

Expand Down
19 changes: 12 additions & 7 deletions tests/run_tests/runTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const Mocha = require('mocha'),
getTestsToIgnore = require('./getTestsToIgnore');

async function makeMocha() {
const testsToIgnore = getTestsToIgnore();
const testsToIgnore = await getTestsToIgnore();

const mocha = new Mocha({
grep: testsToIgnore,
grep: new RegExp(testsToIgnore),
checkLeaks: true,
reporter: 'spec',
timeout: 30000,
Expand All @@ -25,8 +25,13 @@ async function makeMocha() {
}

// Run the tests.
makeMocha().then(mocha =>
mocha.run(function (failures) {
process.exit(failures ? 1 : 0); // exit with non-zero status if there were failures
})
);
makeMocha()
.then(mocha =>
mocha.run(function (failures) {
process.exit(failures ? 1 : 0); // exit with non-zero status if there were failures
})
)
.catch(err => {
console.error(err);
process.exit(1);
});
Loading