2020-03-08 19:48:23 -04:00
|
|
|
const { expect } = require('chai');
|
2015-04-22 10:34:14 -04:00
|
|
|
|
2018-10-15 22:29:53 -04:00
|
|
|
let tableSql;
|
2015-04-22 10:34:14 -04:00
|
|
|
|
2018-10-15 22:29:53 -04:00
|
|
|
const sinon = require('sinon');
|
2019-07-10 22:48:43 +01:00
|
|
|
const PG_Client = require('../../../lib/dialects/postgres');
|
2018-10-15 22:29:53 -04:00
|
|
|
const client = new PG_Client({ client: 'pg' });
|
|
|
|
const knex = require('../../../knex');
|
2015-04-22 10:34:14 -04:00
|
|
|
|
2018-11-19 12:55:50 +01:00
|
|
|
const equal = require('chai').assert.equal;
|
2015-04-22 10:34:14 -04:00
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
describe('PostgreSQL Config', function () {
|
2018-10-15 22:29:53 -04:00
|
|
|
let knexInstance;
|
|
|
|
let version;
|
|
|
|
const config = {
|
2017-03-27 00:21:15 +03:00
|
|
|
client: 'pg',
|
|
|
|
connection: {
|
|
|
|
user: 'postgres',
|
|
|
|
password: '',
|
|
|
|
host: '127.0.0.1',
|
2018-07-09 08:10:34 -04:00
|
|
|
database: 'knex_test',
|
|
|
|
},
|
2017-03-27 00:21:15 +03:00
|
|
|
};
|
2020-04-19 00:40:23 +02:00
|
|
|
describe('check version', function () {
|
|
|
|
describe('check version < 9.2', function () {
|
|
|
|
beforeEach(function () {
|
2017-03-27 00:21:15 +03:00
|
|
|
version = '7.2';
|
|
|
|
config.version = version;
|
|
|
|
knexInstance = knex(config);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('client.version', function () {
|
2017-03-27 00:21:15 +03:00
|
|
|
expect(knexInstance.client.version).to.equal(version);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('json', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = knexInstance.schema
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('public', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.json('test_name');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-03-27 00:21:15 +03:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "public" add column "test_name" text'
|
|
|
|
);
|
2017-03-27 00:21:15 +03:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('jsonb', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = knexInstance.schema
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('public', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.jsonb('test_name');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-03-27 00:21:15 +03:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "public" add column "test_name" text'
|
|
|
|
);
|
2017-03-27 00:21:15 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
describe('check version >= 9.2', function () {
|
|
|
|
beforeEach(function () {
|
2017-03-27 00:21:15 +03:00
|
|
|
version = '9.5';
|
|
|
|
config.version = version;
|
|
|
|
knexInstance = knex(config);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('client.version', function () {
|
2017-03-27 00:21:15 +03:00
|
|
|
expect(knexInstance.client.version).to.equal(version);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('json', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = knexInstance.schema
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('public', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.json('test_name');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-03-27 00:21:15 +03:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "public" add column "test_name" json'
|
|
|
|
);
|
2017-03-27 00:21:15 +03:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('jsonb', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = knexInstance.schema
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('public', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.jsonb('test_name');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-03-27 00:21:15 +03:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "public" add column "test_name" jsonb'
|
|
|
|
);
|
2017-03-27 00:21:15 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
describe('PostgreSQL SchemaBuilder', function () {
|
|
|
|
it('fixes memoization regression', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.uuid('key');
|
|
|
|
table.increments('id');
|
|
|
|
table.string('email');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'create table "users" ("key" uuid, "id" serial primary key, "email" varchar(255))'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-10-15 15:57:46 +02:00
|
|
|
it('create table like another', function () {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.createTableLike('users_like', 'users')
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'create table "users_like" (like "users" including all)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('basic alter table', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.increments('id');
|
|
|
|
table.string('email');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "id" serial primary key, add column "email" varchar(255)'
|
|
|
|
);
|
2015-04-22 10:34:14 -04:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('should alter columns with the alter flag', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function () {
|
|
|
|
this.string('foo').notNullable().default('foo').alter();
|
2018-07-09 08:10:34 -04:00
|
|
|
this.integer('bar').alter();
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-02-16 20:34:59 +02:00
|
|
|
|
|
|
|
equal(8, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" alter column "foo" drop default'
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "users" alter column "foo" drop not null'
|
|
|
|
);
|
|
|
|
expect(tableSql[2].sql).to.equal(
|
|
|
|
'alter table "users" alter column "foo" type varchar(255) using ("foo"::varchar(255))'
|
|
|
|
);
|
|
|
|
expect(tableSql[3].sql).to.equal(
|
|
|
|
'alter table "users" alter column "foo" set default \'foo\''
|
|
|
|
);
|
|
|
|
expect(tableSql[4].sql).to.equal(
|
|
|
|
'alter table "users" alter column "foo" set not null'
|
|
|
|
);
|
|
|
|
expect(tableSql[5].sql).to.equal(
|
|
|
|
'alter table "users" alter column "bar" drop default'
|
|
|
|
);
|
|
|
|
expect(tableSql[6].sql).to.equal(
|
|
|
|
'alter table "users" alter column "bar" drop not null'
|
|
|
|
);
|
|
|
|
expect(tableSql[7].sql).to.equal(
|
|
|
|
'alter table "users" alter column "bar" type integer using ("bar"::integer)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('alter table with schema', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.withSchema('myschema')
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.increments('id');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-08-09 22:24:55 -03:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "myschema"."users" add column "id" serial primary key'
|
|
|
|
);
|
2015-08-09 22:24:55 -03:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop table', function () {
|
|
|
|
tableSql = client.schemaBuilder().dropTable('users').toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal('drop table "users"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop table with schema', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.withSchema('myschema')
|
|
|
|
.dropTable('users')
|
|
|
|
.toSQL();
|
2015-08-09 22:24:55 -03:00
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal('drop table "myschema"."users"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop table if exists', function () {
|
|
|
|
tableSql = client.schemaBuilder().dropTableIfExists('users').toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal('drop table if exists "users"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop table if exists with schema', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.withSchema('myschema')
|
|
|
|
.dropTableIfExists('users')
|
|
|
|
.toSQL();
|
2015-08-09 22:24:55 -03:00
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal('drop table if exists "myschema"."users"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop column', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropColumn('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal('alter table "users" drop column "foo"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop multiple columns', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropColumn(['foo', 'bar']);
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" drop column "foo", drop column "bar"'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop multiple columns with arguments', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropColumn('foo', 'bar');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" drop column "foo", drop column "bar"'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop primary', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropPrimary();
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" drop constraint "users_pkey"'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop unique', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropUnique('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" drop constraint "users_foo_unique"'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop unique, custom', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropUnique(null, 'foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" drop constraint "foo"'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop index', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropIndex('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2015-07-15 23:16:30 -03:00
|
|
|
expect(tableSql[0].sql).to.equal('drop index "users_foo_index"');
|
2015-04-22 10:34:14 -04:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop index, custom', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropIndex(null, 'foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2015-07-15 23:16:30 -03:00
|
|
|
expect(tableSql[0].sql).to.equal('drop index "foo"');
|
2015-04-22 10:34:14 -04:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop index, with schema', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.withSchema('mySchema')
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropIndex('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-06-09 18:07:57 -04:00
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal('drop index "mySchema"."users_foo_index"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop foreign', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropForeign('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" drop constraint "users_foo_foreign"'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop foreign', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropForeign(null, 'foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" drop constraint "foo"'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('drop timestamps', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dropTimestamps();
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" drop column "created_at", drop column "updated_at"'
|
|
|
|
);
|
2015-04-22 10:34:14 -04:00
|
|
|
});
|
|
|
|
|
2021-07-25 17:23:17 +10:00
|
|
|
it('adds foreign key with deferrable initially immediate', function () {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.createTable('person', function (table) {
|
|
|
|
table
|
|
|
|
.integer('user_id')
|
|
|
|
.notNull()
|
|
|
|
.references('users.id')
|
|
|
|
.deferrable('immediate');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(2, tableSql.length);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "person" add constraint "person_user_id_foreign" foreign key ("user_id") references "users" ("id") deferrable initially immediate '
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds unique constraint with deferrable initially immediate', function () {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.createTable('person', function (table) {
|
|
|
|
table
|
|
|
|
.integer('user_id')
|
|
|
|
.unique({ indexName: 'user_id_index', deferrable: 'immediate' });
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(2, tableSql.length);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "person" add constraint "user_id_index" unique ("user_id") deferrable initially immediate'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds primary constraint with deferrable initially immediate', function () {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.createTable('person', function (table) {
|
|
|
|
table.integer('user_id').primary({
|
|
|
|
constraintName: 'user_id_primary',
|
|
|
|
deferrable: 'immediate',
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(2, tableSql.length);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "person" add constraint "user_id_primary" primary key ("user_id") deferrable initially immediate'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('rename table', function () {
|
|
|
|
tableSql = client.schemaBuilder().renameTable('users', 'foo').toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal('alter table "users" rename to "foo"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('rename column', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.renameColumn('foo', 'bar');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-06-09 23:53:25 +02:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" rename "foo" to "bar"'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding primary key', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.primary('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add constraint "users_pkey" primary key ("foo")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding primary key fluently', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.string('name').primary();
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(2, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'create table "users" ("name" varchar(255))'
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "users" add constraint "users_pkey" primary key ("name")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding foreign key', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function () {
|
|
|
|
this.foreign('foo_id').references('id').on('orders');
|
2018-07-09 08:10:34 -04:00
|
|
|
})
|
|
|
|
.toSQL();
|
2017-02-17 00:35:43 +02:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add constraint "users_foo_id_foreign" foreign key ("foo_id") references "orders" ("id")'
|
|
|
|
);
|
|
|
|
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function () {
|
|
|
|
this.integer('foo_id').references('id').on('orders');
|
2018-07-09 08:10:34 -04:00
|
|
|
})
|
|
|
|
.toSQL();
|
2017-02-17 00:35:43 +02:00
|
|
|
equal(2, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo_id" integer'
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "users" add constraint "users_foo_id_foreign" foreign key ("foo_id") references "orders" ("id")'
|
|
|
|
);
|
2017-02-17 00:35:43 +02:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding foreign key with specific identifier', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function () {
|
|
|
|
this.foreign('foo_id', 'fk_foo').references('id').on('orders');
|
2018-07-09 08:10:34 -04:00
|
|
|
})
|
|
|
|
.toSQL();
|
2017-02-17 00:35:43 +02:00
|
|
|
|
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add constraint "fk_foo" foreign key ("foo_id") references "orders" ("id")'
|
|
|
|
);
|
|
|
|
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
this.integer('foo_id')
|
|
|
|
.references('id')
|
|
|
|
.on('orders')
|
|
|
|
.withKeyName('fk_foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-02-17 00:35:43 +02:00
|
|
|
|
|
|
|
equal(2, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo_id" integer'
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "users" add constraint "fk_foo" foreign key ("foo_id") references "orders" ("id")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adds foreign key with onUpdate and onDelete', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('person', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table
|
|
|
|
.integer('user_id')
|
|
|
|
.notNull()
|
|
|
|
.references('users.id')
|
|
|
|
.onDelete('SET NULL');
|
|
|
|
table
|
|
|
|
.integer('account_id')
|
|
|
|
.notNull()
|
|
|
|
.references('id')
|
|
|
|
.inTable('accounts')
|
|
|
|
.onUpdate('cascade');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(3, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "person" add constraint "person_user_id_foreign" foreign key ("user_id") references "users" ("id") on delete SET NULL'
|
|
|
|
);
|
|
|
|
expect(tableSql[2].sql).to.equal(
|
|
|
|
'alter table "person" add constraint "person_account_id_foreign" foreign key ("account_id") references "accounts" ("id") on update cascade'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding unique key', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.unique('foo', 'bar');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add constraint "bar" unique ("foo")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding unique key fluently', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.string('email').unique();
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(2, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'create table "users" ("email" varchar(255))'
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "users" add constraint "users_email_unique" unique ("email")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding index without value', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.index(['foo', 'bar']);
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'create index "users_foo_bar_index" on "users" ("foo", "bar")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding index', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.index(['foo', 'bar'], 'baz');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'create index "baz" on "users" ("foo", "bar")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding index fluently', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.string('name').index();
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(2, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "name" varchar(255)'
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'create index "users_name_index" on "users" ("name")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding index with an index type', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.index(['foo', 'bar'], 'baz', 'gist');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'create index "baz" on "users" using gist ("foo", "bar")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding index with an index type fluently', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.string('name').index('baz', 'gist');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(2, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "name" varchar(255)'
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'create index "baz" on "users" using gist ("name")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding index with an index type and default name fluently', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.string('name').index(null, 'gist');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(2, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "name" varchar(255)'
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'create index "users_name_index" on "users" using gist ("name")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding incrementing id', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.increments('id');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "id" serial primary key'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-02-03 13:47:32 +01:00
|
|
|
it('adding incrementing id without primary key', function () {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', function (table) {
|
|
|
|
table.increments('id', { primaryKey: false });
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "id" serial'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding big incrementing id', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.bigIncrements('id');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "id" bigserial primary key'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-02-03 13:47:32 +01:00
|
|
|
it('adding big incrementing id without primary key', function () {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', function (table) {
|
|
|
|
table.bigIncrements('id', { primaryKey: false });
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "id" bigserial'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding string', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.string('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" varchar(255)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding varchar with length', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.string('foo', 100);
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" varchar(100)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding a string with a default', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.string('foo', 100).defaultTo('bar');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" varchar(100) default \'bar\''
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding text', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.text('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" text'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding big integer', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.bigInteger('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" bigint'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('tests a big integer as the primary autoincrement key', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.bigIncrements('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" bigserial primary key'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding integer', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.integer('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" integer'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding autoincrement integer', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.increments('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" serial primary key'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding medium integer', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.mediumint('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" integer'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding tiny integer', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.tinyint('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" smallint'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding small integer', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.smallint('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" smallint'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding float', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.float('foo', 5, 2);
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" real'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding double', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.double('foo', 15, 8);
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" double precision'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding decimal', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.decimal('foo', 5, 2);
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" decimal(5, 2)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding decimal, variable precision', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.decimal('foo', null);
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-11-30 15:05:39 -06:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" decimal'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding boolean', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.boolean('foo').defaultTo(false);
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" boolean default \'0\''
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding enum', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.enum('foo', ['bar', 'baz']);
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" text check ("foo" in (\'bar\', \'baz\'))'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding enum with useNative', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table
|
|
|
|
.enu('foo', ['bar', 'baz'], {
|
|
|
|
useNative: true,
|
|
|
|
enumName: 'foo_type',
|
|
|
|
})
|
|
|
|
.notNullable();
|
|
|
|
})
|
|
|
|
.toSQL();
|
2018-05-29 10:09:13 -04:00
|
|
|
equal(2, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
"create type \"foo_type\" as enum ('bar', 'baz')"
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" "foo_type" not null'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding enum with useNative and withSchema', function () {
|
2019-08-24 18:37:29 +03:00
|
|
|
const schema = 'test';
|
|
|
|
const enumName = 'foo_type';
|
|
|
|
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.withSchema(schema)
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2019-08-24 18:37:29 +03:00
|
|
|
table
|
|
|
|
.enu('foo', ['bar', 'baz'], {
|
|
|
|
useNative: true,
|
|
|
|
schema: true,
|
|
|
|
enumName,
|
|
|
|
})
|
|
|
|
.notNullable();
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(2, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
`create type "${schema}"."${enumName}" as enum ('bar', 'baz')`
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
`alter table "${schema}"."users" add column "foo" "${schema}"."${enumName}" not null`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding enum with useNative and existingType', function () {
|
2018-11-09 00:47:15 -08:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.raw("create type \"foo_type\" as enum ('bar', 'baz')")
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-11-09 00:47:15 -08:00
|
|
|
table
|
|
|
|
.enu('foo', ['bar', 'baz'], {
|
|
|
|
useNative: true,
|
|
|
|
existingType: true,
|
|
|
|
enumName: 'foo_type',
|
|
|
|
})
|
|
|
|
.notNullable();
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(2, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
"create type \"foo_type\" as enum ('bar', 'baz')"
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" "foo_type" not null'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding enum with useNative and existingType works without enum values', function () {
|
2018-11-09 00:47:15 -08:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.raw("create type \"foo_type\" as enum ('bar', 'baz')")
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-11-09 00:47:15 -08:00
|
|
|
table
|
|
|
|
.enu('foo', undefined, {
|
|
|
|
useNative: true,
|
|
|
|
existingType: true,
|
|
|
|
enumName: 'foo_type',
|
|
|
|
})
|
|
|
|
.notNullable();
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(2, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
"create type \"foo_type\" as enum ('bar', 'baz')"
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" "foo_type" not null'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding enum with useNative, from manually defined schema and withSchema', function () {
|
2019-08-26 00:07:30 +03:00
|
|
|
const tableSchema = 'table_schema';
|
|
|
|
const tableName = 'table_name';
|
|
|
|
const typeSchema = 'type_schema';
|
|
|
|
const typeName = 'type_name';
|
|
|
|
const columnName = 'column_name';
|
|
|
|
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.withSchema(tableSchema)
|
2020-04-19 00:40:23 +02:00
|
|
|
.table(tableName, function (table) {
|
2019-08-26 00:07:30 +03:00
|
|
|
table.enu(columnName, ['foo', 'bar', 'baz'], {
|
|
|
|
useNative: true,
|
|
|
|
schemaName: typeSchema,
|
|
|
|
enumName: typeName,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(2, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
`create type "${typeSchema}"."${typeName}" as enum ('foo', 'bar', 'baz')`
|
|
|
|
);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
`alter table "${tableSchema}"."${tableName}" add column "${columnName}" "${typeSchema}"."${typeName}"`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding enum with useNative and existingType, from manually defined schema and withSchema', function () {
|
2019-08-26 00:07:30 +03:00
|
|
|
const tableSchema = 'table_schema';
|
|
|
|
const tableName = 'table_name';
|
|
|
|
const typeSchema = 'type_schema';
|
|
|
|
const typeName = 'type_name';
|
|
|
|
const columnName = 'column_name';
|
|
|
|
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.withSchema(tableSchema)
|
2020-04-19 00:40:23 +02:00
|
|
|
.table(tableName, function (table) {
|
2019-08-26 00:07:30 +03:00
|
|
|
table.enu(columnName, null, {
|
|
|
|
useNative: true,
|
|
|
|
schemaName: typeSchema,
|
|
|
|
enumName: typeName,
|
|
|
|
existingType: true,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
`alter table "${tableSchema}"."${tableName}" add column "${columnName}" "${typeSchema}"."${typeName}"`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-01-16 06:16:00 -08:00
|
|
|
it('adding enum with useNative and alter', function () {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', function (table) {
|
|
|
|
table
|
|
|
|
.enu('foo', ['bar', 'baz'], {
|
|
|
|
useNative: true,
|
|
|
|
enumName: 'foo_type',
|
|
|
|
})
|
|
|
|
.notNullable()
|
|
|
|
.alter();
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(5, tableSql.length);
|
|
|
|
|
|
|
|
const expectedSql = [
|
|
|
|
"create type \"foo_type\" as enum ('bar', 'baz')",
|
|
|
|
'alter table "users" alter column "foo" drop default',
|
|
|
|
'alter table "users" alter column "foo" drop not null',
|
|
|
|
'alter table "users" alter column "foo" type "foo_type" using ("foo"::text::"foo_type")',
|
|
|
|
'alter table "users" alter column "foo" set not null',
|
|
|
|
];
|
|
|
|
|
|
|
|
for (let i = 0; i < tableSql.length; i++) {
|
|
|
|
expect(tableSql[i].sql).to.equal(expectedSql[i]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adding multiple useNative enums with some alters', function () {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', function (table) {
|
|
|
|
table
|
|
|
|
.enu('foo', ['bar', 'baz'], {
|
|
|
|
useNative: true,
|
|
|
|
enumName: 'foo_type',
|
|
|
|
})
|
|
|
|
.notNullable()
|
|
|
|
.alter();
|
|
|
|
|
|
|
|
table.enu('bar', ['foo', 'baz'], {
|
|
|
|
useNative: true,
|
|
|
|
enumName: 'bar_type',
|
|
|
|
});
|
|
|
|
|
|
|
|
table
|
|
|
|
.enu('baz', ['foo', 'bar'], {
|
|
|
|
useNative: true,
|
|
|
|
enumName: 'baz_type',
|
|
|
|
})
|
|
|
|
.defaultTo('foo')
|
|
|
|
.alter();
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(12, tableSql.length);
|
|
|
|
|
|
|
|
const expectedSql = [
|
|
|
|
"create type \"baz_type\" as enum ('foo', 'bar')",
|
|
|
|
"create type \"foo_type\" as enum ('bar', 'baz')",
|
|
|
|
"create type \"bar_type\" as enum ('foo', 'baz')",
|
|
|
|
|
|
|
|
'alter table "users" add column "bar" "bar_type"',
|
|
|
|
|
|
|
|
'alter table "users" alter column "foo" drop default',
|
|
|
|
'alter table "users" alter column "foo" drop not null',
|
|
|
|
'alter table "users" alter column "foo" type "foo_type" using ("foo"::text::"foo_type")',
|
|
|
|
'alter table "users" alter column "foo" set not null',
|
|
|
|
|
|
|
|
'alter table "users" alter column "baz" drop default',
|
|
|
|
'alter table "users" alter column "baz" drop not null',
|
|
|
|
'alter table "users" alter column "baz" type "baz_type" using ("baz"::text::"baz_type")',
|
|
|
|
'alter table "users" alter column "baz" set default \'foo\'',
|
|
|
|
];
|
|
|
|
|
|
|
|
for (let i = 0; i < tableSql.length; i++) {
|
|
|
|
expect(tableSql[i].sql).to.equal(expectedSql[i]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding date', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.date('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" date'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-26 10:22:27 +01:00
|
|
|
it('adding date time', () => {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2018-11-26 10:22:27 +01:00
|
|
|
.table('users', (table) => {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.dateTime('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-26 10:22:27 +01:00
|
|
|
it('adding time', () => {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2018-11-26 10:22:27 +01:00
|
|
|
.table('users', (table) => {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.time('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" time'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-26 10:22:27 +01:00
|
|
|
it('adding default timestamp', () => {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2018-11-26 10:22:27 +01:00
|
|
|
.table('users', (table) => {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.timestamp('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-07-21 08:23:20 +10:00
|
|
|
it('adding default datetime', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.datetime('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-26 10:22:27 +01:00
|
|
|
it('adding timestamp with timezone', () => {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2018-11-26 10:22:27 +01:00
|
|
|
.table('users', (table) => {
|
|
|
|
table.timestamp('foo', false);
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-07-21 08:23:20 +10:00
|
|
|
it('adding datetime with timezone', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.datetime('foo', false);
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-26 10:22:27 +01:00
|
|
|
it('adding timestamp without timezone', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.timestamp('foo', true);
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamp'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-07-21 08:23:20 +10:00
|
|
|
it('adding datetime without timezone', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.datetime('foo', true);
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamp'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-26 10:22:27 +01:00
|
|
|
it('adding timestamp with precision', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.timestamp('foo', undefined, 2);
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz(2)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-07-21 08:23:20 +10:00
|
|
|
it('adding datetime with precision', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.datetime('foo', undefined, 3);
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz(3)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-26 10:22:27 +01:00
|
|
|
it('adding timestamp with options object', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.timestamp('foo', { useTz: false, precision: 3 });
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamp(3)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-07-21 08:23:20 +10:00
|
|
|
it('adding timestamp with options object but no timestamp', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.timestamp('foo', { precision: 3 });
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz(3)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adding timestamp with empty options object', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.timestamp('foo', {});
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-26 10:22:27 +01:00
|
|
|
it('adding datetime with options object', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.datetime('foo', { useTz: false, precision: 3 });
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamp(3)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-07-21 08:23:20 +10:00
|
|
|
it('adding datetime with options object but no timestamp', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.datetime('foo', { precision: 3 });
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz(3)'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adding datetime with empty options object', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
|
|
|
table.datetime('foo', {});
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" timestamptz'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-26 10:22:27 +01:00
|
|
|
it('adding timestamps', () => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.table('users', (table) => {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.timestamps();
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "created_at" timestamptz, add column "updated_at" timestamptz'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-26 10:22:27 +01:00
|
|
|
it('adding timestamps with defaults', () => {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2018-11-26 10:22:27 +01:00
|
|
|
.table('users', (table) => {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.timestamps(false, true);
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-12-23 01:15:23 +01:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "created_at" timestamptz not null default CURRENT_TIMESTAMP, add column "updated_at" timestamptz not null default CURRENT_TIMESTAMP'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding binary', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-07-09 08:10:34 -04:00
|
|
|
table.binary('foo');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add column "foo" bytea'
|
|
|
|
);
|
2015-04-22 10:34:14 -04:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('adding jsonb', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('user', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.jsonb('preferences');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "user" add column "preferences" jsonb'
|
|
|
|
);
|
2015-04-22 10:34:14 -04:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('set comment', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('user', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.comment('Custom comment');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-06-10 19:47:51 +02:00
|
|
|
equal(1, tableSql.length);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'comment on table "user" is \'Custom comment\''
|
|
|
|
);
|
2017-06-10 19:47:51 +02:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('set empty comment', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('user', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.comment('');
|
|
|
|
})
|
|
|
|
.toSQL();
|
2017-06-10 19:47:51 +02:00
|
|
|
equal(1, tableSql.length);
|
|
|
|
expect(tableSql[0].sql).to.equal('comment on table "user" is \'\'');
|
|
|
|
});
|
|
|
|
|
2020-10-27 10:05:21 +02:00
|
|
|
it('test column comment with quotes', function () {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.createTable('test', (t) => {
|
|
|
|
t.text('column1').comment("The table's first column and it's escaped");
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
|
|
|
|
equal(tableSql.length, 2);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
"comment on column \"test\".\"column1\" is 'The table''s first column and it''s escaped'"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test column comment with pre-escaped quotes', function () {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
|
|
|
.createTable('test', (t) => {
|
|
|
|
t.text('column1').comment(
|
|
|
|
"The table''s first column and it''s escaped"
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
|
|
|
|
equal(tableSql.length, 2);
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
"comment on column \"test\".\"column1\" is 'The table''s first column and it''s escaped'"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('set comment to undefined', function () {
|
|
|
|
expect(function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('user', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.comment();
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
}).to.throw(TypeError);
|
2017-10-31 23:22:07 +01:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('set comment to null', function () {
|
|
|
|
expect(function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('user', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.comment(null);
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
}).to.throw(TypeError);
|
2017-10-31 23:22:07 +01:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('allows adding default json objects when the column is json', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('user', function (t) {
|
|
|
|
t.json('preferences').defaultTo({}).notNullable();
|
2018-07-09 08:10:34 -04:00
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
2019-06-30 23:38:15 +05:30
|
|
|
'alter table "user" add column "preferences" json not null default \'{}\''
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('allows adding default jsonb objects when the column is json', function () {
|
2019-06-30 23:38:15 +05:30
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('user', function (t) {
|
|
|
|
t.jsonb('preferences').defaultTo({}).notNullable();
|
2019-06-30 23:38:15 +05:30
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "user" add column "preferences" jsonb not null default \'{}\''
|
2018-07-09 08:10:34 -04:00
|
|
|
);
|
2015-04-22 10:34:14 -04:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('sets specificType correctly', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('user', function (t) {
|
|
|
|
t.specificType('email', 'CITEXT').unique().notNullable();
|
2018-07-09 08:10:34 -04:00
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "user" add column "email" CITEXT not null'
|
|
|
|
);
|
2015-04-22 10:34:14 -04:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('allows creating an extension', function () {
|
|
|
|
const sql = client.schemaBuilder().createExtension('test').toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
expect(sql[0].sql).to.equal('create extension "test"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('allows dropping an extension', function () {
|
|
|
|
const sql = client.schemaBuilder().dropExtension('test').toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
expect(sql[0].sql).to.equal('drop extension "test"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it("allows creating an extension only if it doesn't exist", function () {
|
2018-10-15 22:29:53 -04:00
|
|
|
const sql = client
|
2018-07-09 08:10:34 -04:00
|
|
|
.schemaBuilder()
|
|
|
|
.createExtensionIfNotExists('test')
|
|
|
|
.toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
expect(sql[0].sql).to.equal('create extension if not exists "test"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('allows dropping an extension only if it exists', function () {
|
|
|
|
const sql = client.schemaBuilder().dropExtensionIfExists('test').toSQL();
|
2015-04-22 10:34:14 -04:00
|
|
|
expect(sql[0].sql).to.equal('drop extension if exists "test"');
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('table inherits another table', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('inheriteeTable', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.string('username');
|
|
|
|
t.inherits('inheritedTable');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'create table "inheriteeTable" ("username" varchar(255)) inherits ("inheritedTable")'
|
|
|
|
);
|
2016-03-15 16:31:07 -07:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('should warn on disallowed method', function () {
|
2019-11-21 19:52:29 +05:30
|
|
|
expect(() => {
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('users', function (t) {
|
2019-11-21 19:52:29 +05:30
|
|
|
t.string('username');
|
|
|
|
t.engine('myISAM');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
}).to.throw('Knex only supports engine statement with mysql');
|
2016-03-15 16:31:07 -07:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('#1430 - .primary & .dropPrimary takes columns and constraintName', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.primary(['test1', 'test2'], 'testconstraintname');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
expect(tableSql[0].sql).to.equal(
|
|
|
|
'alter table "users" add constraint "testconstraintname" primary key ("test1", "test2")'
|
|
|
|
);
|
|
|
|
|
|
|
|
tableSql = client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('users', function (t) {
|
2018-07-09 08:10:34 -04:00
|
|
|
t.string('test').primary('testconstraintname');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
|
|
|
|
expect(tableSql[1].sql).to.equal(
|
|
|
|
'alter table "users" add constraint "testconstraintname" primary key ("test")'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
describe('queryContext', function () {
|
2018-02-01 23:41:01 +01:00
|
|
|
let spy;
|
|
|
|
let originalWrapIdentifier;
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
before(function () {
|
2018-02-01 23:41:01 +01:00
|
|
|
spy = sinon.spy();
|
|
|
|
originalWrapIdentifier = client.config.wrapIdentifier;
|
2020-04-19 00:40:23 +02:00
|
|
|
client.config.wrapIdentifier = function (value, wrap, queryContext) {
|
2018-02-01 23:41:01 +01:00
|
|
|
spy(value, queryContext);
|
|
|
|
return wrap(value);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
beforeEach(function () {
|
2018-07-07 09:47:51 +02:00
|
|
|
spy.resetHistory();
|
2018-02-01 23:41:01 +01:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
after(function () {
|
2018-02-01 23:41:01 +01:00
|
|
|
client.config.wrapIdentifier = originalWrapIdentifier;
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('SchemaCompiler passes queryContext to wrapIdentifier via TableCompiler', function () {
|
2018-02-01 23:41:01 +01:00
|
|
|
client
|
|
|
|
.schemaBuilder()
|
|
|
|
.queryContext('table context')
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('users', function (table) {
|
2018-02-01 23:41:01 +01:00
|
|
|
table.increments('id');
|
|
|
|
table.string('email');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
|
|
|
|
expect(spy.callCount).to.equal(3);
|
|
|
|
expect(spy.firstCall.args).to.deep.equal(['id', 'table context']);
|
|
|
|
expect(spy.secondCall.args).to.deep.equal(['email', 'table context']);
|
|
|
|
expect(spy.thirdCall.args).to.deep.equal(['users', 'table context']);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('TableCompiler passes queryContext to wrapIdentifier', function () {
|
2018-02-01 23:41:01 +01:00
|
|
|
client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('users', function (table) {
|
2018-02-01 23:41:01 +01:00
|
|
|
table.increments('id').queryContext('id context');
|
|
|
|
table.string('email').queryContext('email context');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
|
|
|
|
expect(spy.callCount).to.equal(3);
|
|
|
|
expect(spy.firstCall.args).to.deep.equal(['id', 'id context']);
|
|
|
|
expect(spy.secondCall.args).to.deep.equal(['email', 'email context']);
|
|
|
|
expect(spy.thirdCall.args).to.deep.equal(['users', undefined]);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('TableCompiler allows overwriting queryContext from SchemaCompiler', function () {
|
2018-02-01 23:41:01 +01:00
|
|
|
client
|
|
|
|
.schemaBuilder()
|
|
|
|
.queryContext('schema context')
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('users', function (table) {
|
2018-02-01 23:41:01 +01:00
|
|
|
table.queryContext('table context');
|
|
|
|
table.increments('id');
|
|
|
|
table.string('email');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
|
|
|
|
expect(spy.callCount).to.equal(3);
|
|
|
|
expect(spy.firstCall.args).to.deep.equal(['id', 'table context']);
|
|
|
|
expect(spy.secondCall.args).to.deep.equal(['email', 'table context']);
|
|
|
|
expect(spy.thirdCall.args).to.deep.equal(['users', 'table context']);
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('ColumnCompiler allows overwriting queryContext from TableCompiler', function () {
|
2018-02-01 23:41:01 +01:00
|
|
|
client
|
|
|
|
.schemaBuilder()
|
|
|
|
.queryContext('schema context')
|
2020-04-19 00:40:23 +02:00
|
|
|
.createTable('users', function (table) {
|
2018-02-01 23:41:01 +01:00
|
|
|
table.queryContext('table context');
|
|
|
|
table.increments('id').queryContext('id context');
|
|
|
|
table.string('email').queryContext('email context');
|
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
|
|
|
|
expect(spy.callCount).to.equal(3);
|
|
|
|
expect(spy.firstCall.args).to.deep.equal(['id', 'id context']);
|
|
|
|
expect(spy.secondCall.args).to.deep.equal(['email', 'email context']);
|
|
|
|
expect(spy.thirdCall.args).to.deep.equal(['users', 'table context']);
|
|
|
|
});
|
2018-05-30 07:57:51 -07:00
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('TableCompiler calls wrapIdentifier when altering column', function () {
|
2018-05-30 07:57:51 -07:00
|
|
|
client
|
|
|
|
.schemaBuilder()
|
2020-04-19 00:40:23 +02:00
|
|
|
.table('users', function (table) {
|
2018-05-30 07:57:51 -07:00
|
|
|
table.queryContext('table context');
|
2018-07-09 08:10:34 -04:00
|
|
|
table
|
|
|
|
.string('email')
|
|
|
|
.notNull()
|
|
|
|
.alter()
|
|
|
|
.queryContext('email alter context');
|
2018-05-30 07:57:51 -07:00
|
|
|
})
|
|
|
|
.toSQL();
|
|
|
|
|
|
|
|
expect(spy.callCount).to.equal(3);
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(spy.thirdCall.args).to.deep.equal([
|
|
|
|
'email',
|
|
|
|
'email alter context',
|
|
|
|
]);
|
|
|
|
});
|
2018-02-01 23:41:01 +01:00
|
|
|
});
|
2015-11-04 13:34:18 +02:00
|
|
|
});
|