2018-10-03 05:02:37 +02:00
|
|
|
// global it, describe, expect
|
|
|
|
|
|
|
|
|
|
'use strict';
|
2018-10-15 22:29:53 -04:00
|
|
|
const sinon = require('sinon');
|
2019-07-10 22:48:43 +01:00
|
|
|
const DDL = require('../../../lib/dialects/sqlite3/schema/ddl');
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
it('[backwards compatible] can rename column with double quotes', function() {
|
|
|
|
|
const client = sinon.stub();
|
|
|
|
|
const tableCompiler = sinon.stub();
|
|
|
|
|
const pragma = sinon.stub();
|
|
|
|
|
const connection = sinon.stub();
|
|
|
|
|
const ddl = new DDL(client, tableCompiler, pragma, connection);
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
const sql =
|
|
|
|
|
'CREATE TABLE "accounts" ("id" varchar(24) not null primary key, "about" varchar(24))';
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
const newSql = ddl._doReplace(sql, '`about`', '`about_me`');
|
|
|
|
|
newSql.should.eql(
|
2019-10-06 18:27:52 +02:00
|
|
|
'CREATE TABLE "accounts" ("id" varchar(24) not null primary key, `about_me` varchar(24))'
|
2019-03-13 22:58:59 +01:00
|
|
|
);
|
|
|
|
|
});
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
it('[backwards compatible] can rename column with double quotes', function() {
|
|
|
|
|
const client = sinon.stub();
|
|
|
|
|
const tableCompiler = sinon.stub();
|
|
|
|
|
const pragma = sinon.stub();
|
|
|
|
|
const connection = sinon.stub();
|
|
|
|
|
const ddl = new DDL(client, tableCompiler, pragma, connection);
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
const sql =
|
|
|
|
|
'CREATE TABLE "accounts" ("id" varchar(24) not null primary key, "about" varchar(24))';
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
const newSql = ddl._doReplace(sql, '"about"', '"about_me"');
|
|
|
|
|
newSql.should.eql(
|
|
|
|
|
'CREATE TABLE "accounts" ("id" varchar(24) not null primary key, "about_me" varchar(24))'
|
|
|
|
|
);
|
|
|
|
|
});
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
it('[backwards compatible] can rename column with double quotes', function() {
|
|
|
|
|
const client = sinon.stub();
|
|
|
|
|
const tableCompiler = sinon.stub();
|
|
|
|
|
const pragma = sinon.stub();
|
|
|
|
|
const connection = sinon.stub();
|
|
|
|
|
const ddl = new DDL(client, tableCompiler, pragma, connection);
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
const sql =
|
|
|
|
|
'CREATE TABLE "accounts" ("id" varchar(24) not null primary key, "about" varchar(24))';
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
const newSql = ddl._doReplace(sql, '"about"', '`about_me`');
|
|
|
|
|
newSql.should.eql(
|
2019-10-06 18:27:52 +02:00
|
|
|
'CREATE TABLE "accounts" ("id" varchar(24) not null primary key, `about_me` varchar(24))'
|
2019-03-13 22:58:59 +01:00
|
|
|
);
|
|
|
|
|
});
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
it('can rename column with back sticks', function() {
|
|
|
|
|
const client = sinon.stub();
|
|
|
|
|
const tableCompiler = sinon.stub();
|
|
|
|
|
const pragma = sinon.stub();
|
|
|
|
|
const connection = sinon.stub();
|
|
|
|
|
const ddl = new DDL(client, tableCompiler, pragma, connection);
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
const sql =
|
|
|
|
|
'CREATE TABLE `accounts` (`id` varchar(24) not null primary key, `about` varchar(24))';
|
2018-10-03 05:02:37 +02:00
|
|
|
|
2019-03-13 22:58:59 +01:00
|
|
|
const newSql = ddl._doReplace(sql, '`about`', '`about_me`');
|
|
|
|
|
newSql.should.eql(
|
|
|
|
|
'CREATE TABLE `accounts` (`id` varchar(24) not null primary key, `about_me` varchar(24))'
|
|
|
|
|
);
|
2018-10-03 05:02:37 +02:00
|
|
|
});
|
2019-10-06 18:27:52 +02:00
|
|
|
|
|
|
|
|
it('can rename column with multiline and tabulated sql statement', function() {
|
|
|
|
|
const client = sinon.stub();
|
|
|
|
|
const tableCompiler = sinon.stub();
|
|
|
|
|
const pragma = sinon.stub();
|
|
|
|
|
const connection = sinon.stub();
|
|
|
|
|
const ddl = new DDL(client, tableCompiler, pragma, connection);
|
|
|
|
|
|
|
|
|
|
const sql =
|
|
|
|
|
'CREATE TABLE `accounts` (\n\n`id`\tvarchar(24) not null primary key,\r\n`about`\t \t\t \tvarchar(24)\n\n)';
|
|
|
|
|
|
|
|
|
|
const newSql = ddl._doReplace(sql, '`about`', '`about_me`');
|
|
|
|
|
newSql.should.eql(
|
|
|
|
|
'CREATE TABLE `accounts` (`id` varchar(24) not null primary key, `about_me` varchar(24))'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can drop column with multiline and tabulated sql statement', function() {
|
|
|
|
|
const client = sinon.stub();
|
|
|
|
|
const tableCompiler = sinon.stub();
|
|
|
|
|
const pragma = sinon.stub();
|
|
|
|
|
const connection = sinon.stub();
|
|
|
|
|
const ddl = new DDL(client, tableCompiler, pragma, connection);
|
|
|
|
|
|
|
|
|
|
const sql =
|
|
|
|
|
'CREATE TABLE `accounts` (\n\n`id`\tvarchar(24) not null primary key,\r\n`about`\t \tvarchar(24)\n)';
|
|
|
|
|
|
|
|
|
|
const newSql = ddl._doReplace(sql, '`about`', '');
|
|
|
|
|
newSql.should.eql(
|
|
|
|
|
'CREATE TABLE `accounts` (`id` varchar(24) not null primary key)'
|
|
|
|
|
);
|
|
|
|
|
});
|