mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
build: setup SAP HANA tests (#11347)
* build: setup SAP HANA tests * test: fix/skip failing SAP HANA tests * fix(sap): rename schema
This commit is contained in:
parent
6ba408214e
commit
fb06662bea
39
.github/workflows/database-compose-tests.yml
vendored
39
.github/workflows/database-compose-tests.yml
vendored
@ -1,39 +0,0 @@
|
||||
name: database-tests
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
node-version:
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
oracle:
|
||||
# nyc is stuck at the end of the test execution even if all tests pass on Node.js 16.x
|
||||
if: ${{ inputs.node-version != 16 }}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- run: docker compose -f .github/workflows/test/oracle.docker-compose.yml up oracle --detach
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ inputs.node-version }}
|
||||
cache: "npm"
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: build
|
||||
path: build/
|
||||
|
||||
- run: npm i
|
||||
- run: cp .github/workflows/test/oracle.ormconfig.json ormconfig.json
|
||||
- run: docker compose -f .github/workflows/test/oracle.docker-compose.yml up oracle --wait
|
||||
- run: npx nyc npm run test:ci
|
||||
|
||||
- name: Coveralls Parallel
|
||||
uses: coverallsapp/github-action@v2
|
||||
with:
|
||||
flag-name: oracle-node:${{ inputs.node-version }}
|
||||
parallel: true
|
||||
65
.github/workflows/database-tests-compose.yml
vendored
Normal file
65
.github/workflows/database-tests-compose.yml
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
name: database-tests-compose
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
node-version:
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
oracle:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- run: docker compose up oracle --detach
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ inputs.node-version }}
|
||||
cache: "npm"
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: build
|
||||
path: build/
|
||||
|
||||
- run: npm ci
|
||||
- run: cat ormconfig.sample.json | jq 'map(select(.name == "oracle"))' > ormconfig.json
|
||||
- run: docker compose up oracle --no-recreate --wait
|
||||
- run: npx nyc npm run test:ci
|
||||
|
||||
- name: Coveralls Parallel
|
||||
uses: coverallsapp/github-action@v2
|
||||
with:
|
||||
flag-name: oracle-node:${{ inputs.node-version }}
|
||||
parallel: true
|
||||
|
||||
sap:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- run: docker compose up hanaexpress --detach
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ inputs.node-version }}
|
||||
cache: "npm"
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: build
|
||||
path: build/
|
||||
|
||||
- run: npm i
|
||||
- run: cat ormconfig.sample.json | jq 'map(select(.name == "hanaexpress"))' > ormconfig.json
|
||||
- run: docker compose up hanaexpress --no-recreate --wait
|
||||
- run: npx nyc npm run test:ci
|
||||
|
||||
- name: Coveralls Parallel
|
||||
uses: coverallsapp/github-action@v2
|
||||
with:
|
||||
flag-name: sap-node:${{ inputs.node-version }}
|
||||
parallel: true
|
||||
@ -1,4 +1,4 @@
|
||||
name: database-tests
|
||||
name: database-tests-windows
|
||||
|
||||
on: workflow_call
|
||||
|
||||
12
.github/workflows/test.yml
vendored
12
.github/workflows/test.yml
vendored
@ -58,23 +58,23 @@ jobs:
|
||||
node-version: ${{matrix.node-version}}
|
||||
|
||||
# These tests run with custom docker image attributes that can't be specified in a GHA service
|
||||
database-compose-tests:
|
||||
database-tests-compose:
|
||||
needs: build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||
node-version: [16, 18, 20] #, 22]
|
||||
uses: ./.github/workflows/database-compose-tests.yml
|
||||
node-version: [18, 20] #, 22]
|
||||
uses: ./.github/workflows/database-tests-compose.yml
|
||||
with:
|
||||
node-version: ${{matrix.node-version}}
|
||||
|
||||
windows-database-tests:
|
||||
database-tests-windows:
|
||||
needs: build
|
||||
uses: ./.github/workflows/windows-database-tests.yml
|
||||
uses: ./.github/workflows/database-tests-windows.yml
|
||||
|
||||
# Run with most databases possible to provide the coverage of the tests
|
||||
coverage:
|
||||
if: ${{ always() }}
|
||||
needs: [database-tests, database-compose-tests, windows-database-tests]
|
||||
needs: [database-tests, database-tests-compose, database-tests-windows]
|
||||
uses: ./.github/workflows/coverage.yml
|
||||
|
||||
12
.github/workflows/test/oracle.docker-compose.yml
vendored
12
.github/workflows/test/oracle.docker-compose.yml
vendored
@ -1,12 +0,0 @@
|
||||
services:
|
||||
oracle:
|
||||
image: "container-registry.oracle.com/database/free:23.5.0.0-lite"
|
||||
container_name: "typeorm-oracle"
|
||||
ports:
|
||||
- "1521:1521"
|
||||
environment:
|
||||
ORACLE_PWD: "oracle"
|
||||
ORACLE_SID: "FREE"
|
||||
volumes:
|
||||
# - oracle-data:/opt/oracle/oradata
|
||||
- ../../../docker/oracle/startup:/opt/oracle/scripts/startup:ro
|
||||
13
.github/workflows/test/oracle.ormconfig.json
vendored
13
.github/workflows/test/oracle.ormconfig.json
vendored
@ -1,13 +0,0 @@
|
||||
[
|
||||
{
|
||||
"skip": false,
|
||||
"name": "oracle",
|
||||
"type": "oracle",
|
||||
"host": "localhost",
|
||||
"port": 1521,
|
||||
"serviceName": "FREEPDB1",
|
||||
"username": "typeorm",
|
||||
"password": "oracle",
|
||||
"logging": false
|
||||
}
|
||||
]
|
||||
@ -63,7 +63,7 @@ npm install
|
||||
To create an initial `ormconfig.json` file, run the following command:
|
||||
|
||||
```shell
|
||||
cp ormconfig.json.dist ormconfig.json
|
||||
cp ormconfig.sample.json ormconfig.json
|
||||
```
|
||||
|
||||
## Building
|
||||
@ -128,7 +128,7 @@ describe("github issues > #<issue number> <issue title>", () => {
|
||||
If you place entities in `./entity/<entity-name>.ts` relative to your `issue-<num>.ts` file,
|
||||
they will automatically be loaded.
|
||||
|
||||
To run the tests, setup your environment configuration by copying `ormconfig.json.dist` into `ormconfig.json` and replacing parameters with your own. The tests will be run for each database that is defined in that file. If you're working on something that's not database specific and you want to speed things up, you can pick which objects in the file make sense for you to keep.
|
||||
To run the tests, setup your environment configuration by copying `ormconfig.sample.json` into `ormconfig.json` and replacing parameters with your own. The tests will be run for each database that is defined in that file. If you're working on something that's not database specific and you want to speed things up, you can pick which objects in the file make sense for you to keep.
|
||||
|
||||
Run the tests as follows:
|
||||
|
||||
@ -149,12 +149,12 @@ describe.only('your describe test', ....)
|
||||
Alternatively, you can use the `--grep` flag to pass a regex to `mocha`. Only the tests that have `describe`/`it` statements that match the regex will be run. For example:
|
||||
|
||||
```shell
|
||||
npm test -- --grep="github issues > #363"
|
||||
npm run test -- --grep "github issues > #363"
|
||||
```
|
||||
|
||||
### Faster developer cycle for editing code and running tests
|
||||
|
||||
The `npm test` script works by deleting built TypeScript code, rebuilding the codebase, and then running tests. This can take a long time.
|
||||
The `npm run test` script works by deleting built TypeScript code, rebuilding the codebase, and then running tests. This can take a long time.
|
||||
|
||||
Instead, for a quicker feedback cycle, you can run `npm run compile -- --watch` to make a fresh build and instruct TypeScript to watch for changes and only compile what code you've changed.
|
||||
|
||||
|
||||
@ -78,33 +78,33 @@ services:
|
||||
- "9010:9010"
|
||||
- "9020:9020"
|
||||
|
||||
# sap hana (works only on linux)
|
||||
# hanaexpress:
|
||||
# image: "store/saplabs/hanaexpress:2.00.040.00.20190729.1"
|
||||
# container_name: "typeorm-hanaexpress"
|
||||
# hostname: hxe
|
||||
# command:
|
||||
# [
|
||||
# "--passwords-url",
|
||||
# "file:////hana/hxe-config.json",
|
||||
# "--agree-to-sap-license",
|
||||
# ]
|
||||
# ulimits:
|
||||
# nofile: 1048576
|
||||
# sysctls:
|
||||
# - kernel.shmmax=1073741824
|
||||
# - net.ipv4.ip_local_port_range=40000 60999
|
||||
# - kernel.shmmni=524288
|
||||
# - kernel.shmall=8388608
|
||||
# volumes:
|
||||
# - volume-hana-xe:/hana/mounts
|
||||
# - ./docker/hana/hxe-config.json:/hana/hxe-config.json
|
||||
# ports:
|
||||
# - 39013:39013
|
||||
# - 39017:39017
|
||||
# - 39041-39045:39041-39045
|
||||
# - 1128-1129:1128-1129
|
||||
# - 59013-59014:59013-59014
|
||||
# sap hana
|
||||
# works only on linux, minimum 10GB RAM for docker required
|
||||
hanaexpress:
|
||||
image: "saplabs/hanaexpress:2.00.076.00.20240701.1"
|
||||
container_name: "typeorm-hanaexpress"
|
||||
hostname: hxe
|
||||
command:
|
||||
[
|
||||
"--passwords-url",
|
||||
"file:////hana/hxe-config.json",
|
||||
"--agree-to-sap-license",
|
||||
]
|
||||
ulimits:
|
||||
nofile: 1048576
|
||||
sysctls:
|
||||
- kernel.shmall=3145728 # System-wide limit of total shared memory, in 4k pages
|
||||
- kernel.shmmax=1073741824 # Maximum shared memory segment sizes
|
||||
- kernel.shmmni=4096 # Maximum number of shared memory segments
|
||||
- net.ipv4.ip_local_port_range=40000 60999
|
||||
volumes:
|
||||
- volume-hana-xe:/hana/mounts
|
||||
- ./docker/hana/hxe-config.json:/hana/hxe-config.json:ro
|
||||
ports:
|
||||
- "39041:39041"
|
||||
healthcheck:
|
||||
test: "/hana/shared/HXE/exe/linuxx86_64/hdb/hdbsql -n localhost:39041 -u SYSTEM -p HXEHana1 \"\\s\""
|
||||
interval: 5s
|
||||
|
||||
# mongodb
|
||||
mongodb:
|
||||
@ -120,7 +120,7 @@ services:
|
||||
# ports:
|
||||
# - "6379:6379"
|
||||
|
||||
# volumes:
|
||||
# cockroach-data:
|
||||
# oracle-data:
|
||||
# volume-hana-xe:
|
||||
volumes:
|
||||
# cockroach-data:
|
||||
# oracle-data:
|
||||
volume-hana-xe:
|
||||
|
||||
@ -91,13 +91,12 @@
|
||||
},
|
||||
{
|
||||
"skip": false,
|
||||
"name": "sap",
|
||||
"name": "hanaexpress",
|
||||
"type": "sap",
|
||||
"host": "192.168.56.102",
|
||||
"port": 39015,
|
||||
"host": "localhost",
|
||||
"port": 39041,
|
||||
"username": "SYSTEM",
|
||||
"password": "MySuperHanaPwd123!",
|
||||
"database": "HXE",
|
||||
"password": "HXEHana1",
|
||||
"logging": false
|
||||
},
|
||||
{
|
||||
41
package-lock.json
generated
41
package-lock.json
generated
@ -30,6 +30,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.22.0",
|
||||
"@sap/hana-client": "^2.24.21",
|
||||
"@tsconfig/node16": "^16.1.3",
|
||||
"@types/chai": "^4.3.20",
|
||||
"@types/chai-as-promised": "^7.1.8",
|
||||
@ -58,6 +59,7 @@
|
||||
"gulp-sourcemaps": "^3.0.0",
|
||||
"gulp-typescript": "^6.0.0-alpha.1",
|
||||
"gulpclass": "^0.2.0",
|
||||
"hdb-pool": "^0.1.6",
|
||||
"mocha": "^10.8.2",
|
||||
"mongodb": "^6.15.0",
|
||||
"mssql": "^11.0.1",
|
||||
@ -2211,6 +2213,34 @@
|
||||
"@redis/client": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@sap/hana-client": {
|
||||
"version": "2.24.21",
|
||||
"resolved": "https://registry.npmjs.org/@sap/hana-client/-/hana-client-2.24.21.tgz",
|
||||
"integrity": "sha512-Mat/LwhvboZqbBKXxLDJz+Xtjf+Hht/SDaVRmzCoNDrbWNKiWIGZ5b9xQVBAXZFfU6GTzFQPcP1wGLBb71BRRg==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"hasShrinkwrap": true,
|
||||
"license": "SEE LICENSE IN developer-license-3_2.txt",
|
||||
"dependencies": {
|
||||
"debug": "3.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@sap/hana-client/node_modules/debug": {
|
||||
"version": "3.1.0",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@sap/hana-client/node_modules/ms": {
|
||||
"version": "2.0.0",
|
||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@sinonjs/commons": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.0.tgz",
|
||||
@ -7878,6 +7908,17 @@
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/hdb-pool": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/hdb-pool/-/hdb-pool-0.1.6.tgz",
|
||||
"integrity": "sha512-8VZOLn1EHamm1NmTFQj2iqjVcfonYIsD7F5DU2bz2N+gF+knp6/MbAVeRXkJtya717IBkPeA5iv0/1iPuYo4ZA==",
|
||||
"deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/he": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
|
||||
|
||||
@ -82,10 +82,10 @@
|
||||
"lint": "eslint .",
|
||||
"pack": "gulp pack",
|
||||
"package": "gulp package",
|
||||
"test": "npm run compile && npm run test:fast",
|
||||
"test": "npm run compile && npm run test:fast --",
|
||||
"test:ci": "mocha --bail",
|
||||
"test:fast": "mocha",
|
||||
"watch": "./node_modules/.bin/tsc -w"
|
||||
"watch": "tsc --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sqltools/formatter": "^1.2.5",
|
||||
@ -104,6 +104,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.22.0",
|
||||
"@sap/hana-client": "^2.24.21",
|
||||
"@tsconfig/node16": "^16.1.3",
|
||||
"@types/chai": "^4.3.20",
|
||||
"@types/chai-as-promised": "^7.1.8",
|
||||
@ -132,6 +133,7 @@
|
||||
"gulp-sourcemaps": "^3.0.0",
|
||||
"gulp-typescript": "^6.0.0-alpha.1",
|
||||
"gulpclass": "^0.2.0",
|
||||
"hdb-pool": "^0.1.6",
|
||||
"mocha": "^10.8.2",
|
||||
"mongodb": "^6.15.0",
|
||||
"mssql": "^11.0.1",
|
||||
|
||||
@ -302,11 +302,9 @@ export class SapDriver implements Driver {
|
||||
|
||||
const queryRunner = this.createQueryRunner("master")
|
||||
|
||||
this.version = await queryRunner.getVersion()
|
||||
|
||||
if (!this.database) {
|
||||
this.database = await queryRunner.getCurrentDatabase()
|
||||
}
|
||||
const { version, database } = await queryRunner.getDatabaseAndVersion()
|
||||
this.version = version
|
||||
this.database = database
|
||||
|
||||
if (!this.schema) {
|
||||
this.schema = await queryRunner.getCurrentSchema()
|
||||
|
||||
@ -396,12 +396,16 @@ export class SapQueryRunner extends BaseQueryRunner implements QueryRunner {
|
||||
/**
|
||||
* Returns the database server version.
|
||||
*/
|
||||
async getVersion(): Promise<string> {
|
||||
const currentDBQuery: [{ version: string }] = await this.query(
|
||||
`SELECT "VERSION" AS "version" FROM "SYS"."M_DATABASE"`,
|
||||
)
|
||||
async getDatabaseAndVersion(): Promise<{
|
||||
database: string
|
||||
version: string
|
||||
}> {
|
||||
const currentDBQuery: [{ database: string; version: string }] =
|
||||
await this.query(
|
||||
`SELECT "DATABASE_NAME" AS "database", "VERSION" AS "version" FROM "SYS"."M_DATABASE"`,
|
||||
)
|
||||
|
||||
return currentDBQuery[0].version
|
||||
return currentDBQuery[0]
|
||||
}
|
||||
|
||||
/**
|
||||
@ -674,14 +678,14 @@ export class SapQueryRunner extends BaseQueryRunner implements QueryRunner {
|
||||
upQueries.push(
|
||||
new Query(
|
||||
`RENAME TABLE ${this.escapePath(oldTable)} TO ${this.escapePath(
|
||||
newTableName,
|
||||
newTable,
|
||||
)}`,
|
||||
),
|
||||
)
|
||||
downQueries.push(
|
||||
new Query(
|
||||
`RENAME TABLE ${this.escapePath(newTable)} TO ${this.escapePath(
|
||||
oldTableName,
|
||||
oldTable,
|
||||
)}`,
|
||||
),
|
||||
)
|
||||
|
||||
@ -25,7 +25,7 @@ const expectCurrentApplicationName = async (
|
||||
describe("Connection replication", () => {
|
||||
const ormConfigConnectionOptionsArray = getTypeOrmConfig()
|
||||
const postgresOptions = ormConfigConnectionOptionsArray.find(
|
||||
(options) => options.type == "postgres",
|
||||
(options) => options.type == "postgres" && !options.skip,
|
||||
)
|
||||
if (!postgresOptions) {
|
||||
return
|
||||
|
||||
@ -87,6 +87,13 @@ describe("database schema > custom constraint names > foreign key", () => {
|
||||
it("should not change constraint names when table renamed", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
await queryRunner.renameTable("animal", "animal_renamed")
|
||||
await queryRunner.renameTable(
|
||||
@ -132,6 +139,13 @@ describe("database schema > custom constraint names > foreign key", () => {
|
||||
// in SqlServer we can't change column that is used in FK.
|
||||
if (dataSource.driver.options.type === "mssql") return
|
||||
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
|
||||
let table = await queryRunner.getTable("animal")
|
||||
|
||||
@ -59,6 +59,13 @@ describe("database schema > custom constraint names > index", () => {
|
||||
it("should not change constraint names when table renamed", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
await queryRunner.renameTable("post", "post_renamed")
|
||||
|
||||
@ -81,6 +88,13 @@ describe("database schema > custom constraint names > index", () => {
|
||||
it("should not change constraint names when column renamed", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
|
||||
let table = await queryRunner.getTable("post")
|
||||
|
||||
@ -76,6 +76,13 @@ describe("database schema > custom constraint names > unique", () => {
|
||||
it("should not change constraint names when table renamed", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
await queryRunner.renameTable("post", "post_renamed")
|
||||
|
||||
@ -87,7 +94,6 @@ describe("database schema > custom constraint names > unique", () => {
|
||||
if (
|
||||
DriverUtils.isMySQLFamily(dataSource.driver) ||
|
||||
dataSource.driver.options.type === "aurora-mysql" ||
|
||||
dataSource.driver.options.type === "sap" ||
|
||||
dataSource.driver.options.type === "spanner"
|
||||
) {
|
||||
const uniqueIndex = table!.indices.find(
|
||||
@ -106,6 +112,13 @@ describe("database schema > custom constraint names > unique", () => {
|
||||
it("should not change constraint names when column renamed", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
|
||||
let table = await queryRunner.getTable("post")
|
||||
@ -129,7 +142,6 @@ describe("database schema > custom constraint names > unique", () => {
|
||||
if (
|
||||
DriverUtils.isMySQLFamily(dataSource.driver) ||
|
||||
dataSource.driver.options.type === "aurora-mysql" ||
|
||||
dataSource.driver.options.type === "sap" ||
|
||||
dataSource.driver.options.type === "spanner"
|
||||
) {
|
||||
const uniqueIndex = table!.indices.find(
|
||||
|
||||
@ -87,6 +87,13 @@ describe("entity schema > custom constraint names > foreign key", () => {
|
||||
it("should not change constraint names when table renamed", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
await queryRunner.renameTable("animal", "animal_renamed")
|
||||
await queryRunner.renameTable(
|
||||
@ -132,6 +139,13 @@ describe("entity schema > custom constraint names > foreign key", () => {
|
||||
// in SqlServer we can't change column that is used in FK.
|
||||
if (dataSource.driver.options.type === "mssql") return
|
||||
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
|
||||
let table = await queryRunner.getTable("animal")
|
||||
|
||||
@ -59,6 +59,13 @@ describe("entity schema > custom constraint names > index", () => {
|
||||
it("should not change constraint names when table renamed", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
await queryRunner.renameTable("post", "post_renamed")
|
||||
|
||||
@ -81,6 +88,13 @@ describe("entity schema > custom constraint names > index", () => {
|
||||
it("should not change constraint names when column renamed", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
|
||||
let table = await queryRunner.getTable("post")
|
||||
|
||||
@ -76,6 +76,13 @@ describe("database schema > custom constraint names > unique", () => {
|
||||
it("should not change constraint names when table renamed", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
await queryRunner.renameTable("post", "post_renamed")
|
||||
|
||||
@ -87,7 +94,6 @@ describe("database schema > custom constraint names > unique", () => {
|
||||
if (
|
||||
DriverUtils.isMySQLFamily(dataSource.driver) ||
|
||||
dataSource.driver.options.type === "aurora-mysql" ||
|
||||
dataSource.driver.options.type === "sap" ||
|
||||
dataSource.driver.options.type === "spanner"
|
||||
) {
|
||||
const uniqueIndex = table!.indices.find(
|
||||
@ -106,6 +112,13 @@ describe("database schema > custom constraint names > unique", () => {
|
||||
it("should not change constraint names when column renamed", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
if (dataSource.driver.options.type === "sap") {
|
||||
// TODO: https://github.com/typeorm/typeorm/issues/11348
|
||||
console.log("Skip failing test for SAP HANA")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = dataSource.createQueryRunner()
|
||||
|
||||
let table = await queryRunner.getTable("post")
|
||||
@ -129,7 +142,6 @@ describe("database schema > custom constraint names > unique", () => {
|
||||
if (
|
||||
DriverUtils.isMySQLFamily(dataSource.driver) ||
|
||||
dataSource.driver.options.type === "aurora-mysql" ||
|
||||
dataSource.driver.options.type === "sap" ||
|
||||
dataSource.driver.options.type === "spanner"
|
||||
) {
|
||||
const uniqueIndex = table!.indices.find(
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
import { expect } from "chai"
|
||||
import "reflect-metadata"
|
||||
|
||||
import { DataSource, Repository } from "../../../../../src/index"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../../../utils/test-utils"
|
||||
import { expect } from "chai"
|
||||
import { Category } from "./entity/Category"
|
||||
import { Post } from "./entity/Post"
|
||||
|
||||
@ -48,7 +49,7 @@ describe("persistence > orphanage > delete", () => {
|
||||
)
|
||||
|
||||
const categoryToInsert = await categoryRepository.save(
|
||||
new Category(),
|
||||
new Category("all-posts"),
|
||||
)
|
||||
categoryToInsert.posts = [new Post(), new Post()]
|
||||
|
||||
|
||||
@ -1,16 +1,24 @@
|
||||
import { Entity } from "../../../../../../src/decorator/entity/Entity"
|
||||
import { Column } from "../../../../../../src/decorator/columns/Column"
|
||||
import { PrimaryGeneratedColumn } from "../../../../../../src/decorator/columns/PrimaryGeneratedColumn"
|
||||
import { Post } from "./Post"
|
||||
import { Entity } from "../../../../../../src/decorator/entity/Entity"
|
||||
import { OneToMany } from "../../../../../../src/decorator/relations/OneToMany"
|
||||
import { Post } from "./Post"
|
||||
|
||||
@Entity()
|
||||
export class Category {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@OneToMany(() => Post, (post) => post.category, {
|
||||
cascade: ["insert"],
|
||||
eager: true,
|
||||
})
|
||||
posts: Post[]
|
||||
|
||||
constructor(name: string) {
|
||||
this.name = name
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
import "reflect-metadata"
|
||||
import { Connection, Repository } from "../../../../../src/index"
|
||||
import {
|
||||
reloadTestingDatabases,
|
||||
createTestingConnections,
|
||||
closeTestingConnections,
|
||||
} from "../../../../utils/test-utils"
|
||||
import { expect } from "chai"
|
||||
import { User } from "./entity/User"
|
||||
import "reflect-metadata"
|
||||
|
||||
import { DataSource, Repository } from "../../../../../src/index"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../../../utils/test-utils"
|
||||
import { Setting } from "./entity/Setting"
|
||||
import { User } from "./entity/User"
|
||||
|
||||
describe("persistence > orphanage > disable", () => {
|
||||
// -------------------------------------------------------------------------
|
||||
@ -15,7 +16,7 @@ describe("persistence > orphanage > disable", () => {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// connect to db
|
||||
let connections: Connection[] = []
|
||||
let connections: DataSource[] = []
|
||||
|
||||
before(
|
||||
async () =>
|
||||
@ -47,7 +48,7 @@ describe("persistence > orphanage > disable", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
const user = await userRepo.save(new User())
|
||||
const user = await userRepo.save(new User("test-user"))
|
||||
user.settings = [
|
||||
new Setting("foo"),
|
||||
new Setting("bar"),
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { User } from "./User"
|
||||
import { Entity } from "../../../../../../src/decorator/entity/Entity"
|
||||
import { PrimaryGeneratedColumn } from "../../../../../../src/decorator/columns/PrimaryGeneratedColumn"
|
||||
import { Column } from "../../../../../../src/decorator/columns/Column"
|
||||
import { ManyToOne } from "../../../../../../src/decorator/relations/ManyToOne"
|
||||
import { PrimaryGeneratedColumn } from "../../../../../../src/decorator/columns/PrimaryGeneratedColumn"
|
||||
import { Entity } from "../../../../../../src/decorator/entity/Entity"
|
||||
import { JoinColumn } from "../../../../../../src/decorator/relations/JoinColumn"
|
||||
import { ManyToOne } from "../../../../../../src/decorator/relations/ManyToOne"
|
||||
import { User } from "./User"
|
||||
|
||||
@Entity()
|
||||
export class Setting {
|
||||
|
||||
@ -1,16 +1,24 @@
|
||||
import { Entity } from "../../../../../../src/decorator/entity/Entity"
|
||||
import { Column } from "../../../../../../src/decorator/columns/Column"
|
||||
import { PrimaryGeneratedColumn } from "../../../../../../src/decorator/columns/PrimaryGeneratedColumn"
|
||||
import { Setting } from "./Setting"
|
||||
import { Entity } from "../../../../../../src/decorator/entity/Entity"
|
||||
import { OneToMany } from "../../../../../../src/decorator/relations/OneToMany"
|
||||
import { Setting } from "./Setting"
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@OneToMany(() => Setting, (setting) => setting.user, {
|
||||
cascade: true,
|
||||
eager: true,
|
||||
})
|
||||
settings: Setting[]
|
||||
|
||||
constructor(name: string) {
|
||||
this.name = name
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,8 +25,13 @@ describe("query builder > cte > recursive", () => {
|
||||
dataSources
|
||||
.filter(filterByCteCapabilities("enabled"))
|
||||
.map(async (dataSource) => {
|
||||
// CTE cannot reference itself in Spanner
|
||||
if (dataSource.options.type === "spanner") return
|
||||
if (
|
||||
dataSource.options.type === "sap" ||
|
||||
dataSource.options.type === "spanner"
|
||||
) {
|
||||
// CTE cannot reference itself in SAP HANA / Spanner
|
||||
return
|
||||
}
|
||||
|
||||
let qb: { foo: number }[]
|
||||
if (dataSource.options.type === "oracle") {
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
import "reflect-metadata"
|
||||
import { expect } from "chai"
|
||||
import "reflect-metadata"
|
||||
|
||||
import { DataSource } from "../../../../src"
|
||||
import {
|
||||
createTestingConnections,
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../../utils/test-utils"
|
||||
import { Foo } from "./entity/foo"
|
||||
import { filterByCteCapabilities } from "./helpers"
|
||||
import { DataSource } from "../../../../src/index.js"
|
||||
|
||||
describe("query builder > cte > simple", () => {
|
||||
let dataSources: DataSource[]
|
||||
@ -33,15 +34,12 @@ describe("query builder > cte > simple", () => {
|
||||
[1, 2, 3].map((i) => ({ id: i, bar: String(i) })),
|
||||
)
|
||||
|
||||
let cteSelection =
|
||||
dataSource.driver.options.type === "oracle"
|
||||
? `"foo"."bar"`
|
||||
: `foo.bar`
|
||||
|
||||
const cteSelection = `${dataSource.driver.escape(
|
||||
"foo",
|
||||
)}.${dataSource.driver.escape("bar")}`
|
||||
const cteQuery = dataSource
|
||||
.createQueryBuilder()
|
||||
.select()
|
||||
.addSelect(cteSelection, "bar")
|
||||
.select(cteSelection, "bar")
|
||||
.from(Foo, "foo")
|
||||
.where(`${cteSelection} = :value`, { value: "2" })
|
||||
|
||||
@ -53,19 +51,18 @@ describe("query builder > cte > simple", () => {
|
||||
columnNames: ["raz"],
|
||||
}
|
||||
|
||||
cteSelection =
|
||||
const selection =
|
||||
dataSource.driver.options.type === "spanner"
|
||||
? "qaz.bar"
|
||||
: dataSource.driver.options.type === "oracle"
|
||||
? `"qaz"."raz"`
|
||||
: "qaz.raz"
|
||||
? '"qaz"."bar"'
|
||||
: `${dataSource.driver.escape(
|
||||
"qaz",
|
||||
)}.${dataSource.driver.escape("raz")}`
|
||||
|
||||
const qb = dataSource
|
||||
.createQueryBuilder()
|
||||
.addCommonTableExpression(cteQuery, "qaz", cteOptions)
|
||||
.select(selection, "raz")
|
||||
.from("qaz", "qaz")
|
||||
.select([])
|
||||
.addSelect(cteSelection, "raz")
|
||||
|
||||
expect(await qb.getRawMany()).to.deep.equal([{ raz: "2" }])
|
||||
}),
|
||||
@ -82,20 +79,13 @@ describe("query builder > cte > simple", () => {
|
||||
[1, 2, 3].map((i) => ({ id: i, bar: String(i) })),
|
||||
)
|
||||
|
||||
let cteSelection =
|
||||
dataSource.driver.options.type === "oracle"
|
||||
? `"foo"."bar"`
|
||||
: `foo.bar`
|
||||
const cteSelection = `${dataSource.driver.escape(
|
||||
"foo",
|
||||
)}.${dataSource.driver.escape("bar")}`
|
||||
|
||||
const cteQuery = dataSource
|
||||
.createQueryBuilder()
|
||||
.select()
|
||||
.addSelect(
|
||||
dataSource.driver.options.type === "oracle"
|
||||
? `"bar"`
|
||||
: "bar",
|
||||
"bar",
|
||||
)
|
||||
.select(cteSelection, "bar")
|
||||
.from(Foo, "foo")
|
||||
.where(`${cteSelection} = '2'`)
|
||||
|
||||
@ -107,12 +97,12 @@ describe("query builder > cte > simple", () => {
|
||||
columnNames: ["raz"],
|
||||
}
|
||||
|
||||
cteSelection =
|
||||
const selection =
|
||||
dataSource.driver.options.type === "spanner"
|
||||
? "qaz.bar"
|
||||
: dataSource.driver.options.type === "oracle"
|
||||
? `"qaz"."raz"`
|
||||
: "qaz.raz"
|
||||
? '"qaz"."bar"'
|
||||
: `${dataSource.driver.escape(
|
||||
"qaz",
|
||||
)}.${dataSource.driver.escape("raz")}`
|
||||
|
||||
const results = await dataSource
|
||||
.createQueryBuilder(Foo, "foo")
|
||||
@ -120,11 +110,7 @@ describe("query builder > cte > simple", () => {
|
||||
.innerJoin(
|
||||
"qaz",
|
||||
"qaz",
|
||||
`${cteSelection} = ${
|
||||
dataSource.driver.options.type === "oracle"
|
||||
? `"foo"."bar"`
|
||||
: `foo.bar`
|
||||
}`,
|
||||
`${selection} = ${cteSelection}`,
|
||||
)
|
||||
.getMany()
|
||||
|
||||
@ -172,56 +158,53 @@ describe("query builder > cte > simple", () => {
|
||||
dataSources
|
||||
.filter(filterByCteCapabilities("enabled"))
|
||||
.map(async (dataSource) => {
|
||||
// Spanner does not support column names in CTE
|
||||
let results: { row: number }[]
|
||||
if (dataSource.options.type === "spanner") {
|
||||
// Spanner does not support column names in CTE
|
||||
const query1 = dataSource
|
||||
.createQueryBuilder()
|
||||
.select("1", "foo")
|
||||
.fromDummy()
|
||||
.getSql()
|
||||
const query2 = dataSource
|
||||
.createQueryBuilder()
|
||||
.select("2", "foo")
|
||||
.fromDummy()
|
||||
.getSql()
|
||||
|
||||
let results: { row: any }[]
|
||||
if (dataSource.driver.options.type === "spanner") {
|
||||
results = await dataSource
|
||||
.createQueryBuilder()
|
||||
.select()
|
||||
.addCommonTableExpression(
|
||||
`
|
||||
SELECT 1 AS foo
|
||||
UNION ALL
|
||||
SELECT 2 AS foo
|
||||
`,
|
||||
`${query1} UNION ALL ${query2}`,
|
||||
"cte",
|
||||
)
|
||||
.select('"foo"', "row")
|
||||
.from("cte", "cte")
|
||||
.addSelect("foo", "row")
|
||||
.getRawMany<{ row: any }>()
|
||||
} else if (dataSource.driver.options.type === "oracle") {
|
||||
results = await dataSource
|
||||
.createQueryBuilder()
|
||||
.select()
|
||||
.addCommonTableExpression(
|
||||
`
|
||||
SELECT 1 FROM DUAL
|
||||
UNION
|
||||
SELECT 2 FROM DUAL
|
||||
`,
|
||||
"cte",
|
||||
{ columnNames: ["foo"] },
|
||||
)
|
||||
.from("cte", "cte")
|
||||
.addSelect(`"foo"`, "row")
|
||||
.getRawMany<{ row: any }>()
|
||||
.getRawMany<{ row: number }>()
|
||||
} else {
|
||||
const query1 = dataSource
|
||||
.createQueryBuilder()
|
||||
.select("1")
|
||||
.fromDummy()
|
||||
.getSql()
|
||||
const query2 = dataSource
|
||||
.createQueryBuilder()
|
||||
.select("2")
|
||||
.fromDummy()
|
||||
.getSql()
|
||||
|
||||
const columnName = dataSource.driver.escape("foo")
|
||||
results = await dataSource
|
||||
.createQueryBuilder()
|
||||
.select()
|
||||
.addCommonTableExpression(
|
||||
`
|
||||
SELECT 1
|
||||
UNION
|
||||
SELECT 2
|
||||
`,
|
||||
`${query1} UNION ${query2}`,
|
||||
"cte",
|
||||
{ columnNames: ["foo"] },
|
||||
)
|
||||
.select(columnName, "row")
|
||||
.from("cte", "cte")
|
||||
.addSelect("foo", "row")
|
||||
.getRawMany<{ row: any }>()
|
||||
.orderBy(columnName)
|
||||
.getRawMany<{ row: number }>()
|
||||
}
|
||||
|
||||
const [rowWithOne, rowWithTwo] = results
|
||||
|
||||
@ -120,9 +120,6 @@ describe("query builder > delete", () => {
|
||||
it("should return correct delete result", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
// don't run test for SAP Hana as it won't return these
|
||||
if (connection.name === "sap") return
|
||||
|
||||
// save some users
|
||||
const user1 = new User()
|
||||
user1.name = "John Doe"
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
import { expect } from "chai"
|
||||
import "reflect-metadata"
|
||||
|
||||
import { DataSource } from "../../../src/data-source/DataSource"
|
||||
import { DriverUtils } from "../../../src/driver/DriverUtils"
|
||||
import { Table } from "../../../src/schema-builder/table/Table"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../utils/test-utils"
|
||||
import { Table } from "../../../src/schema-builder/table/Table"
|
||||
import { DriverUtils } from "../../../src/driver/DriverUtils"
|
||||
|
||||
describe("query runner > rename table", () => {
|
||||
let connections: DataSource[]
|
||||
@ -27,8 +29,9 @@ describe("query runner > rename table", () => {
|
||||
if (
|
||||
connection.driver.options.type === "cockroachdb" ||
|
||||
connection.driver.options.type === "spanner"
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = connection.createQueryRunner()
|
||||
|
||||
@ -41,14 +44,14 @@ describe("query runner > rename table", () => {
|
||||
const facultySeq = await queryRunner.query(
|
||||
sequenceQuery("faculty_id_seq"),
|
||||
)
|
||||
facultySeq[0].count.should.be.equal("1")
|
||||
expect(facultySeq[0].count).to.equal("1")
|
||||
}
|
||||
|
||||
let table = await queryRunner.getTable("faculty")
|
||||
|
||||
await queryRunner.renameTable(table!, "question")
|
||||
table = await queryRunner.getTable("question")
|
||||
table!.should.be.exist
|
||||
expect(table).to.exist
|
||||
|
||||
// check if sequence "faculty_id_seq" was renamed to "question_id_seq"
|
||||
if (connection.driver.options.type === "postgres") {
|
||||
@ -58,13 +61,13 @@ describe("query runner > rename table", () => {
|
||||
const questionSeq = await queryRunner.query(
|
||||
sequenceQuery("question_id_seq"),
|
||||
)
|
||||
facultySeq[0].count.should.be.equal("0")
|
||||
questionSeq[0].count.should.be.equal("1")
|
||||
expect(facultySeq[0].count).to.equal("0")
|
||||
expect(questionSeq[0].count).to.equal("1")
|
||||
}
|
||||
|
||||
await queryRunner.renameTable("question", "answer")
|
||||
table = await queryRunner.getTable("answer")
|
||||
table!.should.be.exist
|
||||
expect(table).to.exist
|
||||
|
||||
// check if sequence "question_id_seq" was renamed to "answer_id_seq"
|
||||
if (connection.driver.options.type === "postgres") {
|
||||
@ -74,14 +77,14 @@ describe("query runner > rename table", () => {
|
||||
const answerSeq = await queryRunner.query(
|
||||
sequenceQuery("answer_id_seq"),
|
||||
)
|
||||
questionSeq[0].count.should.be.equal("0")
|
||||
answerSeq[0].count.should.be.equal("1")
|
||||
expect(questionSeq[0].count).to.equal("0")
|
||||
expect(answerSeq[0].count).to.equal("1")
|
||||
}
|
||||
|
||||
await queryRunner.executeMemoryDownSql()
|
||||
|
||||
table = await queryRunner.getTable("faculty")
|
||||
table!.should.be.exist
|
||||
expect(table).to.exist
|
||||
|
||||
// check if sequence "answer_id_seq" was renamed to "faculty_id_seq"
|
||||
if (connection.driver.options.type === "postgres") {
|
||||
@ -91,8 +94,8 @@ describe("query runner > rename table", () => {
|
||||
const facultySeq = await queryRunner.query(
|
||||
sequenceQuery("faculty_id_seq"),
|
||||
)
|
||||
answerSeq[0].count.should.be.equal("0")
|
||||
facultySeq[0].count.should.be.equal("1")
|
||||
expect(answerSeq[0].count).to.equal("0")
|
||||
expect(facultySeq[0].count).to.equal("1")
|
||||
}
|
||||
|
||||
await queryRunner.release()
|
||||
@ -106,8 +109,9 @@ describe("query runner > rename table", () => {
|
||||
if (
|
||||
connection.driver.options.type === "cockroachdb" ||
|
||||
connection.driver.options.type === "spanner"
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = connection.createQueryRunner()
|
||||
|
||||
@ -115,7 +119,7 @@ describe("query runner > rename table", () => {
|
||||
|
||||
await queryRunner.renameTable(table!, "renamedPost")
|
||||
table = await queryRunner.getTable("renamedPost")
|
||||
table!.should.be.exist
|
||||
expect(table).to.exist
|
||||
|
||||
// should successfully drop pk if pk constraint was correctly renamed.
|
||||
await queryRunner.dropPrimaryKey(table!)
|
||||
@ -135,13 +139,13 @@ describe("query runner > rename table", () => {
|
||||
(columnName) => columnName === "tag",
|
||||
)
|
||||
})
|
||||
tableUnique!.name!.should.be.equal(newUniqueConstraintName)
|
||||
expect(tableUnique!.name).to.equal(newUniqueConstraintName)
|
||||
}
|
||||
|
||||
await queryRunner.executeMemoryDownSql()
|
||||
|
||||
table = await queryRunner.getTable("post")
|
||||
table!.should.be.exist
|
||||
expect(table).to.exist
|
||||
|
||||
await queryRunner.release()
|
||||
}),
|
||||
@ -154,8 +158,9 @@ describe("query runner > rename table", () => {
|
||||
if (
|
||||
connection.driver.options.type === "cockroachdb" ||
|
||||
connection.driver.options.type === "spanner"
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const queryRunner = connection.createQueryRunner()
|
||||
let table: Table | undefined
|
||||
@ -261,7 +266,7 @@ describe("query runner > rename table", () => {
|
||||
table!,
|
||||
["name"],
|
||||
)
|
||||
table!.indices[0].name!.should.be.equal(newIndexName)
|
||||
expect(table!.indices[0].name).to.equal(newIndexName)
|
||||
|
||||
await queryRunner.renameTable(
|
||||
categoryTableName,
|
||||
@ -275,15 +280,15 @@ describe("query runner > rename table", () => {
|
||||
"question",
|
||||
["id"],
|
||||
)
|
||||
table!.foreignKeys[0].name!.should.be.equal(newForeignKeyName)
|
||||
expect(table!.foreignKeys[0].name).to.equal(newForeignKeyName)
|
||||
|
||||
await queryRunner.executeMemoryDownSql()
|
||||
|
||||
table = await queryRunner.getTable(questionTableName)
|
||||
table!.should.be.exist
|
||||
expect(table).to.exist
|
||||
|
||||
table = await queryRunner.getTable(categoryTableName)
|
||||
table!.should.be.exist
|
||||
expect(table).to.exist
|
||||
|
||||
await queryRunner.release()
|
||||
}),
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { expect } from "chai"
|
||||
import "reflect-metadata"
|
||||
|
||||
import { DataSource } from "../../../src"
|
||||
import { ForeignKeyMetadata } from "../../../src/metadata/ForeignKeyMetadata"
|
||||
import {
|
||||
@ -143,8 +145,8 @@ describe("schema builder > custom-db-and-schema-sync", () => {
|
||||
let photoTable = await queryRunner.getTable(
|
||||
photoMetadata.tablePath,
|
||||
)
|
||||
albumTable!.should.be.exist
|
||||
photoTable!.should.be.exist
|
||||
expect(albumTable).to.exist
|
||||
expect(photoTable).to.exist
|
||||
|
||||
const columns = photoMetadata.columns.filter(
|
||||
(column) => column.propertyName === "albumId",
|
||||
@ -203,10 +205,10 @@ describe("schema builder > custom-db-and-schema-sync", () => {
|
||||
albumMetadata.synchronize = true
|
||||
|
||||
photoMetadata.schema = "public"
|
||||
photoMetadata.tablePath = "photo"
|
||||
photoMetadata.tablePath = "public.photo"
|
||||
|
||||
albumMetadata.schema = "public"
|
||||
albumMetadata.tablePath = "album"
|
||||
albumMetadata.tablePath = "public.album"
|
||||
|
||||
await queryRunner.createSchema(photoMetadata.schema, true)
|
||||
await queryRunner.createSchema(albumMetadata.schema, true)
|
||||
@ -221,8 +223,8 @@ describe("schema builder > custom-db-and-schema-sync", () => {
|
||||
photoMetadata.tablePath,
|
||||
)
|
||||
|
||||
albumTable!.should.be.exist
|
||||
photoTable!.should.be.exist
|
||||
expect(albumTable).to.exist
|
||||
expect(photoTable).to.exist
|
||||
|
||||
photoTable!.foreignKeys.length.should.be.equal(0)
|
||||
|
||||
@ -327,8 +329,8 @@ describe("schema builder > custom-db-and-schema-sync", () => {
|
||||
let photoTable = await queryRunner.getTable(
|
||||
photoMetadata.tablePath,
|
||||
)
|
||||
albumTable!.should.be.exist
|
||||
photoTable!.should.be.exist
|
||||
expect(albumTable).to.exist
|
||||
expect(photoTable).to.exist
|
||||
|
||||
const columns = photoMetadata.columns.filter(
|
||||
(column) => column.propertyName === "albumId",
|
||||
|
||||
@ -9,7 +9,7 @@ import {
|
||||
import { Post } from "./entity/Post"
|
||||
import { Question } from "./entity/Question"
|
||||
|
||||
describe("uuid-mysql", () => {
|
||||
describe("uuid-sap", () => {
|
||||
let connections: DataSource[]
|
||||
before(async () => {
|
||||
connections = await createTestingConnections({
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
import { Entity, OneToMany, PrimaryGeneratedColumn } from "../../../../src"
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from "../../../../src"
|
||||
import { TicketProduct } from "./TicketProduct"
|
||||
|
||||
@Entity()
|
||||
@ -6,6 +11,13 @@ export class Product {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@OneToMany((type) => TicketProduct, (ticketp) => ticketp.product)
|
||||
ticketProduct: TicketProduct[]
|
||||
|
||||
constructor(name: string) {
|
||||
this.name = name
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +17,6 @@ export class Ticket {
|
||||
@Column()
|
||||
chainId: string
|
||||
|
||||
@OneToMany((type) => TicketProduct, (ticketProduct) => ticketProduct.ticket)
|
||||
@OneToMany(() => TicketProduct, (ticketProduct) => ticketProduct.ticket)
|
||||
ticketItems: TicketProduct[]
|
||||
}
|
||||
|
||||
@ -24,9 +24,9 @@ describe("github issues > #2298 - Repository filtering not considering related c
|
||||
it("should work perfectly", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const product1 = new Product()
|
||||
const product1 = new Product("product1")
|
||||
await connection.manager.save(product1)
|
||||
const product2 = new Product()
|
||||
const product2 = new Product("product2")
|
||||
await connection.manager.save(product2)
|
||||
|
||||
const ticket1 = new Ticket()
|
||||
@ -91,12 +91,14 @@ describe("github issues > #2298 - Repository filtering not considering related c
|
||||
id: 3,
|
||||
product: {
|
||||
id: 2,
|
||||
name: "product2",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
product: {
|
||||
id: 2,
|
||||
name: "product2",
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@ -37,6 +37,7 @@ describe("github issues > #2376 Naming single column unique constraint with deco
|
||||
|
||||
if (
|
||||
DriverUtils.isMySQLFamily(connection.driver) ||
|
||||
connection.driver.options.type === "sap" ||
|
||||
connection.driver.options.type === "spanner"
|
||||
) {
|
||||
unique1 = table!.indices.find(
|
||||
|
||||
@ -64,7 +64,7 @@ describe("github issues > #6815 RelationId() on nullable relation returns 'null'
|
||||
},
|
||||
})
|
||||
|
||||
if (connection.name === "cockroachdb") {
|
||||
if (connection.driver.options.type === "cockroachdb") {
|
||||
// CockroachDB returns id as a number.
|
||||
expect(loaded.childId).to.equal(child.id.toString())
|
||||
} else {
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
import { Entity, OneToMany, PrimaryGeneratedColumn } from "../../../../src"
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from "../../../../src"
|
||||
import { Item } from "./item.entity"
|
||||
|
||||
@Entity()
|
||||
@ -6,6 +11,9 @@ export class Thing {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: number
|
||||
|
||||
@Column()
|
||||
name!: string
|
||||
|
||||
@OneToMany(() => Item, (item) => item.thing)
|
||||
items!: Item[]
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import { Thing } from "./entity/thing.entity"
|
||||
|
||||
describe("github issues > #8681 DeepPartial simplification breaks the .create() and .save() method in certain cases.", () => {
|
||||
let connections: DataSource[]
|
||||
|
||||
before(
|
||||
async () =>
|
||||
(connections = await createTestingConnections({
|
||||
@ -26,6 +27,7 @@ describe("github issues > #8681 DeepPartial simplification breaks the .create()
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const myThing: DeepPartial<Thing> = {
|
||||
name: "myThing",
|
||||
items: [{ id: 1 }, { id: 2 }],
|
||||
}
|
||||
|
||||
@ -42,6 +44,7 @@ describe("github issues > #8681 DeepPartial simplification breaks the .create()
|
||||
return { thing, items }
|
||||
}),
|
||||
))
|
||||
|
||||
it("should .save() and .create() complex deep partial entities using a generic repository", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
@ -61,14 +64,14 @@ describe("github issues > #8681 DeepPartial simplification breaks the .create()
|
||||
|
||||
const thingService = new AbstractService<Thing>(Thing)
|
||||
|
||||
const myThing: DeepPartial<Thing> = { id: 1 }
|
||||
const myThing: DeepPartial<Thing> = { id: 1, name: "myThing" }
|
||||
const thing = await thingService.create(myThing)
|
||||
|
||||
const thingRepository = connection.getRepository(Thing)
|
||||
const dbItems = await thingRepository.find()
|
||||
expect(dbItems).to.have.length(1)
|
||||
|
||||
return { thing }
|
||||
expect(dbItems).to.have.length(1)
|
||||
expect(dbItems[0]).to.deep.equal(thing)
|
||||
}),
|
||||
))
|
||||
})
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Entity, Generated, PrimaryColumn } from "../../../../src"
|
||||
import { Column, Entity, Generated, PrimaryColumn } from "../../../../src"
|
||||
|
||||
const ID_TRANSFORMER = {
|
||||
from: (dbValue: number) => dbValue?.toString(),
|
||||
@ -6,6 +6,11 @@ const ID_TRANSFORMER = {
|
||||
entityValue ? Number(entityValue) : entityValue,
|
||||
}
|
||||
|
||||
const HEX_TRANSFORMER = {
|
||||
from: (dbValue: string) => parseInt(dbValue, 16),
|
||||
to: (entityValue: number) => Number(entityValue).toString(16),
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class ExampleEntity {
|
||||
@Generated("increment")
|
||||
@ -14,4 +19,14 @@ export class ExampleEntity {
|
||||
transformer: ID_TRANSFORMER,
|
||||
})
|
||||
id: string
|
||||
|
||||
@Column({
|
||||
type: String,
|
||||
transformer: HEX_TRANSFORMER,
|
||||
})
|
||||
value: number
|
||||
|
||||
constructor(value: number) {
|
||||
this.value = value
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,11 +19,11 @@ describe("github issues > #9381 The column option 《transformer》 affects the
|
||||
await Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
const repository = dataSource.getRepository(ExampleEntity)
|
||||
await repository.save(new ExampleEntity())
|
||||
await repository.save(new ExampleEntity())
|
||||
await repository.save(new ExampleEntity())
|
||||
await repository.save(new ExampleEntity())
|
||||
await repository.save(new ExampleEntity())
|
||||
await repository.save(new ExampleEntity(15))
|
||||
await repository.save(new ExampleEntity(31))
|
||||
await repository.save(new ExampleEntity(32))
|
||||
await repository.save(new ExampleEntity(63))
|
||||
await repository.save(new ExampleEntity(64))
|
||||
const resultFindAll = await repository.find()
|
||||
expect(resultFindAll.length).to.be.eql(5)
|
||||
|
||||
@ -33,9 +33,11 @@ describe("github issues > #9381 The column option 《transformer》 affects the
|
||||
expect(resultTransformer).to.be.eql([
|
||||
{
|
||||
id: "2",
|
||||
value: 31,
|
||||
},
|
||||
{
|
||||
id: "4",
|
||||
value: 63,
|
||||
},
|
||||
])
|
||||
const findEqualsTransformer = await repository.findOne({
|
||||
@ -43,7 +45,7 @@ describe("github issues > #9381 The column option 《transformer》 affects the
|
||||
id: "1",
|
||||
},
|
||||
})
|
||||
expect(findEqualsTransformer).to.be.eql({ id: "1" })
|
||||
expect(findEqualsTransformer).to.be.eql({ id: "1", value: 15 })
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
@ -208,7 +208,7 @@ function getOrmFilepath(): string {
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
`Cannot find ormconfig.json file in the root of the project. To run tests please create ormconfig.json file` +
|
||||
` in the root of the project (near ormconfig.json.dist, you need to copy ormconfig.json.dist into ormconfig.json` +
|
||||
` in the root of the project (near ormconfig.sample.json, you need to copy ormconfig.sample.json into ormconfig.json` +
|
||||
` and change all database settings to match your local environment settings).`,
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user