mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-15 05:45:33 +08:00
add comment control methods
This commit is contained in:
@@ -18,6 +18,7 @@ DROP TABLE IF EXISTS `constraints` CASCADE;
|
||||
DROP TABLE IF EXISTS `animal` CASCADE;
|
||||
DROP TABLE IF EXISTS `default_pk` CASCADE;
|
||||
DROP TABLE IF EXISTS `document` CASCADE;
|
||||
DROP TABLE IF EXISTS `comment` CASCADE;
|
||||
DROP VIEW IF EXISTS `animal_view`;
|
||||
|
||||
CREATE TABLE `constraints`
|
||||
@@ -150,6 +151,14 @@ CREATE TABLE `document` (
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `comment` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`add_comment` VARCHAR(255) NOT NULL,
|
||||
`replace_comment` VARCHAR(255) COMMENT 'comment',
|
||||
`delete_comment` VARCHAR(128) NOT NULL COMMENT 'comment',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE VIEW `animal_view` AS SELECT * FROM `animal`;
|
||||
|
||||
INSERT INTO `animal` (`type`) VALUES ('yiiunit\data\ar\Cat');
|
||||
|
||||
@@ -20,6 +20,7 @@ DROP TABLE IF EXISTS "bool_values" CASCADE;
|
||||
DROP TABLE IF EXISTS "animal" CASCADE;
|
||||
DROP TABLE IF EXISTS "default_pk" CASCADE;
|
||||
DROP TABLE IF EXISTS "document" CASCADE;
|
||||
DROP TABLE IF EXISTS "comment" CASCADE;
|
||||
DROP VIEW IF EXISTS "animal_view";
|
||||
DROP SCHEMA IF EXISTS "schema1" CASCADE;
|
||||
DROP SCHEMA IF EXISTS "schema2" CASCADE;
|
||||
@@ -154,6 +155,12 @@ CREATE TABLE "document" (
|
||||
version integer not null default 0
|
||||
);
|
||||
|
||||
CREATE TABLE "comment" (
|
||||
id serial primary key,
|
||||
name varchar(255) not null,
|
||||
message text not null
|
||||
);
|
||||
|
||||
CREATE VIEW "animal_view" AS SELECT * FROM "animal";
|
||||
|
||||
INSERT INTO "animal" (type) VALUES ('yiiunit\data\ar\Cat');
|
||||
|
||||
@@ -517,4 +517,34 @@ class QueryBuilderTest extends DatabaseTestCase
|
||||
];
|
||||
(new Query())->from('customer')->where($condition)->all($this->getConnection());
|
||||
}
|
||||
|
||||
public function testCommentColumn()
|
||||
{
|
||||
$qb = $this->getQueryBuilder();
|
||||
|
||||
$expected = "ALTER TABLE `comment` CHANGE `add_comment` `add_comment` varchar(255) NOT NULL COMMENT 'This is my column.'";
|
||||
$sql = $qb->addCommentOnColumn('comment', 'add_comment', 'This is my column.');
|
||||
$this->assertEquals($expected, $sql);
|
||||
|
||||
$expected = "ALTER TABLE `comment` CHANGE `replace_comment` `replace_comment` varchar(255) DEFAULT NULL COMMENT 'This is my column.'";
|
||||
$sql = $qb->addCommentOnColumn('comment', 'replace_comment', 'This is my column.');
|
||||
$this->assertEquals($expected, $sql);
|
||||
|
||||
$expected = "ALTER TABLE `comment` CHANGE `delete_comment` `delete_comment` varchar(128) NOT NULL COMMENT ''";
|
||||
$sql = $qb->dropCommentFromColumn('comment', 'delete_comment');
|
||||
$this->assertEquals($expected, $sql);
|
||||
}
|
||||
|
||||
public function testCommentTable()
|
||||
{
|
||||
$qb = $this->getQueryBuilder();
|
||||
|
||||
$expected = "ALTER TABLE `comment` COMMENT 'This is my table.'";
|
||||
$sql = $qb->addCommentOnTable('comment', 'This is my table.');
|
||||
$this->assertEquals($expected, $sql);
|
||||
|
||||
$expected = "ALTER TABLE `comment` COMMENT ''";
|
||||
$sql = $qb->dropCommentFromTable('comment');
|
||||
$this->assertEquals($expected, $sql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,4 +126,30 @@ class PostgreSQLQueryBuilderTest extends QueryBuilderTest
|
||||
$sql = $qb->alterColumn('foo1', 'bar', 'reset xyz');
|
||||
$this->assertEquals($expected, $sql);
|
||||
}
|
||||
|
||||
public function testCommentColumn()
|
||||
{
|
||||
$qb = $this->getQueryBuilder();
|
||||
|
||||
$expected = "COMMENT ON COLUMN \"comment\".\"text\" IS 'This is my column.'";
|
||||
$sql = $qb->addCommentOnColumn('comment', 'text', 'This is my column.');
|
||||
$this->assertEquals($expected, $sql);
|
||||
|
||||
$expected = "COMMENT ON COLUMN \"comment\".\"text\" IS NULL";
|
||||
$sql = $qb->dropCommentFromColumn('comment', 'text');
|
||||
$this->assertEquals($expected, $sql);
|
||||
}
|
||||
|
||||
public function testCommentTable()
|
||||
{
|
||||
$qb = $this->getQueryBuilder();
|
||||
|
||||
$expected = "COMMENT ON TABLE \"comment\" IS 'This is my table.'";
|
||||
$sql = $qb->addCommentOnTable('comment', 'This is my table.');
|
||||
$this->assertEquals($expected, $sql);
|
||||
|
||||
$expected = "COMMENT ON TABLE \"comment\" IS NULL";
|
||||
$sql = $qb->dropCommentFromTable('comment');
|
||||
$this->assertEquals($expected, $sql);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user