Skip to content
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

[mysql] Database name isn't read from url #2096

Closed
jcudzich opened this issue May 8, 2018 · 15 comments · Fixed by #5640
Closed

[mysql] Database name isn't read from url #2096

jcudzich opened this issue May 8, 2018 · 15 comments · Fixed by #5640

Comments

@jcudzich
Copy link

jcudzich commented May 8, 2018

Issue type:

[x] question

Database system/driver:

[x] mysql / mariadb

TypeORM version:

[x] latest

Question:

Hello,

I use mysql url connection string, but I get error:

Option "database" is not set in your connection options, please define "database" option in your connection options or ormconfig.json

When i add database property to connection options everything is fine, but why database name can't be read from url? My url:

mysql://username:password@host:port/database

I think that database should be reads from url when it's defined.
What do you think?

Update:
I'm not sure, but I think is bug, becouse when I debug connection I see that database name i corectly read from url, but error is throw by EntityMetadataValidator which not found database options in EntityMetadata.

@pleerock
Copy link
Member

pleerock commented May 9, 2018

are you able to dig into source code a bit and find a place with a problem?

@jcudzich
Copy link
Author

jcudzich commented May 9, 2018

I found that in src/driver/mysql/MysqlDriver.ts options property is set in line 242:

this.options = connection.options as MysqlConnectionOptions;

and in line 248 same file database property is set like this:

this.database = this.options.replication ? this.options.replication.master.database : this.options.database;

So problem is really simple. To create database property TypeORM uses raw options, insted of it should use options built by DriverUtils.buildDriverOptions() which has database property parsed from url.

Using above method to set options property in MysqlDriver solve problem.
After fix, line 242 in src/driver/mysql/MysqlDriver.ts is:

this.options = DriverUtils.buildDriverOptions(connection.options) as MysqlConnectionOptions;

I hope it was helpful.

@pleerock
Copy link
Member

pleerock commented May 9, 2018

thanks for the investigations, are you able to provide a PR?

@jcudzich
Copy link
Author

jcudzich commented May 9, 2018

Sure, just give me some time :)

@vlapo
Copy link
Contributor

vlapo commented Dec 22, 2018

I think this is no more issue. @jcudzich could you please test this on latest version of typeorm?

@nicolasigot
Copy link

Hello @vlapo ,
I just found this issue while getting it with version 0.2.11 of typeORM.
I provide URL with this format as explained above and no database as it is within the URL.
Same issue...

@vlapo
Copy link
Contributor

vlapo commented Jan 9, 2019

Sorry for misunderstanding. I think it is fixed. But now I see we have this kind bug in all drivers. But in MySQL it is checked and throw error. I will check it later

@AndKiel
Copy link

AndKiel commented Feb 12, 2019

I think it's not fixed, happening to me on v0.2.13.

@greg-hoarau
Copy link

Still not fixed in v0.2.17.

@giordy
Copy link

giordy commented Jul 10, 2019

Still not fixed in v0.2.18

@cronosxfiles
Copy link

Still not fixed in v0.2.21

@vfasky
Copy link

vfasky commented Dec 31, 2019

Still not fixed in v0.2.22

@byeongsu-hong
Copy link

Still not fixed in v0.2.24

@edtownend
Copy link

for what it's worth, till the fix is released I've worked around this by regexing out the database from the connection string:

url: process.env.DB_URL,
database: process.env.DB_URL.match(/(?!.*\/)(.*)/)[1],

pleerock pushed a commit that referenced this issue May 16, 2020
* fix: respect database from connection urls

database names can be defined in the options object. Now also connection urls that contain a database can be used to have the database set in the drivers object.

Closes: #2096

* only disconnect connection if connected.

* revert changes.

* fix credentials for testing

* create connection by lib function

* check typeorm config during testing to check whether a mysql database is available

Co-authored-by: julius <julius.friedrich@shift-f3.com>
@ant45de
Copy link
Contributor

ant45de commented Jun 22, 2020

My bugfix has been merged. Now it should work as intended :)

pleerock added a commit that referenced this issue Sep 28, 2020
* chore(deps): bump acorn from 5.7.3 to 5.7.4 (#5679)

Bumps [acorn](https://github.com/acornjs/acorn) from 5.7.3 to 5.7.4.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](acornjs/acorn@5.7.3...5.7.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* docs: Update DEVELOPER.md (#5768)

Fix instruction on how to compile in watch mode. `--` is needed to pass arguments to npm scripts

* fix: handle URL objects as column field values (#5771)

* Add assertion test for issue #5762

* Fix handling of URL as a field value type

Fixes #5762

* Fix missing semicolon

* docs: fixed `sql` to `query` in the last example (#5753)

there was no `sql` tag in the example, and `query` made the most sense.

* fix: update dependency mkdirp to 1.x (#5748)

* docs: typo fix (#5739)

* docs: added soft-delete documentation (#5862)

* feat: create-column, update-column, version-column column kinds now support user specified values (#5867)

* Fixes #3271 - create-column, update-column, version-column column kinds now support user specified values

* removed .only

* create/update/version kind columns now considered as "changed" columns

* removed .only

* docs: fix readme wording (#5842)

word `returns` used twice

* docs: fix raw query (#5845)

The code examples assume many results (see a comment below in each example), but queries were filtered by user.id. Instead groupBy clausule should be used in order to select user.id after using aggregation function.

* fix: expo sqlite driver disconnect() (#6027)

Currently the disconnect() function does not perform a call to databaseConnection close, it only sets the
queryRunner and databaseConnection to undefined, this behavior may cause problems when you do something like this:

1 - await getConnection().close();
2 - Replace the database file
3 - Try to open connection createConnection(); and do some insert

more info:
expo/expo#8109

* docs: fix typeorm alias for TS (#6045)

Just did not work with actual version of ts-node and others modules

* docs: update image.json (#6015)

I think that's a typo

* fix: use an empty string enum as the type of a primary key column (#6063)

Closes: #3874

* fix: escape column comment in mysql driver (#6056)

* Fixed bug with unescaped comment string in MySQL driver.

* Added tests.

* Fixed linting issue.

* docs: add @DeleteDateColumn to special columns docs (#6016)

Mostly copied text from the decorator reference: https://github.com/typeorm/typeorm/blob/master/docs/decorator-reference.md#deletedatecolumn

* docs: update env variables listing (#6007)

Some of listed variables are not used anymore, some were are missing.
List is extracted from src/connection/options-reader/ConnectionOptionsEnvReader.ts

* docs: fix grammar for ormconfig error (#6001)

Trying to match line 54

* docs: fix select query builder link (#5980)

* feat: add FOR NO KEY UPDATE lock mode for postgresql (#5971)

* [Add] FOR NO KEY UPDATE lock mode for postgresql

* [Add] for no key update lock test

* [Fix] lint

* [Fix] test

Co-authored-by: JeyongOh <jeyong.oh@gogo-ssing.com>

* feat: add name option to view column (#5962)

Add 'name' option to @ViewColumn to align with @column
and allow a different property name for a column in a view.

Closes #5708

* docs: fix grammatical error (lets => let's) (#5954)

Change "lets" to "let's" in the sentence "since we have errors lets [sic] rollback changes we made".

* fix: HANA - SSL options, column delta detection mechanism (#5938)

* fix: insert and update query builder to handle mssql geometry column correctly (#5947)

* [UPDATE] Update insert and update query builder to handle mssql geometry column with SRID properly

* [FIX] Fix indentation with spaces

* [FIX] Fix semicolon, and quota characters

* [FIX] Fix semicolon

Co-authored-by: Paul Kwok <wkkwok@uacs.hk>

* refactor: refactor deprecated new Buffer to Buffer.from (#5924)

* docs: update connection-options.md (#5902)

The "entitySchemas" connection option doesn't work. Instead, schemas are recognized when added to the "entities" connection option. The docs were updated to reflect that.

* feat: added support for NOWAIT & SKIP LOCKED in Postgres (#5927)

* Added support for NOWAIT & SKIP LOCKED in Postgres

* fix merge typo

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>

* fix: use correct typings for the result of `getUpsertedIds()` (#5878)

This method returns an object with `_id` and `index` properties, according to [the description of `BulkWriteResult`](https://docs.mongodb.com/manual/reference/method/BulkWriteResult/#BulkWriteResult.upserted).

* feat: Aurora Data API - Postgres Support (#5651)

* Data API Postgres WIP

* Refactored the code to be more supportable

* feat: Add soft remove and recover methods to entity (#5854)

* Implement soft remove and recover for entity.

* Add test for entity soft remove and recover.

* Fix entity soft remove and recover test.

* docs: missing word in docs (#5793)

* fix: migrations being generated for FK even if there are no changes (#5869)

* Fix migrations being generated for FK even if there are no changes

* Fix tslint errors

Co-authored-by: Svetlozar Argirov <ext-svetlozar@getitdone.co>

* fix: wrong table name parameter when not using default schema (#5801)

* Fix wrong table name parameter when not using default schema

* Fix linting issue

Co-authored-by: Igor Aguiar Rodrigues <igor@devix.co>

* fix: prevent TypeError when calling bind function with sql.js 1.2.X (#5789)

* docs: fix many-to-many example table (#5717)

- include question entity text column, which is missing in the current docs

* docs: add the missing text in the sentence (#5736)

* feat: aurora Data API - Support for AWS configuration options through aurora driver (#5754)

* AWS.ConfigurationOptions added to AuroraDataApiConnectionOptions

Updated typeorm-aurora-data-api-driver to 1.2.0 for the support of the new constructor argument.

* Unit test for aurora-data-api driver and validation that service config options are passed

* Leaving skip to false for aurora seems to fail some unit tests

* fix: update Entity decorator return type to ClassDecorator (#5776)

I've been making a class decorator composer function, and Function type is not specific enough. I'll augment it locally for the time being.

I suppose some other types would have to be updated as well, hopefully there's a CI in place

* fix: calling EntityManager.insert() with an empty array of entities (#5745)

As described in issue #5734, the current behaviour seems like an oversight and inconsistent with save() and remove() which already have this handled as a special case.

Test Plan: npm test, and more specifically npm test -- --grep='#5734'

Closes: #5734

* fix: sha.js import (#5728)

* Fix sha.js import

* synthetic default exports

* add module interop

* fixup import

* fixup indentation

* docs: note about bigint type being mapped to a string (#5730)

* docs: added enumName property (#5731)

Related to #5729

* feat: names of extra columns for specific tree types moved to NamingStrategy (#5737)

* docs: update FindOneOptions lock property comment (#5701)

* feat: PG allow providing a function for password (#5673)

* fix: redundant undefined parameters are not generated in migration files anymore (#5690)

* fix: redundant undefined parameters are not generated anymore

* fixed lint issues

* fix: provide a default empty array for parameters. (#5677)

The statement bind method in sqljs assumes that either an object or an array has been provided.

* fix: respect database from connection urls (#5640)

* fix: respect database from connection urls

database names can be defined in the options object. Now also connection urls that contain a database can be used to have the database set in the drivers object.

Closes: #2096

* only disconnect connection if connected.

* revert changes.

* fix credentials for testing

* create connection by lib function

* check typeorm config during testing to check whether a mysql database is available

Co-authored-by: julius <julius.friedrich@shift-f3.com>

* docs: documentation for "-c" connection option (#6080)

Add documentantion for this #1333

* fix: Unknown fields are stripped from WHERE clause (issue #3416) (#5603)

* fix: Unknown fields are stripped from WHERE clause (issue #3416)

* update non-exist columns test

* fix: columns with transformer should be normalized for update (#5700)

* fix: columns with transformer should be normalized for update

Closes: #2703

* fix: test case to use separate logger per connection

* fix: test dummy column type

int means int8 on cockroachdb. Explicitly specify int4.

* fix: use string instead of number for test

int4 doesn't work for all dbs. Use string because it's universal.

* fix: let typeorm infer proper test column type

Co-authored-by: Ryan Shea <ryan.shea@alphaledger.com>

* perf: Optimized version of EntityMetadata#compareIds() for the common case (#5419)

* perf: Optimized version of EntityMetadata#compareIds() for the common case

* Extract `compareIds()` into `OrmUtils` and use it instead of `.deepCompare()` where applicable

* Use optimized path in compareIds() also when .id has type "number"

* Add return type to signature of deepCompare() and compareIds()

* made a proper check

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>

* fix: 'in' clause case for ORACLE (#5345)

* fixing 'in' clause case for ORACLE

* fix == to ===

Co-authored-by: Gerwin Brunner <gerwin.brunner@vilango.com>

* docs: fix typo (#6083)

"plan javascript object" -> "plain javascript object"

* removed .only

* docs: updated link to TS node (#6090)

Previous URL returns a 404

* fixed sap issue with dates

* fix: prototype pollution issue (#6096)

* version bump

* closes #6110 (#6117)

added `AuroraDataApiPostgresDriver` to `BrowserDisabledDriversDummy.template` to fix typeorm not compiling when using browser target

* feat: add AWS configurationOptions to aurora-data-api-pg connector (#6106)

Co-authored-by: Sergio Durban Belmonte <sdurban@leadtech.com>

* docs: add a link to TypeORM website (#6143)

Weirdly search sent me here, and it took a while to find the real TypeORM website.

* fix: revert fix handle URL objects as column field values (#6145)

This reverts commit 50a0641.

* fix: SqlQueryRunner.hasColumn was not working (#6146)

* fixed #5718

* removed .only

* feat: add postgres connection timeout option (#6160)

There was no documented way of setting a connection timeout for the
postgres driver. We recently ran into an issue with our network that
caused a container to hang indefinitely attempting to connect to
postgres.

We managed to resolve the issue by setting 'connectionTimeoutMillis' in
the 'extra' field of our connection options. This approach does not
appear to be documented anywhere.

Seeing that MongoDB and MySQL drivers both support a connection timeout
as part of the documented API, we felt it made sense to add a similar
option to the Postgres driver and hopefully avoid some headaches down
the road.

This commit adds a 'connectTimeoutMS' option to the postgres driver
that gets translated to the appropriate field for the pg library. It
also updates the documentation to reflect this new option.

Because the default behavior of the underlying pg library is to attempt
to connect indefinitely, we didn't feel like it was a safe change to
introduce a default timeout, even if that's more sane behavior.

As mentioned earlier, both the MySQL and MongoDB drivers support a
connection timeout option. MySQL uses 'connectTimeout' while MongoDB
uses 'connectTimeoutMS'. We went with 'connectTimeoutMS' as to not
introduce yet another name for a connection timeout, and because the
'MS' suffix makes it clearer what is expected.

We hope a future PR may adjust the MySQL connection options to adopt the
same name, but will leave that up to someone with a stronger opinion.

* docs: fix undefined `repository` variable on docs (#6221)

The `repository` variable is not defined in the first Data Mapper pattern example

* added sap hana note

* docs: fixed small error (#6258)

* docs: replace body-parser with express built-in parser (#6257)

JSON body parser is now built-in by default (>4.16.0), hence no need for body-parser

* docs: fix markdown typo (#6359)

* docs: update relations-faq.md (#6355)

Grammatical error

* fix: resolve missing decorators on shim (#6354)

Closes: #6093

* docs: Add advance subdocument query documentation (#6344)

Example for querying subdocuments and array of subdocuments

* fix: remove unnecessary optionality from Raw operator's columnAlias argument (#6321)

* fix: properly override database url properties (#6247)

* fix: properly override database url properties

Closes #4878

* test: add test for overriding url options

* feat: support cjs extension for ormconfig (#6285)

* support cjs extension for ormconfig

* fix linting errors

* handle cjs extensions in class loader

* fix: insert IN(null) instead of IN() when In([]) empty array for mysqlDriver (#6237)

fix: lint warning

Co-authored-by: shitong.zheng <shitong.zheng@shopee.com>

* chore(deps): bump lodash from 4.17.15 to 4.17.19 (#6408)

Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](lodash/lodash@4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* docs: update using-cli.md (#6407)

* docs: Added one-to-one-relations.md & many-to-one-one-to-many-relations.md cascades link (#6406)

* docs: one-to-one-relations.md cascades link

* docs: many-to-one-one-to-many-relations.md cascades link

* fix: Query builder makes query with joins, without limit for inherited entities (#6402)

Closes: #6399

Co-authored-by: Gregory Komagurov <Komagurov.GV@gazprom-neft.ru>

* fix: decorators should implement the official TypeScript interface (#6398)

Closes: #5922

* docs: fixed small typo error (#6418)

* fix: exporting missing load event (#6396)

* fix: support multiple `JoinColumn`s in EntitySchema (#6397)

update type definition and schema transformer
so that - like the decorator - the EntitySchema can define
composite `JoinColumn` definitions

Closes: #5444

* fix: correctly parse connection URI with query params (#6390)

ref #6389

Co-authored-by: Coroliov Oleg <coroliov.o@goparrot.ai>

* fix: getPendingMigrations isn't properly working (#6372)

getPendingMigrations currently returns the executed migrations instead of the non-executed ones.

* feat: add better-sqlite3 driver (#6224)

* feat: better-sqlite3 driver which is significantly faster than node-sqlite3
* test: added all tests for sqlite to better-sqlite3
* test: "query runner > drop column" modified compatible
* docs: added better-sqlite3 related docs

* style: use LF instead of CRLF in BetterSqlite3 modules (#6433)

* fix: pass formatOptions to Data API Client, fix extensions (#6404)

* fix(aurora): pass formatOptions to Data API Client, fix UUID type support and all other extensions

* fix(aurora): refactored the code to avoid duplication (#1)

* fix(aurora): refactored the code to avoid duplication

* added sponsors section

* updated sponsors section

* Update README.md

* ads styling fixes

* docs: fix grammatical error (#6458)

* chore: use eslint instead of tslint (#6452)

* fix: @jointable does not respect inverseJoinColumns referenced column width (#6444)

* fix: provide width to ColumnMetadataArgs for JoinTable

@jointable does not respect inverseJoinColumns referenced column width

Closes: #6442

* fix: address linting errors, replaced single quotes

* fix: add await so that promises are resolved

* fix: add connection close for migration connection

* chore: update slack invite link (#6447)

* chore: update pg to 8.3.0 (#6462)

update pg to the currently latest version which has support for
node 14

* fix: mysql migration: make sure the indices sql which left-join be the same database (#6426)

* chore: use circleci for all builds (#6460)

drop travis-ci from the builds by using the matrix
functionality in circleci to run multiple node versions
plus refactor the way builds work to allow splitting
and joining builds together more easily

* doc: change @types/node install to install in dev dependencies (#6485)

* feat: implement postgres ltree (#6480)

This new feature implements support for the postgres extension ltree

Closes: #4193

* docs: remove out-of-place 'example:' (#6468)

* modify docs/relational-query-builder.md

* test: remove hardcoded test from github issue tst 2096 (#6463)

the test had assumed the username, password, host, and port of
the mysql server

this update changes that so the test instead uses the config properly
while still checking that the test works as expected

* doc: use CircleCI for CI badge (#6516)

* use CircleCI for CI badge

Updates the badge to point at CircleCI for the passing / failing status

* doc: use circleci badge in README (zh_CN)

* doc: use circleci badge in readme in docs (zh_CN)

* doc: use circleci badge under index in docs (zh_CN)

* docs: Update slack invite link for typeorm.io support page (#6524)

closes #6523

* docs: update supported-platforms.md (#6545)

* docs: fix typos (#6538)

* chore: discourage questions as issues (#6535)

* chore(deps-dev): bump class-transformer from 0.2.3 to 0.3.1 (#6532)

Bumps [class-transformer](https://github.com/typestack/class-transformer) from 0.2.3 to 0.3.1.
- [Release notes](https://github.com/typestack/class-transformer/releases)
- [Changelog](https://github.com/typestack/class-transformer/blob/develop/CHANGELOG.md)
- [Commits](typestack/class-transformer@v0.2.3...v0.3.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build: use `npm install` to work around npm/cli#558 (#6571)

the lockfile we use was generated on a mac & includes
`fsevents` as a dependency. while this is optional for
OSX it's not available for linux & this causes problems
with the `npm ci` command.  npm v7 will correct this
but until we're using that we should switch to
using npm install

* chore: pin version of cockroach to a known good version (#6585)

* chore: remove uneccessary cockroachdriver calls in view-entity tests (#6587)

this is a backport of changes from the `next` branch

* fix: change InsertQueryBuilder.values() with an empty array into a no-op (#6584)

Change InsertQueryBuilder.values() with an empty array into a no-op instead of the current behavior of inserting a row of DEFAULT values.

Closes: #3111

* fix: DeepPartial with any and {[k: string]: any} (#6581)

* test: Test DeepPartial with any and {[k: string]: any}

This tests #6580.

* fix: DeepPartial with any and {[k: string]: any}

Fixes #6580.

* build: use docker-compose for database services (#6602)

* removing gitads

* docs: update zh_CN link path (#6652)

* update zh_CN link path

* Update README-zh_CN.md

* feat: FileLogger accepts custom file path (#6642)

This allows users to override default log filepath and save typeorm logs in a custom location

Closes: #4410

* chore: instead of require, import chalk from chalk (#6637)

* fix: pass `ids_` to alias builder to prevent length overflow (#6624)

* feat: support absolute paths in migrationsDir for the CLI (#6660)

Right now the CLI will ALWAYS prepend the CWD to `options.cli.migrationsDir`. 

This prevents us from using absolute paths there. 

How would we feel about changing that to support absolute paths (by only prepending CLI if the path DOES NOT start with "/")? If we're open to it, I'm happy to make the change for the other CLI commands as well.

* refactor: only use PlatformTools.load for optional dependencies (#6630)

* fix: Migration issues with scale & precision in sqlite/sql.js (#6638)

* fix: Migration issues with scale & precision in sqlite/sql.js

Specifying precision or scale properties on columns with SQLite/sql.js would result in migrations being generated even on an unchanged schema.

This was due to the precision and scale arguments not correctly being inferred when reading the table. This change handles scale and precision in the same way that "length" was already being correctly handled.

Fixes #6636

* awaited the test

* fix missing async

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>

* added directory typing

* added directory typing

* fix: Unnecessary migrations for fulltext indices (#6634)

* fix: Unnecessary migrations for fulltext indices

Fixes #6633 (see issue for root cause explanation)

* test: Enable all tests

* refactor: Add `isFullTextColumnTypeSupported()` method to Driver interface

* fix: Include isFullTextColumnTypeSupported method in SqlServerDriver

* fix: get correct insert ids for multiple entities inserted (#6668)

* fix: (sqlite) get correct increment primary key for mutiple entities inserted

Closes: #2131

* fix: (mysql) get correct increment primary key for mutiple entities inserted

Closes: #5973

* test: add test case for fix of #2131

* docs: update note about sqlite lastID

* fix: make only a single SELECT to get inserted default and generated values of multiple entities (#6669)

* fix: re-select inserted default and generated values with a single SELECT

closes #6266

* test: add test case for fix of #6266

* fix lint error

* fix: Child entities not being saved correctly with cascade actions (#6219)

* fix: Child entities not being saved correctly with cascade actions

* fixes tslint complains

* fix: update query deep partial TypeScript definition (#6085)

User should be able to pass function if field is an array

* build: add oracle to CI (#6623)

* build: add oracle to build database services

* only enable test 1972 for MySQL

* disable github issue 3118 for oracle

* test: escape table name for Github #4410 (#6672)

* fix: add missing schema for OracleDriver (#6673)

* docs: update select-query-builder.md (#6681)

Found a typo on the "Adding WHERE expression" section: user.firstName is used in the SQL snippet where you actually meant user.id

* docs: update query runner examples (#6680)

* refactor: add two examples to use timesteamp when create migration using js/ts

* refactor: add two examples to use timesteamp when create migration using js/ts

* test: Testing that the discriminatorValue gets saved for ChildEntity when saved by cascade (#6671)

* test: Testing that the discriminatorValue gets saved for ChildEntity when saved by cascade

* test: Update assertions to not be specific to retrieval order

Co-authored-by: Gareth Parker <gareth.parker@ros.gov.uk>

* fix: handle 'error' events from pool connection (#6262)

* fix: unnecessary migrations for unsigned numeric types (#6632)

* fix: Unnecessary migrations for unsigned numeric types

In MariaDB, unsigned numeric types (``<tiny,small,medium>int`) without an explicit `width` property set would generate migrations on every run. This is due to an error in setting the default width for unsigned types.

Fixes #2943

* test: Enable all tests

* refactor: Move isDefaultColumnWidth() method out of BaseQueryRunner

See #6632 (review) for discussion as to why.

* fix: Correct unsigned int behaviour for MySQL 5.7

* fix: Correct position of zerofill check

Plus stylistic change based on code review

* version bump

* fix: sql.js v1.2+ don't support undefined parameters (#6698)

before sql.js 1.2 it seems undefined were treated as if they were null,
but as of 1.2 they cause a query error & fail to execute

this change swaps out any undefined parameters with `null`s

closes #5720

* fix: hdb-pool is not namespaced under @SAP (#6700)

closes #6697

* feat: create EntityTarget and use instead of EntitySchema / ObjectType / etc (#6701)

* chore: bump all package versions except typescript (#6696)

also updates some tests to support typing changes

* feat: Beautify generated SQL for migrations (#6685)

* feat: Beautify generated SQL for migrations

Allows user to pass an optional flag to beautify generated SQL for migrations

Closes: #4415

* fixed formatter version

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>

* feat: backport SQLite Busy handler & WAL mode enable (#6588)

* added sqlitebusy handling logic

* added sqlite wal mode enable logic

* cleaner if block

* move pragma journal mode setting to driver connection

* add enable-wal test

Co-authored-by: Umed Khudoiberdiev <zarrhost@gmail.com>

* fix: prevent multiple `release` listeners in PostgresQueryRunner (#6708)

move on-error-release code to the queryRunner connect function
so we only need to have one listener per query runner on each
connection - cutting donw the number of listeners total &
preventing a problem with too many listeners

closes #6699

* docs: correct the comment of OneToMany decorator (#6712)

* fix: backport FindOperator return types (#6717)

the `next` branch added return types to `FindOperator`s and
this backports that change

* style: backport style fixes in next to cut down on churn (#6715)

the `next` branch has a number of style fixes for the project aroundnd
whitespaces - this pulls them into `master` to cut down on the files
changes between the two branches

* update FindOptionUtils to fix typing

* update test to handle withDeleted living under FindOptions.optionswithDeleted lives under options now

* default import for Observable

* work around typing preventing test 3416 from running

* fix test 6399

* SchemaTransformer requires a connection now

* correctly handle composite PK & failed entity loads

* FindCriteriaNotFoundError must extend EntityColumnNotFound

* fix findOneOrFail passing invalid data to findOne

* drop generic from concrete EntityManagers

in the main branch for the project we have linting working as
expceted & it catches the generic `Entity` on these concrete
implementations as an unused definition - which it is

to fix that linting error this change removes the generic
hint from the concrete EntityManager

* update 4415 to address cockroachDB changes

CDB now uses INT4 instead of INT

* chore: explicitly pull in typescript 3.9 (#6724)

this bumps the version of typescript accepted to >=3.9.7,<4.0
we were implicitly pulling in that version (per the package-lock.json)
so this just codifies it in the package.json as well

* test: disable logging for test 1960 (#6721)

this test was emitting logs for no real reason so this removes the
`logging: true` when creating the testing connection

* fix: migration:generate issue with onUpdate using mariadb 10.4 (#6714)

* Update MysqlQueryRunner.ts

In Mariadb the extra information of a DDL is in upper case and in javascript String.indexOf() function is case sensitive, because of that when you generate a new migrations  in mariadb it always create a line to update  "onUpdate" lines.

 example:
```sql
CREATE TABLE `test` (
  `test_id` int(11) NOT NULL AUTO_INCREMENT,
  `test_update` timestamp() NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`test_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
```

When you try to generate a new migration always create the next migration file:

```ts
import { MigrationInterface, QueryRunner } from 'typeorm';

export class test261600082802966 implements MigrationInterface {
  name = 'test261600082802966';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      'ALTER TABLE `test` CHANGE `test_update` `test_update` timestamp() NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP()'
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      'ALTER TABLE `test` CHANGE `test_update` `test_update` timestamp() NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE current_timestamp()'
    );
  }
}
```
Entity file test.ts
```ts
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

@entity()
export class test extends BaseEntity {
  @PrimaryGeneratedColumn({})
  test_id: number;

  @column({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP()',
    onUpdate: 'CURRENT_TIMESTAMP()',
    nullable: false,
  })
  test_update: Date;
}
```

* Update MysqlQueryRunner.ts

* add test to issue 6714

* Update MysqlQueryRunner.ts

* Update issue-6714.ts

Co-authored-by: jesusegado <j.fernandez@lionline.de>

* docs: update many-to-many-relations.md (#6725)

* Update many-to-many-relations.md

* Update many-to-many-relations.md

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>

* feat: add option to pass postgres server notices to client logger (#6215)

This feature for postgres connections means when you pass the logNotifications option, db notices and notifications will be passed to the logger with info log level

Closes: #2216

* fix: ensure browser builds don't include any non-browser modules (#6743)

currently we pull in BetterSqlite3Driver, SqliteDriver, and a few other
drivers & files that aren't possible to use in a browser context.
this change adds some more browser compatibility features so
webpack builds targeted at browsers will be able to complete

closes #6739

* fix: count() method for multiple primary keys for cockroachdb (#6745)

* fix: count() method for multiple primary keys for cockroachdb

Cockroachdb does not support concat() for different types at the moment.
To fix this problem, each primary key is cast to the text type.

* fix: add doublequote

* fix: add doublequote

* test: update and move tests for count() method for multiple primary keys

* fix: count() method for multiple primary keys for oracle

Oracle does not support CONCAT() for more than 2 arguments at the moment.
To solve this problem, operator || is used instead of CONCAT().

* refactor: create a ReplicationMode type and update function defs (#6747)

create a type to track ReplicationMode instead of writing out
`"master"|"slave"` everywhere.

update to drop the default from the QueryRunner constructor
as they will always receive the mode from the driver when
it's part of the QueryRunner

also drop the default from Driver.createQueryRunner in the
implementations - the interface mandates the mode to be defined
so it will never be omitted anyway

also drop the explict "master" from any connection.createQueryRunner
calls so we leave it either the default or `slave` when needed

all of this makes it easier to eventually migrate to
other naming convetions for the replication mode
should it be deemed the right path to go down

* refactor: drop promise utils (#6746)

* stop using PromiseUtils.create & extractValue as they're doing nothing

because we never use PromiseUtils.create, PromiseUtils.extract was technically
never used either - the only case we were using this was in a test
where we can replace it with Promise.resolve

* stop using PromiseUtils.settle in test 1014

there was no reason to use this call in the test
as it was not using the results and only used the `Promise.all`
functionality

* use Promise.all instead of PromiseUtils.runInSequence in tests

in these cases of PromiseUtils.runInSequence in tests there was no need
for us to be running them in sequence - so instead we could use Promise.all
& Array.map for a replacement.  removes the dependency on PromiseUtils &
also speeds up our tests

* run tests sequentially for those that deal with ActiveRecord

because the activerecord mechanism creates a "global" scope through
the class that ActiveRecord is applied to we have to run through the
connections sequentially or end up with them being all over the place
as far as what activerecord model is connected to what connection

* use standard async/await + for/of instead of runInSequence

in cases where actual order of the runs matter we can do for/of
and then await any of the results - because none of the usages of
runInSequence that rely on the correct order actually use the results

* use Promise.all on runInSequence cases where order doesn't matter

* drop PromiseUtils altogether

* sequentially run when dealing with QueryRunner

queryrunner is not 'thread-safe' or async safe

* drop the test to lookup by Promise

before, the test wasn't validating that you could lookup by promise
the test was verifying that if you used something that wasn't a promise
but instead had a magic __value__ variable you'd get a lookup

that's not a promise, unfortunately

I can't find that a promise may be passed into the find options anywhere
in the documentation so I've removed this test

* fix: resolve issues ora-00972:identifier is too long (#6751)

* fix: resolve issues ora-00972:identifier is too long

Closes: #5067

* fix: ensure that this changes applies just for Oracle Driver

Closes: #5067

* fix test - remove `.only` & set the `enabledDrivers` to oracle

* simplify test case

Co-authored-by: Murat Gundes <guendes.murat@indivumed.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Daniel Hritzkiv <daniel.hritzkiv@gmail.com>
Co-authored-by: tejovanthWork <49153303+tejovanthWork@users.noreply.github.com>
Co-authored-by: urdeveloper <urdeveloper@users.noreply.github.com>
Co-authored-by: 蔡小伦 <sliuqin@gmail.com>
Co-authored-by: aRtoo <raphaelg2012@gmail.com>
Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
Co-authored-by: artemnih <23387542+artemnih@users.noreply.github.com>
Co-authored-by: Štefan Malček <stefan.malcek1@gmail.com>
Co-authored-by: Diego <allan_diego@hotmail.com>
Co-authored-by: Jérôme Steunou <jerome.steunou+github@gmail.com>
Co-authored-by: beqa7137 <Beka.Goderdzishvili010@ens.tsu.edu.ge>
Co-authored-by: Bradley Odell <btodell@hotmail.com>
Co-authored-by: Sam Bender <rednebmas@users.noreply.github.com>
Co-authored-by: Andrej Badin <contact@andrejbadin.com>
Co-authored-by: Max Coplan <mchcopl@gmail.com>
Co-authored-by: Domagoj <off.vukovic@gmail.com>
Co-authored-by: ohjeyong <ojy6042@kaist.ac.kr>
Co-authored-by: JeyongOh <jeyong.oh@gogo-ssing.com>
Co-authored-by: Daniel <dsbert@codecantos.com>
Co-authored-by: Patrick Pan <patrickhpan@users.noreply.github.com>
Co-authored-by: Simon Elsbrock <simon@iodev.org>
Co-authored-by: waikuen2010 <waikuen2010@gmail.com>
Co-authored-by: Paul Kwok <wkkwok@uacs.hk>
Co-authored-by: Marko Kaznovac <kaznovac@users.noreply.github.com>
Co-authored-by: Tareq Dayya <41693150+tareqdayya@users.noreply.github.com>
Co-authored-by: Kamil Burzynski <Nopik@users.noreply.github.com>
Co-authored-by: Jesse Pinho <jesse@jessepinho.com>
Co-authored-by: Arseny Yankovsky <p44gr10@gmail.com>
Co-authored-by: Janno Stern <jannostern@users.noreply.github.com>
Co-authored-by: Serż Kwiatkowski <scadgek@live.com>
Co-authored-by: Svetlozar Argirov <zarrro@gmail.com>
Co-authored-by: Svetlozar Argirov <ext-svetlozar@getitdone.co>
Co-authored-by: Igor Aguiar Rodrigues <igor_aguiar@yahoo.com.br>
Co-authored-by: Igor Aguiar Rodrigues <igor@devix.co>
Co-authored-by: Florian Bernard <florian.bernard64@gmail.com>
Co-authored-by: Esa Koskinen <esakoskin2@gmail.com>
Co-authored-by: Richard Onengiye <31253707+klevamane@users.noreply.github.com>
Co-authored-by: cklam2 <cklam2@outlook.com>
Co-authored-by: GrayStrider <43771776+GrayStrider@users.noreply.github.com>
Co-authored-by: Lovro Puzar <l.puzar@synthace.com>
Co-authored-by: Guy Bedford <guybedford@gmail.com>
Co-authored-by: golergka <golergka@Gmail.com>
Co-authored-by: Roland Venesz <roland@venesz.de>
Co-authored-by: Victor Koronen <Koronen@users.noreply.github.com>
Co-authored-by: Robbie Trencheny <me@robbiet.us>
Co-authored-by: Oleg <qu1ze34@gmail.com>
Co-authored-by: graham- <graham.fennell@skilitics.com>
Co-authored-by: ant45de <julius_friedrich@gmx.de>
Co-authored-by: julius <julius.friedrich@shift-f3.com>
Co-authored-by: Mateus Pereira <mateuspereira97@icloud.com>
Co-authored-by: Johannes Sjoberg <johannes.sjoberg@live.se>
Co-authored-by: Ryan Shea <ryansworld10@gmail.com>
Co-authored-by: Ryan Shea <ryan.shea@alphaledger.com>
Co-authored-by: Reto Kaiser <reto@retoonline.com>
Co-authored-by: Gerwin Brunner <gerwin.brunner@gmail.com>
Co-authored-by: Gerwin Brunner <gerwin.brunner@vilango.com>
Co-authored-by: Json Choi <1890mah@gmail.com>
Co-authored-by: JP Bulman <jpbulman@wpi.edu>
Co-authored-by: Chris <chriswep@users.noreply.github.com>
Co-authored-by: Sergio Durban Belmonte <sergio@durban.cat>
Co-authored-by: Sergio Durban Belmonte <sdurban@leadtech.com>
Co-authored-by: Mike MacCana <mike.maccana@gmail.com>
Co-authored-by: Jack Wink <57678801+mothershipper@users.noreply.github.com>
Co-authored-by: Giancarlos Isasi <giancarlos.isasi@gmail.com>
Co-authored-by: 0xflotus <0xflotus@gmail.com>
Co-authored-by: Mustapha Yusuff <mustaphee94@gmail.com>
Co-authored-by: Nipodemos <nipodemos13@gmail.com>
Co-authored-by: Rahul Soni <rahul.soni3883@gmail.com>
Co-authored-by: Pedro Silveira Lopes <silventino.dev@gmail.com>
Co-authored-by: IAGO BRAYHAM <iagobrayhamcunha@hotmail.com>
Co-authored-by: yokomotod <yokomotod@gmail.com>
Co-authored-by: Angel J Piscola <angelpiscola@gmail.com>
Co-authored-by: Dan Pickett <dpickett@users.noreply.github.com>
Co-authored-by: Ryan <zstiu@foxmail.com>
Co-authored-by: shitong.zheng <shitong.zheng@shopee.com>
Co-authored-by: Fernando Moreira <github@nandomoreira.dev>
Co-authored-by: Pouria Tajdivand <tajpouria.dev@gmail.com>
Co-authored-by: Gregory <grkov90@gmail.com>
Co-authored-by: Gregory Komagurov <Komagurov.GV@gazprom-neft.ru>
Co-authored-by: SakirSoft <sahin@sahin-vardar.net>
Co-authored-by: Saulo S. Toledo <saulotoledo@gmail.com>
Co-authored-by: Coroliov Oleg <1880059+ruscon@users.noreply.github.com>
Co-authored-by: Coroliov Oleg <coroliov.o@goparrot.ai>
Co-authored-by: Akos Vandra <axos88@users.noreply.github.com>
Co-authored-by: K024 <2382146546@qq.com>
Co-authored-by: Nathan Lapierre <nathan@lapierre.ca>
Co-authored-by: Michael <mgolden@revspringinc.com>
Co-authored-by: Carlos <echoulen@gmail.com>
Co-authored-by: Alcides Augusto <aaugusto.kd@gmail.com>
Co-authored-by: Thomas Sawkins <sawkins.tom@gmail.com>
Co-authored-by: Izzuddin Ahsanujunda <the.zlood@gmail.com>
Co-authored-by: Ilan <36084092+ilanolkies@users.noreply.github.com>
Co-authored-by: Ashwin Ramaswami <aramaswamis@gmail.com>
Co-authored-by: Lachlan McCarty <lachlan@lachm.com>
Co-authored-by: Matthias Kunnen <matthias.kunnen@gmail.com>
Co-authored-by: xgqfrms <xgqfrms@outlook.com>
Co-authored-by: Arty <26905074+artysidorenko@users.noreply.github.com>
Co-authored-by: Tomas Reimers <tomas@tomasreimers.com>
Co-authored-by: Michael Bromley <michaelbromley@users.noreply.github.com>
Co-authored-by: ZBAGI <zbagi@poczta.fm>
Co-authored-by: Sebastian Domagała <sdomagala@users.noreply.github.com>
Co-authored-by: Michael <pirouet@users.noreply.github.com>
Co-authored-by: Tulio Molina <tuliojose8@gmail.com>
Co-authored-by: Cristian Magalhães <cristian123105@gmail.com>
Co-authored-by: Gareth Parker <blackfireweb@gmail.com>
Co-authored-by: Gareth Parker <gareth.parker@ros.gov.uk>
Co-authored-by: Jaan Oras <jaan.oras@gmail.com>
Co-authored-by: Umed Khudoiberdiev <zarrhost@gmail.com>
Co-authored-by: Juuso Mikkonen <juusaw@users.noreply.github.com>
Co-authored-by: jesussegado <jesusegado@gmail.com>
Co-authored-by: jesusegado <j.fernandez@lionline.de>
Co-authored-by: Louai Hamada <47286486+Louai-H@users.noreply.github.com>
Co-authored-by: Temnov Aleksey <temnov_aleksei@mail.ru>
Co-authored-by: Murat Gundes <guendes.murat@indivumed.com>
zaro pushed a commit to zaro/typeorm that referenced this issue Jan 12, 2021
* fix: respect database from connection urls

database names can be defined in the options object. Now also connection urls that contain a database can be used to have the database set in the drivers object.

Closes: typeorm#2096

* only disconnect connection if connected.

* revert changes.

* fix credentials for testing

* create connection by lib function

* check typeorm config during testing to check whether a mysql database is available

Co-authored-by: julius <julius.friedrich@shift-f3.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.