Initial commit

This commit is contained in:
2025-12-07 14:32:46 +00:00
commit 0a0969b8af
4726 changed files with 536089 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
const ColumnBuilder = require('../../../schema/columnbuilder');
class ColumnBuilder_Redshift extends ColumnBuilder {
constructor() {
super(...arguments);
}
// primary needs to set not null on non-preexisting columns, or fail
primary() {
this.notNullable();
return super.primary(...arguments);
}
index() {
this.client.logger.warn(
'Redshift does not support the creation of indexes.'
);
return this;
}
}
module.exports = ColumnBuilder_Redshift;

View File

@@ -0,0 +1,67 @@
// Redshift Column Compiler
// -------
const ColumnCompiler_PG = require('../../postgres/schema/pg-columncompiler');
const ColumnCompiler = require('../../../schema/columncompiler');
class ColumnCompiler_Redshift extends ColumnCompiler_PG {
constructor() {
super(...arguments);
}
// Types:
// ------
bit(column) {
return column.length !== false ? `char(${column.length})` : 'char(1)';
}
datetime(without) {
return without ? 'timestamp' : 'timestamptz';
}
timestamp(without) {
return without ? 'timestamp' : 'timestamptz';
}
// Modifiers:
// ------
comment(comment) {
this.pushAdditional(function () {
this.pushQuery(
`comment on column ${this.tableCompiler.tableName()}.` +
this.formatter.wrap(this.args[0]) +
' is ' +
(comment ? `'${comment}'` : 'NULL')
);
}, comment);
}
}
ColumnCompiler_Redshift.prototype.increments = ({ primaryKey = true } = {}) =>
'integer identity(1,1)' + (primaryKey ? ' primary key' : '') + ' not null';
ColumnCompiler_Redshift.prototype.bigincrements = ({
primaryKey = true,
} = {}) =>
'bigint identity(1,1)' + (primaryKey ? ' primary key' : '') + ' not null';
ColumnCompiler_Redshift.prototype.binary = 'varchar(max)';
ColumnCompiler_Redshift.prototype.blob = 'varchar(max)';
ColumnCompiler_Redshift.prototype.enu = 'varchar(255)';
ColumnCompiler_Redshift.prototype.enum = 'varchar(255)';
ColumnCompiler_Redshift.prototype.json = 'varchar(max)';
ColumnCompiler_Redshift.prototype.jsonb = 'varchar(max)';
ColumnCompiler_Redshift.prototype.longblob = 'varchar(max)';
ColumnCompiler_Redshift.prototype.mediumblob = 'varchar(16777218)';
ColumnCompiler_Redshift.prototype.set = 'text';
ColumnCompiler_Redshift.prototype.text = 'varchar(max)';
ColumnCompiler_Redshift.prototype.tinyblob = 'varchar(256)';
ColumnCompiler_Redshift.prototype.uuid = ColumnCompiler.prototype.uuid;
ColumnCompiler_Redshift.prototype.varbinary = 'varchar(max)';
ColumnCompiler_Redshift.prototype.bigint = 'bigint';
ColumnCompiler_Redshift.prototype.bool = 'boolean';
ColumnCompiler_Redshift.prototype.double = 'double precision';
ColumnCompiler_Redshift.prototype.floating = 'real';
ColumnCompiler_Redshift.prototype.smallint = 'smallint';
ColumnCompiler_Redshift.prototype.tinyint = 'smallint';
module.exports = ColumnCompiler_Redshift;

View File

@@ -0,0 +1,14 @@
/* eslint max-len: 0 */
// Redshift Table Builder & Compiler
// -------
const SchemaCompiler_PG = require('../../postgres/schema/pg-compiler');
class SchemaCompiler_Redshift extends SchemaCompiler_PG {
constructor() {
super(...arguments);
}
}
module.exports = SchemaCompiler_Redshift;

View File

@@ -0,0 +1,122 @@
/* eslint max-len: 0 */
// Redshift Table Builder & Compiler
// -------
const has = require('lodash/has');
const TableCompiler_PG = require('../../postgres/schema/pg-tablecompiler');
class TableCompiler_Redshift extends TableCompiler_PG {
constructor() {
super(...arguments);
}
index(columns, indexName, options) {
this.client.logger.warn(
'Redshift does not support the creation of indexes.'
);
}
dropIndex(columns, indexName) {
this.client.logger.warn(
'Redshift does not support the deletion of indexes.'
);
}
// TODO: have to disable setting not null on columns that already exist...
// Adds the "create" query to the query sequence.
createQuery(columns, ifNot, like) {
const createStatement = ifNot
? 'create table if not exists '
: 'create table ';
const columnsSql = ' (' + columns.sql.join(', ') + this._addChecks() + ')';
let sql =
createStatement +
this.tableName() +
(like && this.tableNameLike()
? ' (like ' + this.tableNameLike() + ')'
: columnsSql);
if (this.single.inherits)
sql += ` like (${this.formatter.wrap(this.single.inherits)})`;
this.pushQuery({
sql,
bindings: columns.bindings,
});
const hasComment = has(this.single, 'comment');
if (hasComment) this.comment(this.single.comment);
if (like) {
this.addColumns(columns, this.addColumnsPrefix);
}
}
primary(columns, constraintName) {
const self = this;
constraintName = constraintName
? self.formatter.wrap(constraintName)
: self.formatter.wrap(`${this.tableNameRaw}_pkey`);
if (columns.constructor !== Array) {
columns = [columns];
}
const thiscolumns = self.grouped.columns;
if (thiscolumns) {
for (let i = 0; i < columns.length; i++) {
let exists = thiscolumns.find(
(tcb) =>
tcb.grouping === 'columns' &&
tcb.builder &&
tcb.builder._method === 'add' &&
tcb.builder._args &&
tcb.builder._args.indexOf(columns[i]) > -1
);
if (exists) {
exists = exists.builder;
}
const nullable = !(
exists &&
exists._modifiers &&
exists._modifiers['nullable'] &&
exists._modifiers['nullable'][0] === false
);
if (nullable) {
if (exists) {
return this.client.logger.warn(
'Redshift does not allow primary keys to contain nullable columns.'
);
} else {
return this.client.logger.warn(
'Redshift does not allow primary keys to contain nonexistent columns.'
);
}
}
}
}
return self.pushQuery(
`alter table ${self.tableName()} add constraint ${constraintName} primary key (${self.formatter.columnize(
columns
)})`
);
}
// Compiles column add. Redshift can only add one column per ALTER TABLE, so core addColumns doesn't work. #2545
addColumns(columns, prefix, colCompilers) {
if (prefix === this.alterColumnsPrefix) {
super.addColumns(columns, prefix, colCompilers);
} else {
prefix = prefix || this.addColumnsPrefix;
colCompilers = colCompilers || this.getColumns();
for (const col of colCompilers) {
const quotedTableName = this.tableName();
const colCompiled = col.compileColumn();
this.pushQuery({
sql: `alter table ${quotedTableName} ${prefix}${colCompiled}`,
bindings: [],
});
}
}
}
}
module.exports = TableCompiler_Redshift;

View File

@@ -0,0 +1,11 @@
/* eslint max-len: 0 */
const ViewCompiler_PG = require('../../postgres/schema/pg-viewcompiler.js');
class ViewCompiler_Redshift extends ViewCompiler_PG {
constructor(client, viewCompiler) {
super(client, viewCompiler);
}
}
module.exports = ViewCompiler_Redshift;