mirror of
https://github.com/knex/knex.git
synced 2025-11-13 00:24:12 +00:00
73 lines
2.6 KiB
JavaScript
73 lines
2.6 KiB
JavaScript
|
|
// global it, describe, expect
|
||
|
|
|
||
|
|
'use strict';
|
||
|
|
const _ = require('lodash');
|
||
|
|
const expect = require('chai').expect;
|
||
|
|
const DDL = require('../../../lib/dialects/sqlite3/schema/ddl');
|
||
|
|
|
||
|
|
describe('Unit: Sqlite3 - renameColumn', function() {
|
||
|
|
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);
|
||
|
|
|
||
|
|
const sql =
|
||
|
|
'CREATE TABLE "accounts" ("id" varchar(24) not null primary key, "about" varchar(24))';
|
||
|
|
|
||
|
|
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('[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);
|
||
|
|
|
||
|
|
const sql =
|
||
|
|
'CREATE TABLE "accounts" ("id" varchar(24) not null primary key, "about" varchar(24))';
|
||
|
|
|
||
|
|
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('[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);
|
||
|
|
|
||
|
|
const sql =
|
||
|
|
'CREATE TABLE "accounts" ("id" varchar(24) not null primary key, "about" varchar(24))';
|
||
|
|
|
||
|
|
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 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);
|
||
|
|
|
||
|
|
const sql =
|
||
|
|
'CREATE TABLE `accounts` (`id` varchar(24) not null primary key, `about` varchar(24))';
|
||
|
|
|
||
|
|
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))'
|
||
|
|
);
|
||
|
|
});
|
||
|
|
});
|