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

Bluebird removal: part I #3266

Merged
merged 1 commit into from Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPGRADING.md
@@ -1,5 +1,12 @@
## Upgrading to new knex.js versions

### Upgrading to version 0.18.0+

* Node.js older than 8 is no longer supported, make sure to update your environment;
* Knex returns native promises instead of bluebird ones now. You will need to update your code not to rely on bluebird-specific functionality;
* Knex.Promise was removed, use native promises;
* Promise is no longer passed to migrations and seeds, use native one.

### Upgrading to version 0.16.0+

* MSSQL: DB versions older than 2008 are no longer supported, make sure to update your DB;
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -8,7 +8,6 @@
"node": ">=8"
},
"dependencies": {
"@types/bluebird": "^3.5.27",
"bluebird": "^3.5.5",
"colorette": "1.0.8",
"commander": "^2.20.0",
Expand Down
4 changes: 3 additions & 1 deletion src/dialects/mysql/schema/tablecompiler.js
Expand Up @@ -96,7 +96,9 @@ assign(TableCompiler_MySQL.prototype, {
}
})
.then(function() {
let sql = `alter table ${table} change ${wrapped} ${column.Type}`;
let sql = `alter table ${table} change ${wrapped} ${
column.Type
}`;

if (String(column.Null).toUpperCase() !== 'YES') {
sql += ` NOT NULL`;
Expand Down
11 changes: 0 additions & 11 deletions src/knex.js
Expand Up @@ -59,17 +59,6 @@ Knex.Client = Client;

/* eslint no-console:0 */

Object.defineProperties(Knex, {
Promise: {
get() {
console.warn(
`Knex.Promise is deprecated, either require bluebird or use the global Promise`
);
return require('bluebird');
},
},
});

// Run a "raw" query, though we can't do anything with it other than put
// it in a query statement.
Knex.raw = (sql, bindings) => {
Expand Down
4 changes: 2 additions & 2 deletions src/migrate/Migrator.js
Expand Up @@ -438,7 +438,7 @@ class Migrator {
trxOrKnex.enableProcessing();
return checkPromise(
this.knex.client.logger,
migrationContent[direction](trxOrKnex, Promise),
migrationContent[direction](trxOrKnex),
name
);
})
Expand Down Expand Up @@ -469,7 +469,7 @@ class Migrator {
return knex.transaction((trx) => {
return checkPromise(
knex.client.logger,
migrationContent[direction](trx, Promise),
migrationContent[direction](trx),
name,
() => {
trx.commit();
Expand Down
4 changes: 2 additions & 2 deletions src/migrate/stub/coffee.stub
@@ -1,13 +1,13 @@

exports.up = (knex, Promise) ->
exports.up = (knex) ->
<% if (d.tableName) { %>
knex.schema.createTable "<%= d.tableName %>", (t) ->
t.increments()
t.timestamp()
<% } %>


exports.down = (knex, Promise) ->
exports.down = (knex) ->
<% if (d.tableName) { %>
knex.schema.dropTable "<%= d.tableName %>"
<% } %>
4 changes: 2 additions & 2 deletions src/migrate/stub/eg.stub
@@ -1,14 +1,14 @@
provide: up, down

up = (knex, Promise) ->
up = (knex) ->
<% if (d.tableName) { %>
knex.schema.createTable "<%= d.tableName %>": t ->
t.increments()
t.timestamp()
<% } %>


down = (knex, Promise) ->
down = (knex) ->
<% if (d.tableName) { %>
knex.schema.dropTable("<%= d.tableName %>")
<% } %>
4 changes: 2 additions & 2 deletions src/migrate/stub/js.stub
@@ -1,5 +1,5 @@

exports.up = function(knex, Promise) {
exports.up = function(knex) {
<% if (d.tableName) { %>
return knex.schema.createTable("<%= d.tableName %>", function(t) {
t.increments();
Expand All @@ -8,7 +8,7 @@ exports.up = function(knex, Promise) {
<% } %>
};

exports.down = function(knex, Promise) {
exports.down = function(knex) {
<% if (d.tableName) { %>
return knex.schema.dropTable("<%= d.tableName %>");
<% } %>
Expand Down
2 changes: 1 addition & 1 deletion src/seed/Seeder.js
Expand Up @@ -135,7 +135,7 @@ Seeder.prototype._waterfallBatch = function(seeds) {
current = current.then(() =>
// Nesting promise to prevent bubbling up of error on catch
Promise.resolve()
.then(() => seed.seed(knex, Promise))
.then(() => seed.seed(knex))
.then(() => log.push(name))
.catch((originalError) => {
const error = new Error(
Expand Down
2 changes: 1 addition & 1 deletion src/seed/stub/coffee.stub
@@ -1,4 +1,4 @@
exports.seed = (knex, Promise) ->
exports.seed = (knex) ->
knex('table_name').del()
.then () ->
# Inserts seed entries
Expand Down
2 changes: 1 addition & 1 deletion src/seed/stub/eg.stub
@@ -1,5 +1,5 @@
provide: seed
seed = (knex, Promise) ->
seed = (knex) ->
;; Deletes ALL existing entries
knex(.table_name).del()
.then(() ->
Expand Down
2 changes: 1 addition & 1 deletion src/seed/stub/js.stub
@@ -1,5 +1,5 @@

exports.seed = function(knex, Promise) {
exports.seed = function(knex) {
// Deletes ALL existing entries
return knex('table_name').del()
.then(function () {
Expand Down
2 changes: 1 addition & 1 deletion src/seed/stub/ls.stub
@@ -1,4 +1,4 @@
exports.seed = (knex, Promise) ->
exports.seed = (knex) ->
# Deletes ALL existing entries
knex('table_name').del()
.then(() ->
Expand Down
2 changes: 0 additions & 2 deletions src/util/make-knex.js
Expand Up @@ -6,7 +6,6 @@ const FunctionHelper = require('../functionhelper');
const QueryInterface = require('../query/methods');
const { assign, merge } = require('lodash');
const batchInsert = require('./batchInsert');
const bluebird = require('bluebird');

function makeKnex(client) {
// The object we're potentially using to kick off an initial chain.
Expand Down Expand Up @@ -212,7 +211,6 @@ function redefineProperties(knex, client) {
});

initContext(knex);
knex.Promise = bluebird;
knex.client = client;
knex.client.makeKnex = makeKnex;
knex.userParams = {};
Expand Down
43 changes: 21 additions & 22 deletions types/index.d.ts
Expand Up @@ -10,7 +10,6 @@

import events = require('events');
import stream = require('stream');
import Bluebird = require('bluebird');
import ResultTypes = require('./result');

// # Generic type-level utilities
Expand Down Expand Up @@ -330,12 +329,12 @@ interface Knex<TRecord extends {} = any, TResult = any[]>
config?: any
): Promise<Knex.Transaction>;
transaction<T>(
transactionScope: (trx: Knex.Transaction) => Promise<T> | Bluebird<T> | void,
transactionScope: (trx: Knex.Transaction) => Promise<T> | Promise<T> | void,
config?: any
): Bluebird<T>;
): Promise<T>;
initialize(config?: Knex.Config): void;
destroy(callback: Function): void;
destroy(): Bluebird<void>;
destroy(): Promise<void>;
batchInsert(
tableName: Knex.TableDescriptor,
data: any[],
Expand Down Expand Up @@ -1347,7 +1346,7 @@ declare namespace Knex {
and: QueryBuilder<TRecord, TResult>;

// TODO: Promise?
columnInfo(column?: keyof TRecord): Bluebird<ColumnInfo>;
columnInfo(column?: keyof TRecord): Promise<ColumnInfo>;

forUpdate(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
forUpdate(tableNames: string[]): QueryBuilder<TRecord, TResult>;
Expand Down Expand Up @@ -1379,17 +1378,17 @@ declare namespace Knex {
// Chainable interface
//

interface ChainableInterface<T = any> extends Bluebird<T> {
interface ChainableInterface<T = any> extends Promise<T> {
toQuery(): string;
options(options: { [key: string]: any }): this;
connection(connection: any): this;
debug(enabled: boolean): this;
transacting(trx: Transaction): this;
stream(handler: (readable: stream.PassThrough) => any): Bluebird<any>;
stream(handler: (readable: stream.PassThrough) => any): Promise<any>;
stream(
options: { [key: string]: any },
handler: (readable: stream.PassThrough) => any
): Bluebird<any>;
): Promise<any>;
stream(options?: { [key: string]: any }): stream.PassThrough;
pipe<T extends NodeJS.WritableStream>(
writable: T,
Expand All @@ -1408,7 +1407,7 @@ declare namespace Knex {
): QueryBuilder<TRecord, TResult>;
savepoint<T = any>(
transactionScope: (trx: Transaction) => any
): Bluebird<T>;
): Promise<T>;
commit(value?: any): QueryBuilder<TRecord, TResult>;
rollback(error?: any): QueryBuilder<TRecord, TResult>;
}
Expand All @@ -1430,14 +1429,14 @@ declare namespace Knex {
tableName: string,
callback: (tableBuilder: CreateTableBuilder) => any
): SchemaBuilder;
renameTable(oldTableName: string, newTableName: string): Bluebird<void>;
renameTable(oldTableName: string, newTableName: string): Promise<void>;
dropTable(tableName: string): SchemaBuilder;
hasTable(tableName: string): Bluebird<boolean>;
hasColumn(tableName: string, columnName: string): Bluebird<boolean>;
hasTable(tableName: string): Promise<boolean>;
hasColumn(tableName: string, columnName: string): Promise<boolean>;
table(
tableName: string,
callback: (tableBuilder: AlterTableBuilder) => any
): Bluebird<void>;
): Promise<void>;
dropTableIfExists(tableName: string): SchemaBuilder;
raw(statement: string): SchemaBuilder;
withSchema(schemaName: string): SchemaBuilder;
Expand Down Expand Up @@ -1759,13 +1758,13 @@ declare namespace Knex {
}

interface Migrator {
make(name: string, config?: MigratorConfig): Bluebird<string>;
latest(config?: MigratorConfig): Bluebird<any>;
rollback(config?: MigratorConfig, all?: boolean): Bluebird<any>;
status(config?: MigratorConfig): Bluebird<number>;
currentVersion(config?: MigratorConfig): Bluebird<string>;
up(config?: MigratorConfig): Bluebird<any>;
down(config?: MigratorConfig): Bluebird<any>;
make(name: string, config?: MigratorConfig): Promise<string>;
latest(config?: MigratorConfig): Promise<any>;
rollback(config?: MigratorConfig, all?: boolean): Promise<any>;
status(config?: MigratorConfig): Promise<number>;
currentVersion(config?: MigratorConfig): Promise<string>;
up(config?: MigratorConfig): Promise<any>;
down(config?: MigratorConfig): Promise<any>;
}

interface SeederConfig {
Expand All @@ -1777,8 +1776,8 @@ declare namespace Knex {
class Seeder {
constructor(knex: Knex);
setConfig(config: SeederConfig): SeederConfig;
run(config?: SeederConfig): Bluebird<string[]>;
make(name: string, config?: SeederConfig): Bluebird<string>;
run(config?: SeederConfig): Promise<string[]>;
make(name: string, config?: SeederConfig): Promise<string>;
}

interface FunctionHelper {
Expand Down