Skip to content

Commit

Permalink
Merge branch 'main' into v7
Browse files Browse the repository at this point in the history
  • Loading branch information
ephys committed Mar 15, 2023
2 parents 0110386 + 9a9a404 commit 9cfffe4
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 142 deletions.
92 changes: 7 additions & 85 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ on:
- v7
pull_request:

env:
SEQ_DB: sequelize_test
SEQ_USER: sequelize_test
SEQ_PW: sequelize_test

# This configuration cancels previous runs if a new run is started on the same PR. Only one run at a time per PR.
# This does not affect pushes to the v7 branch itself, only PRs.
# from https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-a-fallback-value
Expand Down Expand Up @@ -135,43 +130,13 @@ jobs:
- name: Install TypeScript
run: yarn workspace @sequelize/core add typescript@~${{ matrix.ts-version }}
- name: Typing Tests
run: yarn test-typings
test-db2:
strategy:
fail-fast: false
matrix:
node-version: [14, 18]
name: DB2 (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
needs: [ unit-test, test-typings ]
env:
DIALECT: db2
SEQ_DB: testdb
SEQ_USER: db2inst1
SEQ_PW: password
SEQ_TEST_CLEANUP_TIMEOUT: 1200000
SEQ_PORT: 50000
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: install-build-artifact-node-${{ matrix.node-version }}
- name: Extract artifact
run: tar -xf install-build-node-${{ matrix.node-version }}.tar
- name: Install Local DB2 Copy
run: yarn start-db2-oldest
- name: Integration Tests
run: yarn workspace @sequelize/core test-integration
run: yarn workspace @sequelize/core test-typings
test-sqlite:
strategy:
fail-fast: false
matrix:
node-version: [14, 18]
name: SQLite (Node ${{ matrix.node-version }})
name: sqlite (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
needs: [ unit-test, test-typings ]
env:
Expand All @@ -197,7 +162,7 @@ jobs:
postgres-version: [oldest, latest]
minify-aliases: [true, false]
native: [true, false]
name: Postgres ${{ matrix.postgres-version }}${{ matrix.native && ' (native)' || '' }} (Node ${{ matrix.node-version }})${{ matrix.minify-aliases && ' (minified aliases)' || '' }}
name: postgres ${{ matrix.postgres-version }}${{ matrix.native && ' (native)' || '' }} (Node ${{ matrix.node-version }})${{ matrix.minify-aliases && ' (minified aliases)' || '' }}
runs-on: ubuntu-latest
needs: [ unit-test, test-typings ]
env:
Expand All @@ -219,13 +184,13 @@ jobs:
- run: yarn start-postgres-${{ matrix.postgres-version }}
- name: Integration Tests
run: yarn workspace @sequelize/core test-integration
test-mysql-mariadb:
test-oldest-latest:
strategy:
fail-fast: false
matrix:
node-version: [14, 18]
database-version: [oldest, latest]
dialect: [mysql, mariadb]
dialect: [mysql, mariadb, mssql, db2]
name: ${{ matrix.dialect }} ${{ matrix.database-version }} (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
needs: [ unit-test, test-typings ]
Expand All @@ -245,48 +210,6 @@ jobs:
- run: yarn start-${{ matrix.dialect }}-${{ matrix.database-version }}
- name: Integration Tests
run: yarn workspace @sequelize/core test-integration
test-mssql:
strategy:
fail-fast: false
matrix:
node-version: [14, 18]
mssql-version: [2017, 2022]
name: MSSQL ${{ matrix.mssql-version }} (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
needs: [ unit-test, test-typings ]
services:
mssql:
image: mcr.microsoft.com/mssql/server:${{ matrix.mssql-version }}-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: Password12!
ports:
- 1433:1433
options: >-
--health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P \"Password12!\" -l 30 -Q \"SELECT 1\""
--health-start-period 10s
--health-interval 10s
--health-timeout 5s
--health-retries 10
env:
DIALECT: mssql
SEQ_USER: SA
SEQ_PW: Password12!
SEQ_PORT: 1433
steps:
- run: /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Password12!" -Q "CREATE DATABASE sequelize_test; ALTER DATABASE sequelize_test SET READ_COMMITTED_SNAPSHOT ON;"
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: install-build-artifact-node-${{ matrix.node-version }}
- name: Extract artifact
run: tar -xf install-build-node-${{ matrix.node-version }}.tar
- name: Integration Tests
run: yarn workspace @sequelize/core test-integration
release:
name: Release
runs-on: ubuntu-latest
Expand All @@ -295,10 +218,9 @@ jobs:
docs,
test-sqlite,
test-postgres,
test-mysql-mariadb,
test-mssql,
test-oldest-latest
]
if: github.event_name == 'push' && (github.ref == 'refs/heads/v6' || github.ref == 'refs/heads/v7')
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
File renamed without changes.
37 changes: 37 additions & 0 deletions dev/db2/latest/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/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

export DIALECT=db2
SEQ_DB="${SEQ_DB:-testdb}"
# db2 db names must be uppercase
SEQ_DB=$(echo "$SEQ_DB" | awk '{print toupper($0)}')

mkdir -p Docker
if [ ! "$(sudo docker ps -q -f name=db2server)" ]; then
if [ "$(sudo docker ps -aq -f status=exited -f name=db2server)" ];
then
# cleanup
sudo docker rm -f db2server
sudo rm -rf /Docker
fi
# TODO: use docker compose so renovate can automatically update this version
sudo docker run -h db2server --name db2server --restart=always --detach --privileged=true -p 50000:50000 --env "DBNAME=$SEQ_DB" --env-file ../.env_list -v /Docker:/database ibmcom/db2-amd64:11.5.8.0
count=1
while true
do
if (sudo docker logs db2server | grep 'Setup has completed')
then
sudo docker exec db2server bash -c "su db2inst1 & disown"
break
fi
if [ $count -gt 30 ]; then
echo "Error: Db2 docker setup has not completed in 10 minutes."
break
fi
sleep 20
let "count=count+1"
done
fi

DIALECT=db2 ts-node ../../check-connection.ts
3 changes: 3 additions & 0 deletions dev/db2/latest/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sudo docker stop db2server

echo "Local latest supported Db2 instance stopped (if it was running)."
4 changes: 1 addition & 3 deletions dev/db2/oldest/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [ ! "$(sudo docker ps -q -f name=db2server)" ]; then
sudo docker rm -f db2server
sudo rm -rf /Docker
fi
sudo docker run -h db2server --name db2server --restart=always --detach --privileged=true -p 50000:50000 --env "DBNAME=$SEQ_DB" --env-file .env_list -v /Docker:/database ibmcom/db2-amd64:11.5.7.0
sudo docker run -h db2server --name db2server --restart=always --detach --privileged=true -p 50000:50000 --env "DBNAME=$SEQ_DB" --env-file ../.env_list -v /Docker:/database ibmcom/db2-amd64:11.5.6.0a
count=1
while true
do
Expand All @@ -34,5 +34,3 @@ if [ ! "$(sudo docker ps -q -f name=db2server)" ]; then
fi

DIALECT=db2 ts-node ../../check-connection.ts

echo "Local DB2-11.5 instance is ready for Sequelize tests."
2 changes: 1 addition & 1 deletion dev/db2/oldest/stop.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sudo docker stop db2server

echo "Local Db2 instance stopped (if it was running)."
echo "Local oldest supported Db2 instance stopped (if it was running)."
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
"start-mssql-oldest": "bash dev/mssql/oldest/start.sh",
"start-mssql-latest": "bash dev/mssql/latest/start.sh",
"start-db2-oldest": "bash dev/db2/oldest/start.sh",
"start-db2-latest": "bash dev/db2/latest/start.sh",
"start-oldest": "concurrently \"npm:start-*(!db2)-oldest\" && npm run start-db2-oldest",
"start-latest": "concurrently \"npm:start-*(!db2)-latest\"",
"start-latest": "concurrently \"npm:start-*(!db2)-latest\" && npm run start-db2-latest",
"stop-mariadb": "bash dev/mariadb/oldest/stop.sh; bash dev/mariadb/latest/stop.sh",
"stop-mysql": "bash dev/mysql/oldest/stop.sh; bash dev/mysql/latest/stop.sh",
"stop-postgres": "bash dev/postgres/oldest/stop.sh; bash dev/postgres/latest/stop.sh",
"stop-mssql": "bash dev/mssql/oldest/stop.sh; bash dev/mssql/latest/stop.sh",
"stop-db2": "bash dev/db2/oldest/stop.sh",
"stop-db2": "bash dev/db2/oldest/stop.sh; bash dev/db2/latest/stop.sh",
"stop-all": "concurrently \"npm:stop-*(!all|db2)\" && npm run stop-db2",
"----------------------------------------- SSCCEs ------------------------------------------": "",
"sscce": "ts-node sscce.ts",
Expand All @@ -49,7 +50,7 @@
"chai": "4.3.7",
"esbuild": "0.17.11",
"eslint": "8.36.0",
"eslint-plugin-jsdoc": "40.0.1",
"eslint-plugin-jsdoc": "40.0.2",
"eslint-plugin-mocha": "10.1.0",
"fast-glob": "3.2.12",
"lerna": "6.5.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"dependencies": {
"@types/debug": "^4.1.7",
"@types/validator": "^13.7.5",
"bnf-parser": "^3.1.1",
"bnf-parser": "3.1.1",
"dayjs": "^1.11.5",
"debug": "^4.3.4",
"dottie": "^2.0.2",
Expand All @@ -72,7 +72,7 @@
"@types/ibm_db": "2.0.12",
"@types/lodash": "4.14.191",
"@types/mocha": "10.0.1",
"@types/node": "18.15.0",
"@types/node": "18.15.3",
"@types/pg": "8.6.6",
"@types/semver": "7.3.13",
"@types/sinon": "10.0.13",
Expand Down Expand Up @@ -104,10 +104,10 @@
"pg": "8.10.0",
"pg-hstore": "2.3.4",
"rimraf": "4.4.0",
"sinon": "15.0.1",
"sinon": "15.0.2",
"sinon-chai": "3.7.0",
"snowflake-sdk": "1.6.19",
"sqlite3": "5.1.4",
"sqlite3": "5.1.6",
"tedious": "15.1.3"
},
"peerDependenciesMeta": {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/decorators/legacy/attribute-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from './decorator-utils.js';
import {
createOptionallyParameterizedPropertyDecorator,
DECORATOR_NO_DEFAULT,
DECORATOR_NO_DEFAULT, throwMustBeAttribute,
throwMustBeInstanceProperty,
throwMustBeMethod,
} from './decorator-utils.js';
Expand Down Expand Up @@ -52,7 +52,7 @@ export function createOptionalAttributeOptionsDecorator<T>(
defaultValue,
(decoratorOption, target, propertyName, propertyDescriptor) => {
if (typeof propertyName === 'symbol') {
throw new TypeError('Symbol Model Attributes are not currently supported. We welcome a PR that implements this feature.');
throwMustBeAttribute(decoratorName, target, propertyName);
}

const attributeOptions = callback(decoratorOption, target, propertyName, propertyDescriptor);
Expand Down
77 changes: 77 additions & 0 deletions packages/core/src/decorators/legacy/built-in-attributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { ModelStatic } from '../../model.js';
import { isModelStatic } from '../../utils/model-utils.js';
import { registerModelOptions } from '../shared/model.js';
import type { OptionalParameterizedPropertyDecorator } from './decorator-utils.js';
import {
createOptionallyParameterizedPropertyDecorator,
throwMustBeAttribute, throwMustBeInstanceProperty,
throwMustBeModel,
} from './decorator-utils.js';

function createBuiltInAttributeDecorator(
decoratorName: string,
callback: (
target: ModelStatic,
propertyName: string,
) => void,
): OptionalParameterizedPropertyDecorator<undefined> {
return createOptionallyParameterizedPropertyDecorator<undefined>(
decoratorName,
undefined,
(decoratorOption, target, propertyName) => {
if (typeof target === 'function') {
throwMustBeInstanceProperty(decoratorName, target, propertyName);
}

if (!isModelStatic(target.constructor)) {
throwMustBeModel(decoratorName, target, propertyName);
}

if (typeof propertyName === 'symbol') {
throwMustBeAttribute(decoratorName, target, propertyName);
}

callback(target.constructor, propertyName);
},
);
}

export const CreatedAt = createBuiltInAttributeDecorator(
'CreatedAt',
(target: ModelStatic, propertyName: string) => {
registerModelOptions(target, {
createdAt: propertyName,
timestamps: true,
});
},
);

export const UpdatedAt = createBuiltInAttributeDecorator(
'UpdatedAt',
(target: ModelStatic, propertyName: string) => {
registerModelOptions(target, {
updatedAt: propertyName,
timestamps: true,
});
},
);

export const DeletedAt = createBuiltInAttributeDecorator(
'DeletedAt',
(target: ModelStatic, propertyName: string) => {
registerModelOptions(target, {
deletedAt: propertyName,
timestamps: true,
paranoid: true,
});
},
);

export const Version = createBuiltInAttributeDecorator(
'Version',
(target: ModelStatic, propertyName: string) => {
registerModelOptions(target, {
version: propertyName,
});
},
);
6 changes: 6 additions & 0 deletions packages/core/src/decorators/legacy/decorator-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ export function throwMustBeMethod(decoratorName: string, target: Object, propert
);
}

export function throwMustBeAttribute(decoratorName: string, target: Object, propertyName: string | symbol): never {
throw new TypeError(
`Decorator @${decoratorName} has been used on ${getPropertyName(target, propertyName)}, which is a symbol field. Symbol Model Attributes are not currently supported. We welcome a PR that implements this feature.`,
);
}

export function getPropertyName(obj: object, property: string | symbol): string {
if (typeof obj === 'function') {
return `${obj.name}.${String(property)}`;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/decorators/legacy/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export const Unique = Pkg.Unique;
export const Index = Pkg.Index;
export const createIndexDecorator = Pkg.createIndexDecorator;

// Built-in Attribute Decorators

export const CreatedAt = Pkg.CreatedAt;
export const UpdatedAt = Pkg.UpdatedAt;
export const DeletedAt = Pkg.DeletedAt;
export const Version = Pkg.Version;

// Association Decorators

export const BelongsTo = Pkg.BelongsTo;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/decorators/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from './attribute.js';
export * from './table.js';
export * from './validation.js';
export { HasOne, HasMany, BelongsTo, BelongsToMany } from './associations.js';
export * from './built-in-attributes.js';
Loading

0 comments on commit 9cfffe4

Please sign in to comment.