Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/rimraf-5.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Dec 2, 2023
2 parents 1455454 + 0f2aea0 commit 327ab59
Show file tree
Hide file tree
Showing 40 changed files with 934 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
fetch-depth: 1

- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v3.7.0
uses: actions/setup-node@v4
with:
always-auth: false
node-version: ${{ matrix.node-version }}
Expand Down Expand Up @@ -109,15 +109,15 @@ jobs:
name: Test user experience
strategy:
matrix:
node-version: [18.x, 16.x, 14.x, 12.x]
node-version: [18.x]
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with: { fetch-depth: 1 }

- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v3.7.0
uses: actions/setup-node@v4
with:
always-auth: false
node-version: ${{ matrix.node-version }}
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/linting-legacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Legacy Types Linting

on:
push:
branches:
- master
pull_request:
branches:
- master

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
name: Legacy Types Linting

strategy:
matrix:
node-version: [16.x]

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
always-auth: false
node-version: ${{ matrix.node-version }}

- name: Run npm install
run: npm install

- name: Run lint:everything
run: npm run lint:types:legacy
6 changes: 3 additions & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [20.x]

steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v3.7.0
uses: actions/setup-node@v4
with:
always-auth: false
node-version: ${{ matrix.node-version }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ jobs:

steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v3.7.0
uses: actions/setup-node@v4
with:
always-auth: false
node-version: ${{ matrix.node-version }}
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Master (Unreleased)

# 3.0.1 - 6 October, 2023

- Build fix

# 3.0.0 - 6 October, 2023

- Fix raw bindings typing (#5401)
- Fix migrate:unlock when used with custom identifier wrapping. (#5353)
- Fix driver options specified with .options() method being ignored for oracledb dialect (#5123)
- Drop compatibility for Node < 16
- Fix knex d.ts to work with mixed modules (#5659)
- Fix Lexical error from "Instaed" to "Instead" (#5655)

### Bug fixes

- Fix Linting #5455 - #5460

# 2.5.1 - 12 July, 2023

### Bug fixes
Expand Down
5 changes: 5 additions & 0 deletions lib/dialects/mysql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { promisify } = require('util');
const Client = require('../../client');

const Transaction = require('./transaction');
const QueryBuilder = require('./query/mysql-querybuilder');
const QueryCompiler = require('./query/mysql-querycompiler');
const SchemaCompiler = require('./schema/mysql-compiler');
const TableCompiler = require('./schema/mysql-tablecompiler');
Expand All @@ -23,6 +24,10 @@ class Client_MySQL extends Client {
return require('mysql');
}

queryBuilder() {
return new QueryBuilder(this);
}

queryCompiler(builder, formatter) {
return new QueryCompiler(this, builder, formatter);
}
Expand Down
14 changes: 14 additions & 0 deletions lib/dialects/mysql/query/mysql-querybuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const QueryBuilder = require('../../../query/querybuilder');
const isEmpty = require('lodash/isEmpty');

module.exports = class QueryBuilder_MySQL extends QueryBuilder {
upsert(values, returning, options) {
this._method = 'upsert';
if (!isEmpty(returning)) {
this.returning(returning, options);
}

this._single.upsert = values;
return this;
}
};
18 changes: 18 additions & 0 deletions lib/dialects/mysql/query/mysql-querycompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ class QueryCompiler_MySQL extends QueryCompiler {

this._emptyInsertValue = '() values ()';
}
// Compiles an `delete` allowing comments
del() {
const sql = super.del();
if (sql === '') return sql;
const comments = this.comments();
return (comments === '' ? '' : comments + ' ') + sql;
}

// Compiles an `insert` query, allowing for multiple
// inserts using a single query statement.
insert() {
let sql = super.insert();
if (sql === '') return sql;
const comments = this.comments();
sql = (comments === '' ? '' : comments + ' ') + sql;

const { ignore, merge, insert } = this.single;
if (ignore) sql = sql.replace('insert into', 'insert ignore into');
Expand All @@ -49,6 +58,13 @@ class QueryCompiler_MySQL extends QueryCompiler {
return sql;
}

upsert() {
const upsertValues = this.single.upsert || [];
const sql = this.with() + `replace into ${this.tableName} `;
const body = this._insertBody(upsertValues);
return body === '' ? '' : sql + body;
}

// Compiles merge for onConflict, allowing for different merge strategies
_merge(updates, insert) {
const sql = ' on duplicate key update ';
Expand Down Expand Up @@ -86,13 +102,15 @@ class QueryCompiler_MySQL extends QueryCompiler {

// Update method, including joins, wheres, order & limits.
update() {
const comments = this.comments();
const withSQL = this.with();
const join = this.join();
const updates = this._prepUpdate(this.single.update);
const where = this.where();
const order = this.order();
const limit = this.limit();
return (
(comments === '' ? '' : comments + ' ') +
withSQL +
`update ${this.tableName}` +
(join ? ` ${join}` : '') +
Expand Down
24 changes: 24 additions & 0 deletions lib/dialects/mysql/schema/mysql-tablecompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ class TableCompiler_MySQL extends TableCompiler {
}
});
}
const bigIncrementsCols = this._getBigIncrementsColumnNames();
if (bigIncrementsCols.length) {
bigIncrementsCols.forEach((c) => {
if (!columns.includes(c)) {
columns.unshift(c);
}
});
}
}

return `,${constraintName} primary key (${this.formatter.columnize(
Expand Down Expand Up @@ -292,6 +300,7 @@ class TableCompiler_MySQL extends TableCompiler {

const primaryCols = columns;
let incrementsCols = [];
let bigIncrementsCols = [];
if (this.grouped.columns) {
incrementsCols = this._getIncrementsColumnNames();
if (incrementsCols) {
Expand All @@ -301,6 +310,14 @@ class TableCompiler_MySQL extends TableCompiler {
}
});
}
bigIncrementsCols = this._getBigIncrementsColumnNames();
if (bigIncrementsCols) {
bigIncrementsCols.forEach((c) => {
if (!primaryCols.includes(c)) {
primaryCols.unshift(c);
}
});
}
}
if (this.method !== 'create' && this.method !== 'createIfNot') {
this.pushQuery(
Expand All @@ -316,6 +333,13 @@ class TableCompiler_MySQL extends TableCompiler {
)} int unsigned not null auto_increment`
);
}
if (bigIncrementsCols.length) {
this.pushQuery(
`alter table ${this.tableName()} modify column ${this.formatter.columnize(
bigIncrementsCols
)} bigint unsigned not null auto_increment`
);
}
}

unique(columns, indexName) {
Expand Down
4 changes: 3 additions & 1 deletion lib/dialects/oracle/schema/internal/incrementUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ const Trigger = require('./trigger');

// helper function for pushAdditional in increments() and bigincrements()
function createAutoIncrementTriggerAndSequence(columnCompiler) {
const trigger = new Trigger(columnCompiler.client.version);

// TODO Add warning that sequence etc is created
columnCompiler.pushAdditional(function () {
const tableName = this.tableCompiler.tableNameRaw;
const schemaName = this.tableCompiler.schemaNameRaw;
const createTriggerSQL = Trigger.createAutoIncrementTrigger(
const createTriggerSQL = trigger.createAutoIncrementTrigger(
this.client.logger,
tableName,
schemaName
Expand Down
56 changes: 38 additions & 18 deletions lib/dialects/oracle/schema/internal/trigger.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
const utils = require('../../utils');
const { NameHelper } = require('../../utils');

const trigger = {
renameColumnTrigger: function (logger, tableName, columnName, to) {
const triggerName = utils.generateCombinedName(
class Trigger {
constructor(oracleVersion) {
this.nameHelper = new NameHelper(oracleVersion);
}

renameColumnTrigger(logger, tableName, columnName, to) {
const triggerName = this.nameHelper.generateCombinedName(
logger,
'autoinc_trg',
tableName
);
const sequenceName = utils.generateCombinedName(logger, 'seq', tableName);
const sequenceName = this.nameHelper.generateCombinedName(
logger,
'seq',
tableName
);
return (
`DECLARE ` +
`PK_NAME VARCHAR(200); ` +
Expand Down Expand Up @@ -41,19 +49,19 @@ const trigger = {
` end if;` +
`END;`
);
},
}

createAutoIncrementTrigger: function (logger, tableName, schemaName) {
createAutoIncrementTrigger(logger, tableName, schemaName) {
const tableQuoted = `"${tableName}"`;
const tableUnquoted = tableName;
const schemaQuoted = schemaName ? `"${schemaName}".` : '';
const constraintOwner = schemaName ? `'${schemaName}'` : 'cols.owner';
const triggerName = utils.generateCombinedName(
const triggerName = this.nameHelper.generateCombinedName(
logger,
'autoinc_trg',
tableName
);
const sequenceNameUnquoted = utils.generateCombinedName(
const sequenceNameUnquoted = this.nameHelper.generateCombinedName(
logger,
'seq',
tableName
Expand Down Expand Up @@ -86,17 +94,29 @@ const trigger = {
` end;'); ` +
`END;`
);
},
}

renameTableAndAutoIncrementTrigger: function (logger, tableName, to) {
const triggerName = utils.generateCombinedName(
renameTableAndAutoIncrementTrigger(logger, tableName, to) {
const triggerName = this.nameHelper.generateCombinedName(
logger,
'autoinc_trg',
tableName
);
const sequenceName = utils.generateCombinedName(logger, 'seq', tableName);
const toTriggerName = utils.generateCombinedName(logger, 'autoinc_trg', to);
const toSequenceName = utils.generateCombinedName(logger, 'seq', to);
const sequenceName = this.nameHelper.generateCombinedName(
logger,
'seq',
tableName
);
const toTriggerName = this.nameHelper.generateCombinedName(
logger,
'autoinc_trg',
to
);
const toSequenceName = this.nameHelper.generateCombinedName(
logger,
'seq',
to
);
return (
`DECLARE ` +
`PK_NAME VARCHAR(200); ` +
Expand Down Expand Up @@ -129,7 +149,7 @@ const trigger = {
` end if;` +
`END;`
);
},
};
}
}

module.exports = trigger;
module.exports = Trigger;

0 comments on commit 327ab59

Please sign in to comment.