994 Commits

Author SHA1 Message Date
Lee Allen
a2ab754eed Bugfix/rollback all wrong order (#3172)
* Fix rollback all bug attempting to perform rollback in chronological order

* Set up second migration to depend on first migration so when rolling back order is tests

* Add test for rollback all only running completed tests in reverse chronological order
2019-05-01 00:21:49 +02:00
Igor Savin
fe6083eda4 Support nullable timestamps on MySQL (#3100)
* Add test to recreate the issue

* Improve test, add some documentation

* Improve test

* Add explicit nullable flag to column

* Set nullability explicitly on MySQL to deal with timestamp edge case

* Use same assertion for everything
2019-03-30 15:58:56 +02:00
Andrew Schmadel
b15ee3def1 make unionAll()'s call signature match union() (#3055)
* make unionAll()'s call signature match union()

consolidates the logic used by union() and unionAll(), allowing the two to be used interchangeably

* use spread args instead of arguments array

* Fix unionAll spread arguments
2019-03-29 19:55:32 +02:00
Igor Savin
e7ed005995
Fix queryContext not being passed to raw queries (#3111)
* Fix queryContext not being passed to raw queries

* Add unit case for transaction as well
2019-03-19 00:45:08 +01:00
elunic
19926d8eba [#3033] fix: sqlite3 drop/renameColumn() breaks with postProcessResponse (#3040)
* [#3033] fix: sqlite3 drop/renameColumn() breaks with postProcessResponse

* When postProcessResponse is configured, and client.processResponse()
returns a Promise (e.g. for custom cases such as sqlite3 dropColumn()),
then that Promise is not awaited, but handed to postProcessResponse,
which might break is (e.g. with Objection's knexSnakeCaseMappers()).

* when reinserting data in the modified table, the rows are now being
handled with the "mapped" identifiers (instead of the unmapped)

* add tests, fix hasColumn

* add hasColumn tests for add mysql + snakeCaseMappers

* Improve tests and fix more cases related to processing

* Fix SQLite-specific tests

* MySQL is not case-sensitive, pg is
2019-03-13 22:58:59 +01:00
Igor Savin
24fcf27e05
Fix transaction support for migrations (#3084)
* Fix transaction support for migrations

* Clarify warning

* Clarify warning message

* Simplify logic, make enabling/disabling more consistent

* Fix tests

* Fix test

* Reduce duplication
2019-03-13 22:47:43 +01:00
Pierre Voisin
0aacab50be Fix for #2998 - Migrator & TypeScript (#3041)
* Fix `#listAllAndCompleted` not considering `loadExtensions` in migrator configuration (#2998)

* Add unit test

* Fix linting
2019-03-09 23:39:55 +01:00
EthanHur
0db785949b add test that clearing offset (#2954)
* add test that clearing offset

* fix typo
2019-03-05 16:25:30 +01:00
Igor Savin
1b39d67550
Tests for drop-and-recreate with async/await (#3083)
* Add test for drop-and-recreate with async/await

* Add some tests with schema

* Use correct migrations

* Add tests with promise chains for comparison

* Fix migration

* Fix Node 6 compatibility
2019-03-05 01:03:51 +01:00
Randy Garces
c2bf7a375c MSSQL removes support column width/length on data type int and tinyint (#2738)
* MSSQL remove support column width/length on data type int

- fixes error `Cannot specify a column width on data type int`
- ignore length even if pass as agrument

* Add integration test for numeric lengths

* Fix syntax

* Add test that actually executes SQL

* Fix failing tests

* Fix tests
2019-03-05 01:02:06 +01:00
Igor Savin
b269e45842
Update dependencies (#3085)
* Update dependencies

* Fix linting errors
2019-03-04 01:40:35 +01:00
thekuom
71e097b663 add intersect() (#3023)
* add intersect()

* update intersect integration tests to validate results

* use const instead of var, remove .only in test, remove commented out type
2019-03-03 20:57:40 +01:00
EthanHur
dfe01298d2 mysql warn .returning() does not have any effect. (#3039)
* mysql warn `.returning()` does not have any effect.

* add test if warning is emitted or not
2019-03-03 14:53:06 +02:00
Igor Savin
26868f864c Fix event listener duplication (#2982)
* Fix event listener duplication. Start executing more tests in CI; fix broken test.

* Fix listener

* Fix listener

* Fix Node 6 support

* There doesn't seem to be a clear way to fix listener behaviour in Node 6, so let's just ignore it for the time being, especially considering that we are dropping support for Node 6 in April anyway.

* Update migration guide
2019-01-31 07:23:05 +02:00
James Beavers
816695bdbf Always use well documented pg client query() config argument (#3004)
* always use well documented query config argument

* fix options typo
2019-01-19 13:26:51 +02:00
Valentin Agachi
2430ae0c54 Add verbose option to CLI commands (#2887) 2018-12-30 17:11:57 +01:00
Igor Savin
9daf7f3d09
Display name of a failed seed (#2973) 2018-12-27 18:20:13 +01:00
André Cruz
c2dff7f843 Implemented extra boolean param for rollback() (#2968)
* Implemented extra boolean param for rollback()
Extra parameter allows all migrations to be rolled back.

* Removed spurious log

* Removed stray debugger instruction

* Moved to arrow functions
2018-12-20 17:05:28 -06:00
Igor Savin
02e327c51d Resolve migrations and seeds relatively to knexfile directory (#2959) 2018-12-17 14:51:35 +02:00
Igor Savin
ff75f1d2bd
Do not reset prior Promise overrides on knex import (#2944)
* Do not reset prior Promise overrides on knex import

* Do not leak global state outside of the test
2018-12-10 18:20:06 +02:00
Igor Savin
ac6423f3b3 Fix support for default knexfile in working dir (#2941)
* Fix support for default knexfile in working dir

* Bump version

* Remove incorrect comment
2018-12-05 09:30:55 +02:00
Igor Savin
1cd1f079f8
Apply postprocessing in migrations (#2934)
Apply postprocessing in migrations
2018-12-03 23:47:09 +01:00
Igor Savin
8dc0a716f9
Fix CWD parameter support for CLI (#2935)
* Fix cwd support for knex-cli. Add test

* Remove redundant code

* Remove commented out code
2018-12-03 23:14:34 +01:00
Igor Savin
0115f933ca
Align signature for PG datetime and timestamp methods with docs (#2919)
* Align signature for PG datetime and timestamp methods with documentation. Add precision support

* Remove redundant method

* Add upgrade note for the change

* Changes after code review

* Improve API
2018-11-26 10:22:27 +01:00
Randy Garces
ab35e97614 GH-2915 Oracledb tests are failing (#2924)
* GH-2915 Oracledb tests are failing

- fixes oracledb failing tests

* Fixes oracledb increment() and decrement() empty query

- Error: The query is empty

* Add ToDo for fixing Oracle bug
2018-11-23 12:58:23 +01:00
Igor Savin
461868b614
Fix knexfile resolution. Add missing test (#2923)
* Fix knexfile resolution. Add missing test

* Try fixing Jake test execution

* Avoid having non-test files in jake folder

* Fix test compatibility with Node 6

* Fix the fix
2018-11-22 10:19:06 +01:00
Igor Savin
1eac063b28
Do not postprocess internal queries in Migrator (#2914)
* Do not postprocess internal queries in Migrator

* Fixes

* Fix var -> const autofix

* Fix regression
2018-11-19 12:55:50 +01:00
EthanHur
723346f7c5 fix client typo in test script (#2912) 2018-11-16 14:36:33 +01:00
Igor Savin
887fb53929
CLI cleanup. Do not require client for creating seeds or migrations (#2905)
* Specify jakefile explicitly to ensure it being run. Do not require client when creating seeds or migrations. cli.js cleanup. Formatting

* Fix message

* Fix typo

* Ignore console rule in CLI tests

* Fix rimraf import

* Improvements after code review

* One more arrow function
2018-11-16 13:23:22 +01:00
Neil Gentleman
833829aff1 Fix failed migration filename (#2910)
* Fix migration test assertions

* Report failing migration instead of latest migration

Migrator._activeMigration needs to be set twice: once when loading the
migration, and again when running it.
2018-11-16 01:23:13 +01:00
Douglas Nassif Roma Junior
931c157a2e Added option to pass indexType for MySQL dialect (#2890)
* Added option to pass indexType for MySQL dialect.

* Added test for: test adding index with type

* Removing extra space when no type is provided.
2018-11-10 16:36:10 +01:00
Eric Kennedy
1c0dc2c913 Add option of existingType to .enum method to support repeated use of enums (#2719)
* Update table column .enu to take an option that does not manually create the type

* Add tests for psql enum existingType

* Avoid utilizing enum values when using an existing type
2018-11-09 09:47:15 +01:00
Igor Savin
1bc24dfe4d
Add tests for specifying explicit pg version (#2895) 2018-11-07 12:57:25 +01:00
EthanHur
4db047df02 support multiple columns in .orderBy() (#2881)
* support multiple columns in `.orderBy()`

* add unit tests of order by

* orderByArray function to private

* use isString in string check
2018-11-06 22:30:06 +01:00
Aurélio A. Heckert
bb5da4b200 Migrations with CLI and without knexfile (#2884)
* Migrations with CLI and without knexfile

Allows to create and run migrations.

closes #2819

* Apply tweaks to migrate without knexfile

Thanks to @kibertoad comments!
The bigger change was to remove the bash script to test knex's cli command, and replace it with a jake file. I believe this jake file may be used as a base for future cli tests.

* Replace `fs.promises` with `new Promise`
2018-11-06 11:03:18 +02:00
Casey Foster
c0838053bd Add withRecursive() (#2889)
* Add withRecursive()
2018-11-04 20:30:04 -05:00
Igor Savin
8c269ca0d9
Add test for retrieving null dates (#2865)
* Add test for retrieving null dates

* Also test date and time columns

* Fix default value for TIMESTAMP type

* Make timestamp nullable
2018-10-19 16:21:39 +02:00
Henry Williams
2611e5a300 Fix linter errors in tests (#2859)
* fix lint errors for tests
2018-10-15 22:29:53 -04:00
Igor Savin
96a8e3a4d8 Add support for named unique, primary and foreign keys to SQLite3 (#2840)
* Add support for named unique, primary and foreign keys to SQLite3

* Add integration testing for named keys

* Improve tests for primary and unique keys

* Improve tests for foreign keys

* Run prettier

* Fix tests

* Fix additional test
2018-10-11 19:14:26 +03:00
Dale Anderson
46dbe917d7 Throw instead of process.exit when client module missing (#2843)
* Change process.exit to throw

* Add error message to wrapped error
2018-10-08 07:04:28 +02:00
Simon Lidén
66acbe7719 Allow chaining of increment, decrement, and update (#2740)
* Allow chaining of increment, decrement, and update
* Adds clearCounters
2018-10-06 10:10:56 -04:00
sgoll
1c782cf2c8 Allow table names with forUpdate/forShare (tgriesser/knex#2834) (#2835)
* Allow table names with forUpdate/forShare (tgriesser/knex#2834)

* Add integration test for partial table locks

* Simplify code of table name concatenation

* Add changelog entry
2018-10-04 09:39:24 -04:00
Tim Griesser
051bdc7e2a
whereColumn (#2837)
Adds: 
  - whereColumn
  - orWhereColumn
  - andWhereColumn
  - whereNotColumn
  - andWhereNotColumn
  - orWhereNotColumn
2018-10-03 11:26:19 -04:00
Tim Griesser
ca00ddb9c5 Revert "onVal -> onColumn for #2746"
This reverts commit b83fc4db476d596d3fb136f187cd91cb7f1dbcfe.
2018-10-03 09:32:29 -04:00
Katharina Irrgang
c746deaf12 Added support for renameColumn and double slashes (#2833)
refs #2763
2018-10-02 23:02:37 -04:00
Tim Griesser
b83fc4db47 onVal -> onColumn for #2746 2018-10-02 22:49:12 -04:00
Simon Lidén
0b417e5371 Feature/join onVal andOnVal orOnVal (#2746)
* Added onVal, andOnVal, orOnVal to JoinClause
2018-10-02 22:44:46 -04:00
Igor Savin
8c87650388 Support passing connection override to a query (#2817)
* Support passing connection override to a query

* Include connection param when cloning

* Only clone connection override if specified
2018-09-27 01:08:18 +03:00
veikovx
932fa4b683 Kill queries after timeout for PostgreSQL (#2636)
* Kill queries after timeout for PostgreSQL

* Fix cancellation connection acquiring and test.

* Fix releasing connection in case query cancellation fails

* Add support for native enums on Postgres (#2632)

Reference https://www.postgresql.org/docs/current/static/sql-createtype.html

Closes #394

Signed-off-by: Will Soto <will.soto9@gmail.com>

* Removal of 'skim' (#2520)

* Allow overwriting log functions (#2625)

* Example build of custom log functions
* Handle logger object better for transactions
* Adjust test to ignore sqlite warning message

* Fixed onIn with empty values array (#2513)

* Drop support for strong-oracle (#2487)

* Remove babel-plugin-lodash (#2634)

While in theory, this may reduce the bundle size,
in practice it adds a ton of overhead during startup
due to the number of additional requires. Bundle
size also shouldn't matter for server side modules.

* Add json support to the query builder for mysql (#2635)

* Add json support to the query builder for mysql

refs #1036

Based on #1902

* Clarify supported version

* fix wrapIdentifier not being called in postgres alter column (#2612)

* fix wrapIdentifier not being called in postgres alter column

* add test for wrapIdentifier call in postgres alter column

* add comment regarding issue

* add issue & PR #'s in comment

* Remove readable-stream and safe-buffer (#2640)

* Add json support to the query builder for mysql

refs #1036

Based on #1902

* Clarify supported version

* Use native Buffer and Stream implementations

* fixes 2630 (#2642)

* Timeout errors shouldn't silently ignore the passed errors, but rather reject with original error. Fixes #2582 (#2626)

* chore: add Node.js 10 (#2594)

* chore: add Node.js 10

* chore: trigger new build

* chore: update lockfile

* chore: trigger new build

* fix: use npm i instead of npm ci

* Fix mssql driver crashing (#2637)

* Run SQL Server tests locally running SQL server in docker

* WIP mssql test stuff

* Patched MSSQL driver to not crash knex anymore

* Removed semicolon from rollback stmt for oracle (#2564)

* Remove WebSQL dialect (#2647)

* Add json support to the query builder for mysql

refs #1036

Based on #1902

* Clarify supported version

* Use native Buffer and Stream implementations

* Remove WebSQL dialect

* add homepage field to package.json (#2650)

* Make the stream catch errors in the query (#2638)

* Make the stream catch errors in the query

* Fix another case in which stream doesnt emits error

* Linter stuff

* Remove setTimeout in tests

* Make a test not to check the MySQL error code

* Fix stream error catching for MariaDB and PostgreSQL

* Fix stream error catching in Oracle

* Throw the error after emitting it to the stream

* Throw the error without instantiating a new Error

* Various fixes to mssql dialect (#2653)

* Fixed float type of mssql to be float

* Many tests where postgres test was not actually ran at all

* Migrations to be mssql compatible

Mssql driver doesn't handle if multiple queries are sent to same transaction concurrently.

* Prevented mssql failing when invalid schema builder was executed by accident

Instead of trying to generate sql from broken schema calls, just make exception to leak before query compiling is started

* Fixed mssql trx rollback to always throw an error

Also modified some connection test query to be mssql compatible

* Fixed various bugs from MSSQL driver to make tests run

* Fixed mssql unique index to be compatible with other dialect implementations

* Enable running mssql tests on CI

* Test for #2588

* Updated tests to not be dependend on tables left from previous test rans

* Trying to make mssql server work on travis

* Updated changelog and version

* Drop mariadb support  (#2681)

* Dropped support for mariasql

* ESLint

* Fixed docs to build again

* Fix knex.initialize() and adds test (#2477)

* Fix knex.initialize() and adds test

* Fix knex.initialize() and adds test

* Added test for reinitializing pool after destroy

* Fixed destroy / reinitialization test

* Fixed the fix

* Implement missing schema support for mssql dialect

* chore: Update dependencies. Remove estraverse (#2691)

* Update dependencies. Remove estraverse

* Fix compatibility with new Sinon

* Increase mssql timeout

* Normalized and validated driverNames of test db clients and fixed oracle test setup (#2692)

* Normalized and validated driverNames of test db clients and fixed oracle test setup

* Fixed failed queries from old query building tests which hadn't been ran in ages

* Allow selecting node version which is used to run oracledb docker tests

* Improved sql tester error messages

* Fixed rest of the oracledb tests

* Removed invalid flag from docker-compose

* Print mssql logs if initialization fails

* Fixed syntax error + final tests

* Added restart of failure for mssql DB initialization to try again if server was not ready

* Printout always mssql logs after container is started

* Fixed wait time printing after trying to connect

* Use npm run oracledb:test for testing oracle in travis

* Add Prettier (#2697)

* Add prettier
* Run files through prettier

* Istanbul -> NYC (#2700)

* istanbul -> nyc

* Update mocha

* Enforce code coverage (#2702)

* Enforce code coverage
* Update coverage numbers with current values

* version assignment on base class, copy on tx client, fix #2705

* Update changelog

* v0.15.1

* Added build step to test script. Fixes #2541 (#2712)

* Revert "Added build step to test script. Fixes #2541 (#2712)" (#2714)

This reverts commit 90ed8db58053b859a6bdc45a17f2f510ce8a3411.

* Allow oracle failures for now

* Fix issue with select(0) (#2711)

* Fix issue with select(0). Fixes #2658

* Refactor migrator (#2695)

* Refactor migrator

* Fix exports

* Fix ESLint

* Fix migrator

* Fix reference to config

* Split some more

* Fix table builder

* Fix argument order

* Merge branch 'master' of https://github.com/tgriesser/knex into feature/2690-support-multiple-migration-dirs

# Conflicts:
#	src/migrate/index.js
#	test/index.js
#	test/unit/migrate/migrator.js

* Fix #2715 (#2721)

* Fix #2715, explicitly set precision in datetime & timestamp
* Allow for precision in knex.fn.now, mysql time
* Add test for datetime with precision

* Bump changelog

* 0.15.2

* Fix issues with warnPromise when migration does not return a promise. Fixes #2725 (#2730)

* Add tests for multiple union arguments with callbacks and builders (#2749)

* Add tests for multiple union arguments

* Add some callback and raw tests to union unit tests

* Compile with before update so that bindings are put in correct order (#2733)

* Fix join using builder withSchema. (#2744)

* Use Datetime2 for MSSQL datetime + timestamp types (#2757)

* Use Datetime2 for MSSQL datetime + timestamp types

Datetime2 is now the recommended column type for new date work: https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetime-transact-sql?view=sql-server-2017

* Add tests for MSSQL datetime2 changes

* General/document breaking change (#2774)

* Add changelog entry for a breaking change

* Improve entry

* Allow timestamp with timezone on mssql databases (#2724)

* Allow timestamp with timezone on mssql databases

* Change timestamp parameter to use object instead of boolean

* Update dependencies (#2772)

* Feature/2690: Multiple migration directories (#2735)

* Implement support for multiple migration directories

* Add tests for new functionality

* Fix tape tests

* Pass migration directory upwards

* Fix multiple directory support

* Fix bugs

* Rollback correctly

* Fix remaining tests

* Address comments

* #2758: Implement fail-fast logic for dialect resolution (#2776)

* Implement fail-fast logic for dialect resolution, clean-up code around.

* Remove method that was deprecated long time ago

* Address additional comments

* Try addressing comments

* Set client explicitly

* Fix compatibility with older Node versions

* Use columnize instead of wrap in using(). (#2713)

* Use columnize instead of wrap in using().

This is an attempt to fix #2136. Also added an integration test, couldn't find any existing.

* Exclude MSSQL from test as it does not support .using

* Change test to not use subquery

* Change test

* Introduced abstraction for getting migrations (#2775)

* Introduced abstraction for getting migrations

This would allow a webpack migration source which is compatible with bundling.

* Fixed migration validation with custom migration source

* Fixed issues after rebasing on muti directory PR

* Renamed parameter and fixed error message

* Addressed some PR comments

* Finished comment

* Moved filename extension filtering into fs-migrator

* Added test showing in memory custom migration source

* Cleaned up how to get config

* Fixed failing test

* Hopefully fix tests

* Fix Node.js 10 support in tests

* Test for correctly releasing cancel query connection
2018-09-27 00:06:43 +03:00
Igor Savin
d4a3387c56 Pass migration config object as an argument to the migrations (V 2.0) (#2802)
* Pass migration config object as an argument to the migrations themselves, to allow custom parameters to be set for migrations. (#2014)

* Run prettier

* Remove unneeded change

* Remove more unneeded changes

* Fix Node 10 support

* Update documentation based on a new design

* Restore test execution (oops)

* Fix withUserParams method

* Fix knex instance cloning

* Remove unused import

* Fix reference to knex from migrator

* Do not lose user params on transactions

* Remove unneeded require

* Address review comments

* Fix setting event emitter and listeners on Knex copies. Use knex copies to run tests in CI

* Remove knex cloning

* Fix event listener leak
2018-09-26 23:27:59 +03:00