Repository: knex/knex
Pull request #5181 (2022-05-16 11:56:17)

Fixes Maria issue with 'NULL' returned instead of NULL on MariaDB 10.2.6+
Fixes: #5154

---

If we look at https://jira.mariadb.org/browse/MDEV-13132, a bug was fixed to properly quote default value to be able to determine expressions vs null. This meant due to the strict typing that `'NULL'` was not detected as null and thus attempted to be included as a default value even against a not-nullable table here - https://github.com/knex/knex/blob/master/lib/schema/tablecompiler.js#L333

I've never worked with this project, but my Ghost blog stopped working and while Ghost is dropping Maria and I'm sad about that. I cannot complain seeing how I paid $0, so I'm attempting to fix to resolve this issue.

I added a test which I believe resolves issue, but to truly replicate you need Maria 10.2.6+ and I don't even see that in the integration suite (the docker). So while I pointed my test to my own Maria and confirmed this works as well as "monkey patching" this fix into my live environment as well. So I am setting this to draft to figure out how you recommend I solve this in terms of "proving" it was solved.

* Should I bring in Maria into integration suite, which might expose a few more issues?
* How should I handle this?

---
(proof of Ghost working after patch)

```
Message: Ghost was able to start, but errored during boot with: alter table `newsletters` modify  `created_at` datetime null default 'NULL' - Invalid default value for 'created_at'

Debug Information:
    OS: Ubuntu, v20.04.4 LTS
    Node Version: v14.19.2
    Ghost Version: 4.47.3
    Ghost-CLI Version: 1.18.1
    Environment: production
    Command: 'ghost restart'

Additional log info available in: xxx

connor@dune:/var/www/connor/blog$ ghost start
+ sudo systemctl start ghost_connortumbleson-com
✔ Starting Ghost
```


Patch:
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index a40f981b..c919020c 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -22,7 +22,7 @@ jobs:
           fetch-depth: 1
 
       - name: Setup Node ${{ matrix.node-version }}
-        uses: actions/setup-node@v3.1.1
+        uses: actions/setup-node@v3.2.0
         with:
           always-auth: false
           node-version: ${{ matrix.node-version }}
diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml
index b958c8c9..ae072088 100644
--- a/.github/workflows/linting.yml
+++ b/.github/workflows/linting.yml
@@ -26,7 +26,7 @@ jobs:
           fetch-depth: 1
 
       - name: Setup Node ${{ matrix.node-version }}
-        uses: actions/setup-node@v3.1.1
+        uses: actions/setup-node@v3.2.0
         with:
           always-auth: false
           node-version: ${{ matrix.node-version }}
diff --git a/.gitignore b/.gitignore
index b0d47e0f..4cc39126 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@ node_modules
 test.sqlite3
 npm-debug.log
 tmp
+knex-*.tgz
 
 # Testing for the knex cli:
 bin/migrations-folder
diff --git a/.husky/post-checkout b/.husky/post-checkout
new file mode 100755
index 00000000..9b3d2e81
--- /dev/null
+++ b/.husky/post-checkout
@@ -0,0 +1,4 @@
+#!/bin/sh
+. "$(dirname "$0")/_/husky.sh"
+
+npm run clean && npm run build
diff --git a/.husky/pre-commit b/.husky/pre-commit
old mode 100644
new mode 100755
index 36af2198..d24fdfc6
--- a/.husky/pre-commit
+++ b/.husky/pre-commit
@@ -1,4 +1,4 @@
-#!/bin/sh
-. "$(dirname "$0")/_/husky.sh"
+#!/usr/bin/env sh
+. "$(dirname -- "$0")/_/husky.sh"
 
 npx lint-staged
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 1c146567..634539df 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -171,11 +171,11 @@ psql -h localhost -U postgres -d knex_test
 
 ## Typescript source files
 
-> TL;DR: Starting with release 2.0.0 Knex is adding support for Typescript source files. Thus to develop in this repo you will need to run `npm run build` each time you edit `.ts` files to generate the resulting `.js` files. This is automatically run whenever you run `npm install` so when developing in Javascript you don't have to worry about it. It is encouraged that new functionality and sources be written in Typescript but this is not required.
+> TL;DR: Starting with release 2.0.0 Knex is adding support for Typescript source files. Thus to develop in this repo you will need to run `npm run build` each time you edit `.ts` files to generate the resulting `.js` files. This is automatically run whenever you run `npm install` or checkout a new Git branch so when developing in Javascript you don't have to worry about it. It is encouraged that new functionality and sources be written in Typescript but this is not required.
 
 Starting with release 2.0.0, Knex is support source additions in Typescript! This allows for better safety in the code added. However, pre-2.0.0 Knex was always written in pure Javascript and thus a "hybrid" approach is being used for 2.0.0 to allow for the new `.ts` files to exist along `.js` files that make up the majority of this repository.
 
-To develop in this repository use the `npm run build` and `npm run clean` commands to compile and delete the `.js` and related files from `.ts` files. If you wish to have the `tsc` compiled watch and recompile on changes then run `npm run build:ts -- --watch`. Note that for easy integration with Javascript the outputted files are done in a "side-by-side" manner meaning that `lib/foo/bar.ts` will result in `lib/foo/bar.js`. This is done automatically via the npm `postinstall` script trigger which executes when you run commands like `npm install` or `npm ci`, thus making it easier to not have to worry about this if you're working in pure Javascript.
+To develop in this repository use the `npm run build` and `npm run clean` commands to compile and delete the `.js` and related files from `.ts` files. If you wish to have the `tsc` compiled watch and recompile on changes then run `npm run build:ts -- --watch`. Note that for easy integration with Javascript the outputted files are done in a "side-by-side" manner meaning that `lib/foo/bar.ts` will result in `lib/foo/bar.js`. This is done automatically via the npm script command `"prepare"` whenever you run `npm install` and Git hook for `post-checkout` (added by Husky) which executes when you run commands like `git checkout` , thus making it easier to not have to worry about this if you're working in pure Javascript.
 
 The script file `./scripts/update_gitignore_for_tsc_output.js` file is called as part of the `npm run build` command which will update the `lib/.gitignore` file which is used to ensure generated `.js` and related files from `tsc` compilation are not checked into the git repo.
 
diff --git a/lib/dialects/mysql/query/mysql-querycompiler.js b/lib/dialects/mysql/query/mysql-querycompiler.js
index 52dd18b2..a235c64f 100644
--- a/lib/dialects/mysql/query/mysql-querycompiler.js
+++ b/lib/dialects/mysql/query/mysql-querycompiler.js
@@ -131,7 +131,7 @@ class QueryCompiler_MySQL extends QueryCompiler {
       output(resp) {
         const out = resp.reduce(function (columns, val) {
           columns[val.COLUMN_NAME] = {
-            defaultValue: val.COLUMN_DEFAULT,
+            defaultValue: val.COLUMN_DEFAULT === 'NULL' ? null : val.COLUMN_DEFAULT,
             type: val.DATA_TYPE,
             maxLength: val.CHARACTER_MAXIMUM_LENGTH,
             nullable: val.IS_NULLABLE === 'YES',
diff --git a/lib/knex-builder/Knex.js b/lib/knex-builder/Knex.js
index fd59b6d1..3f89233e 100644
--- a/lib/knex-builder/Knex.js
+++ b/lib/knex-builder/Knex.js
@@ -5,6 +5,10 @@ const QueryInterface = require('../query/method-constants');
 const makeKnex = require('./make-knex');
 const { KnexTimeoutError } = require('../util/timeout');
 const { resolveConfig } = require('./internal/config-resolver');
+const SchemaBuilder = require('../schema/builder');
+const ViewBuilder = require('../schema/viewbuilder');
+const ColumnBuilder = require('../schema/columnbuilder');
+const TableBuilder = require('../schema/tablebuilder');
 
 function knex(config) {
   const { resolvedConfig, Dialect } = resolveConfig(...arguments);
@@ -28,4 +32,28 @@ knex.QueryBuilder = {
   },
 };
 
+knex.SchemaBuilder = {
+  extend: function (methodName, fn) {
+    SchemaBuilder.extend(methodName, fn);
+  },
+};
+
+knex.ViewBuilder = {
+  extend: function (methodName, fn) {
+    ViewBuilder.extend(methodName, fn);
+  },
+};
+
+knex.ColumnBuilder = {
+  extend: function (methodName, fn) {
+    ColumnBuilder.extend(methodName, fn);
+  },
+};
+
+knex.TableBuilder  = {
+  extend: function (methodName, fn) {
+    TableBuilder.extend(methodName, fn);
+  },
+};
+
 module.exports = knex;
diff --git a/lib/migrations/migrate/MigrationGenerator.js b/lib/migrations/migrate/MigrationGenerator.js
index a33d55bd..979510a2 100644
--- a/lib/migrations/migrate/MigrationGenerator.js
+++ b/lib/migrations/migrate/MigrationGenerator.js
@@ -41,7 +41,7 @@ class MigrationGenerator {
 
   _getNewMigrationName(name) {
     if (name[0] === '-') name = name.slice(1);
-    return yyyymmddhhmmss() + '_' + name + '.' + this.config.extension;
+    return yyyymmddhhmmss() + '_' + name + '.' + this.config.extension.split('-')[0];
   }
 
   _getNewMigrationPath(name) {
diff --git a/lib/migrations/migrate/stub/js-schema.stub b/lib/migrations/migrate/stub/js-schema.stub
new file mode 100644
index 00000000..bf8d2743
--- /dev/null
+++ b/lib/migrations/migrate/stub/js-schema.stub
@@ -0,0 +1,22 @@
+/**
+ * @param { import("knex").Knex } knex
+ * @returns { Promise<void> }
+ */
+exports.up = function({schema}) {
+  <% if (d.tableName) { %>
+  return schema.createTable("<%= d.tableName %>", function(t) {
+    t.increments();
+    t.timestamp();
+  });
+  <% } %>
+};
+
+/**
+ * @param { import("knex").Knex } knex
+ * @returns { Promise<void> }
+ */
+exports.down = function({schema}) {
+  <% if (d.tableName) { %>
+  return schema.dropTable("<%= d.tableName %>");
+  <% } %>
+};
diff --git a/lib/migrations/migrate/stub/ts-schema.stub b/lib/migrations/migrate/stub/ts-schema.stub
new file mode 100644
index 00000000..850d1bfc
--- /dev/null
+++ b/lib/migrations/migrate/stub/ts-schema.stub
@@ -0,0 +1,21 @@
+import { Knex } from "knex";
+
+<% if (d.tableName) { %>
+export async function up({schema}: Knex): Promise<Knex.SchemaBuilder> {
+    return schema.createTable("<%= d.tableName %>", (t) => {
+        t.increments();
+        t.timestamps();
+    });
+}
+<% } else { %>
+export async function up({schema}: Knex): Promise<void> {
+}
+<% } %>
+<% if (d.tableName) { %>
+export async function down({schema}: Knex): Promise<Knex.SchemaBuilder> {
+    return schema.dropTable("<%= d.tableName %>");
+}
+<% } else { %>
+export async function down({schema}: Knex): Promise<void> {
+}
+<% } %>
diff --git a/lib/schema/builder.js b/lib/schema/builder.js
index f9a38e97..fc4fa959 100644
--- a/lib/schema/builder.js
+++ b/lib/schema/builder.js
@@ -1,5 +1,6 @@
 const { EventEmitter } = require('events');
 const toArray = require('lodash/toArray');
+const assign = require('lodash/assign');
 const { addQueryContext } = require('../util/helpers');
 const saveAsyncStack = require('../util/save-async-stack');
 const {
@@ -96,6 +97,17 @@ class SchemaBuilder extends EventEmitter {
   };
 });
 
+
+SchemaBuilder.extend = (methodName, fn) => {
+  if (Object.prototype.hasOwnProperty.call(SchemaBuilder.prototype, methodName)) {
+    throw new Error(
+      `Can't extend SchemaBuilder with existing method ('${methodName}').`
+    );
+  }
+
+  assign(SchemaBuilder.prototype, { [methodName]: fn });
+};
+
 augmentWithBuilderInterface(SchemaBuilder);
 addQueryContext(SchemaBuilder);
 
diff --git a/lib/schema/columnbuilder.js b/lib/schema/columnbuilder.js
index 685872c0..d520644c 100644
--- a/lib/schema/columnbuilder.js
+++ b/lib/schema/columnbuilder.js
@@ -1,4 +1,5 @@
 const extend = require('lodash/extend');
+const assign = require('lodash/assign');
 const toArray = require('lodash/toArray');
 const { addQueryContext } = require('../util/helpers');
 
@@ -87,6 +88,17 @@ ColumnBuilder.prototype.notNull = ColumnBuilder.prototype.notNullable =
   };
 });
 
+
+ColumnBuilder.extend = (methodName, fn) => {
+  if (Object.prototype.hasOwnProperty.call(ColumnBuilder.prototype, methodName)) {
+    throw new Error(
+      `Can't extend ColumnBuilder with existing method ('${methodName}').`
+    );
+  }
+
+  assign(ColumnBuilder.prototype, { [methodName]: fn });
+};
+
 const AlterMethods = {};
 
 // Specify that the column is to be dropped. This takes precedence
diff --git a/lib/schema/tablebuilder.js b/lib/schema/tablebuilder.js
index b52c031e..953b09cc 100644
--- a/lib/schema/tablebuilder.js
+++ b/lib/schema/tablebuilder.js
@@ -8,6 +8,7 @@
 // ------
 const each = require('lodash/each');
 const extend = require('lodash/extend');
+const assign = require('lodash/assign');
 const toArray = require('lodash/toArray');
 const helpers = require('../util/helpers');
 const { isString, isFunction, isObject } = require('../util/is');
@@ -360,4 +361,15 @@ AlterMethods.dropColumn = AlterMethods.dropColumns = function () {
   return this;
 };
 
+
+TableBuilder.extend = (methodName, fn) => {
+  if (Object.prototype.hasOwnProperty.call(TableBuilder.prototype, methodName)) {
+    throw new Error(
+      `Can't extend TableBuilder with existing method ('${methodName}').`
+    );
+  }
+
+  assign(TableBuilder.prototype, { [methodName]: fn });
+};
+
 module.exports = TableBuilder;
diff --git a/lib/schema/viewbuilder.js b/lib/schema/viewbuilder.js
index f33e7067..dd7e0e99 100644
--- a/lib/schema/viewbuilder.js
+++ b/lib/schema/viewbuilder.js
@@ -1,5 +1,6 @@
 const helpers = require('../util/helpers');
 const extend = require('lodash/extend');
+const assign = require('lodash/assign');
 
 class ViewBuilder {
   constructor(client, method, viewName, fn) {
@@ -78,4 +79,15 @@ const AlterMethods = {
 
 helpers.addQueryContext(ViewBuilder);
 
+
+ViewBuilder.extend = (methodName, fn) => {
+  if (Object.prototype.hasOwnProperty.call(ViewBuilder.prototype, methodName)) {
+    throw new Error(
+      `Can't extend ViewBuilder with existing method ('${methodName}').`
+    );
+  }
+
+  assign(ViewBuilder.prototype, { [methodName]: fn });
+};
+
 module.exports = ViewBuilder;
diff --git a/package.json b/package.json
index 1189e333..62f63deb 100644
--- a/package.json
+++ b/package.json
@@ -9,9 +9,9 @@
   },
   "scripts": {
     "build": "npm run build:gitignore && npm run build:ts",
-    "clean": "git clean -f -X lib/",
+    "clean": "node scripts/clean.js",
     "build:ts": "tsc",
-    "build:gitignore": "./scripts/update_gitignore_for_tsc_output.js run",
+    "build:gitignore": "node scripts/update_gitignore_for_tsc_output.js run",
     "format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"",
     "debug:test": "mocha --inspect-brk --exit -t 0 test/all-tests-suite.js",
     "debug:tape": "node --inspect-brk test/tape/index.js",
@@ -56,9 +56,7 @@
     "stress:init": "docker-compose -f scripts/stress-test/docker-compose.yml up --no-start && docker-compose -f scripts/stress-test/docker-compose.yml start",
     "stress:test": "node scripts/stress-test/knex-stress-test.js | grep -A 5 -B 60 -- '- STATS '",
     "stress:destroy": "docker-compose -f scripts/stress-test/docker-compose.yml stop",
-    "prepare": "husky install",
-    "prepublishOnly": "npm run clean && npm run build",
-    "postinstall": "npm run clean && npm run build"
+    "prepare": "husky install && npm run clean && npm run build"
   },
   "dependencies": {
     "colorette": "2.0.16",
@@ -101,8 +99,7 @@
   },
   "lint-staged": {
     "*.{js,json}": [
-      "prettier --write",
-      "git add"
+      "prettier --write"
     ]
   },
   "devDependencies": {
@@ -120,11 +117,11 @@
     "eslint-config-prettier": "^8.5.0",
     "eslint-plugin-import": "^2.26.0",
     "eslint-plugin-mocha-no-only": "^1.1.1",
-    "husky": "^7.0.4",
+    "husky": "^8.0.1",
     "jake": "^10.8.5",
     "JSONStream": "^1.3.5",
     "lint-staged": "^12.3.7",
-    "mocha": "^9.2.2",
+    "mocha": "^10.0.0",
     "mock-fs": "^5.1.2",
     "mysql": "^2.18.1",
     "mysql2": "^2.3.3",
@@ -201,9 +198,9 @@
     }
   ],
   "browser": {
-    "./lib/migrate/Migrator.js": "./lib/util/noop.js",
+    "./lib/migrations/migrate/Migrator.js": "./lib/util/noop.js",
     "./lib/bin/cli.js": "./lib/util/noop.js",
-    "./lib/seed/Seeder.js": "./lib/util/noop.js",
+    "./lib/migrations/seed/Seeder.js": "./lib/util/noop.js",
     "tedious": false,
     "mysql": false,
     "mysql2": false,
@@ -221,7 +218,8 @@
   },
   "files": [
     "bin/*",
-    "lib/*",
+    "lib/",
+    "lib/**/*.js",
     "!lib/**/*.ts",
     "!lib/**/*.d.ts",
     "!lib/**/*.js.map",
diff --git a/scripts/clean.js b/scripts/clean.js
new file mode 100755
index 00000000..fa1b7884
--- /dev/null
+++ b/scripts/clean.js
@@ -0,0 +1,29 @@
+#!/usr/bin/env node
+
+const fs = require('fs')
+const path = require('path')
+const { execSync } = require("child_process");
+
+function main() {
+  const repoDir = path.dirname(__dirname)
+  const gitDir = path.join(repoDir, '.git')
+  const gitDirExists = doesDirectoryExist(gitDir)
+  if (!gitDirExists) {
+    console.log("No .git directory detected so can not clean 'lib/'. Exiting.")
+    process.exit(0)
+  }
+  console.log("Cleaning 'lib/' of outputted files from Typescript compilation ...")
+  const cmd = 'git clean -f -X lib/'
+  const output = execSync(cmd, { cwd: repoDir })
+  console.log(output.toString('utf8'))
+  console.log('Done')
+}
+
+function doesDirectoryExist(p) {
+  if (fs.existsSync(p)) {
+    return fs.lstatSync(p).isDirectory()
+  }
+  return false
+}
+
+main()
diff --git a/types/index.d.ts b/types/index.d.ts
index 1c999f53..98bed908 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -384,6 +384,43 @@ export declare namespace knex {
     ): void;
   }
 
+  class TableBuilder {
+    static extend(
+      methodName: string,
+      fn: (
+        this: Knex.TableBuilder,
+        ...args: any[]
+      ) => Knex.TableBuilder
+    ): void;
+  }
+  class ViewBuilder {
+    static extend(
+      methodName: string,
+      fn: (
+        this: Knex.ViewBuilder,
+        ...args: any[]
+      ) => Knex.ViewBuilder
+    ): void;
+  }
+  class SchemaBuilder {
+    static extend(
+      methodName: string,
+      fn: (
+        this: Knex.SchemaBuilder,
+        ...args: any[]
+      ) => Knex.SchemaBuilder
+    ): void;
+  }
+  class ColumnBuilder {
+    static extend(
+      methodName: string,
+      fn: (
+        this: Knex.ColumnBuilder,
+        ...args: any[]
+      ) => Knex.ColumnBuilder
+    ): void;
+  }
+
   export class KnexTimeoutError extends Error {}
 
   export const Client: typeof Knex.Client;


Test patch:
diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml
index f1bab091..0d57eaa4 100644
--- a/.github/workflows/integration-tests.yml
+++ b/.github/workflows/integration-tests.yml
@@ -28,7 +28,7 @@ jobs:
           fetch-depth: 1
 
       - name: Setup Node ${{ matrix.node-version }}
-        uses: actions/setup-node@v3.1.1
+        uses: actions/setup-node@v3.2.0
         with:
           always-auth: false
           node-version: ${{ matrix.node-version }}
@@ -91,3 +91,29 @@ jobs:
             --file "scripts/docker-compose.yml" \
             down
         if: matrix.database-type != 'sqlite3' && matrix.database-type != 'better-sqlite3'
+
+  user_experience:
+    runs-on: ${{ matrix.os }}
+    name: Test user experience
+    strategy:
+      matrix:
+        node-version: [18.x, 16.x, 14.x, 12.x]
+        os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
+    steps:
+      - name: Checkout Repository
+        uses: actions/checkout@v3
+        with: { fetch-depth: 1 }
+
+      - name: Setup Node ${{ matrix.node-version }}
+        uses: actions/setup-node@v3.2.0
+        with:
+          always-auth: false
+          node-version: ${{ matrix.node-version }}
+      
+      - name: Test npm git dependency
+        shell: bash
+        run: |
+          mkdir TMP/
+          echo "{ \"dependencies\": { \"knex\": \"git+file://$(pwd)/\" } }" > TMP/package.json
+          cd TMP/
+          npm install --verbose
diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
index 47053054..200efa32 100644
--- a/.github/workflows/unit-tests.yml
+++ b/.github/workflows/unit-tests.yml
@@ -26,7 +26,7 @@ jobs:
           fetch-depth: 1
 
       - name: Setup Node ${{ matrix.node-version }}
-        uses: actions/setup-node@v3.1.1
+        uses: actions/setup-node@v3.2.0
         with:
           always-auth: false
           node-version: ${{ matrix.node-version }}
diff --git a/test/db-less-test-suite.js b/test/db-less-test-suite.js
index ed5a5935..5dd92807 100644
--- a/test/db-less-test-suite.js
+++ b/test/db-less-test-suite.js
@@ -20,6 +20,7 @@ describe('Query Building Tests', function () {
   require('./unit/query/string');
   require('./unit/schema-builder/mysql')('mysql');
   require('./unit/schema-builder/mysql')('mysql2');
+  require('./unit/schema-builder/extensions');
   require('./unit/schema-builder/postgres');
   require('./unit/schema-builder/redshift');
   require('./unit/schema-builder/sqlite3');
diff --git a/test/integration2/query/misc/additional.spec.js b/test/integration2/query/misc/additional.spec.js
index 30c92371..913ee7d8 100644
--- a/test/integration2/query/misc/additional.spec.js
+++ b/test/integration2/query/misc/additional.spec.js
@@ -423,6 +423,27 @@ describe('Additional', function () {
           expect(expectedUuid).to.equal(originalUuid);
         });
 
+        it ('#5154 - should properly mark COLUMN_DEFAULT as null', async function () {
+          if (!isMysql(knex)) {
+            return this.skip();
+          }
+
+          await knex.schema.dropTableIfExists('null_col');
+          await knex.schema.createTable('null_col', function (table) {
+            table.date('foo').defaultTo(null).nullable();
+          })
+          const columnInfo = await knex('null_col').columnInfo();
+
+          expect(columnInfo).to.deep.equal({
+            foo: {
+              type: 'date',
+              maxLength: null,
+              nullable: true,
+              defaultValue: null,
+            },
+          });
+        });
+
         it('#2184 - should properly escape table name for SQLite columnInfo', async function () {
           if (!isSQLite(knex)) {
             return this.skip();
diff --git a/test/unit/schema-builder/extensions.js b/test/unit/schema-builder/extensions.js
new file mode 100644
index 00000000..d300b3dd
--- /dev/null
+++ b/test/unit/schema-builder/extensions.js
@@ -0,0 +1,52 @@
+'use strict';
+
+const expect = require('chai').expect;
+const MySQL_Client = require('../../../lib/dialects/mysql');
+const knex = require('../../../knex');
+describe('SchemaBuilder Extensions', () => {
+  const client = new MySQL_Client({ client: 'mysql' });
+
+  const equal = require('assert').equal;
+  const functionToExtend = () => true;
+  knex.SchemaBuilder.extend('tryCreateTable', functionToExtend);
+  knex.TableBuilder.extend('testCol', functionToExtend);
+  knex.ColumnBuilder.extend('testCol', functionToExtend);
+  knex.ViewBuilder.extend('testCol', functionToExtend);
+
+  it('schemabuilder has method', () => {
+    equal(client.schemaBuilder().tryCreateTable, functionToExtend);
+    expect(client.schemaBuilder().tryCreateTable()).to.be.true;
+  });
+
+  it('tablebuilder has method', () => {
+    client
+      .schemaBuilder()
+      .createTable('users', function (table) {
+        equal(table.testCol, functionToExtend);
+      })
+      .toSQL();
+  });
+
+  it('columnbuilder has method', () => {
+    client
+      .schemaBuilder()
+      .createTable('users', function (table) {
+        equal(table.string('t').testCol, functionToExtend);
+      })
+      .toSQL();
+  });
+
+  it('viewbuilder has method', () => {
+    client
+      .schemaBuilder()
+      .createView('users', function (view) {
+        equal(view.testCol, functionToExtend);
+        view.as(
+          knex('users')
+            .join('user_roles', 'users.user_id', 'user_roles.user_id')
+            .select('users.*', 'user_roles.role_code')
+        );
+      })
+      .toSQL();
+  });
+});