public function tearDown() { parent::tearDown(); $q = new DropTableQuery('products'); $q->IfExists(); $this->assertQuery($q); $q = new DropTableQuery('users'); $q->IfExists(); $this->assertQuery($q); }
public function cleanUpTables() { foreach (array('products', 'users', 'products_new') as $table) { $dropQuery = new DropTableQuery($table); $dropQuery->IfExists(); $this->assertDriverQuery(new MySQLDriver(), $dropQuery); $this->assertDriverQuery(new PgSQLDriver(), $dropQuery); $this->assertDriverQuery(new SQLiteDriver(), $dropQuery); } }
public function testDropTable() { $q = new CreateTableQuery('points'); $q->column('x')->float(10, 2); $q->column('y')->float(10, 2); $this->assertQuery($q); $q = new DropTableQuery('points'); $q->drop('users'); $q->drop('books'); $q->ifExists(); $this->assertQuery($q); }
public function setUp() { parent::setUp(); $q = new DropTableQuery('users'); $q->ifExists(); $this->assertQuery($q); $q = new CreateTableQuery('users'); $q->column('id')->integer()->primary()->autoIncrement(); $q->column('first_name')->varchar(32); $q->column('last_name')->varchar(16); $q->column('age')->tinyint(3)->unsigned()->null(); $q->column('phone')->varchar(24)->null(); $q->column('email')->varchar(128)->notNull(); $q->column('confirmed')->boolean()->default(false); $q->column('types')->set('student', 'teacher'); $q->column('remark')->text(); $q->index(['first_name', 'last_name'])->name('username_idx'); $this->assertQuery($q); }
public function testCreateTableQuery() { $q = new CreateTableQuery('groups'); $q->column('id')->integer()->primary()->autoIncrement(); $q->engine('InnoDB'); $this->assertQuery($q); $q = new CreateTableQuery('users'); $q->table('authors'); $q->column('id')->integer()->primary()->autoIncrement(); $q->column('first_name')->varchar(32); $q->column('last_name')->varchar(16); $q->column('age')->tinyint(3)->unsigned()->null(); $q->column('phone')->varchar(24)->null(); $q->column('email')->varchar(128)->notNull(); $q->column('confirmed')->boolean()->default(false); $q->column('types')->set('student', 'teacher'); $q->column('remark')->text(); $q->column('group_id')->integer(); // create table t1 ( // id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, // product_id integer unsigned, constraint `fk_product_id` // FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ); $q->constraint('fk_group_id')->foreignKey('group_id')->references('groups', 'id')->onDelete('CASCADE')->onUpdate('CASCADE'); $q->uniqueKey('email'); $q->engine('InnoDB'); $dropQuery = new DropTableQuery('authors'); $dropQuery->IfExists(); $this->assertSql('DROP TABLE IF EXISTS `authors`', $dropQuery); $this->assertQuery($dropQuery); $this->assertSql('CREATE TABLE `authors`( `id` int PRIMARY KEY AUTO_INCREMENT, `first_name` varchar(32), `last_name` varchar(16), `age` tinyint(3) UNSIGNED NULL, `phone` varchar(24) NULL, `email` varchar(128) NOT NULL, `confirmed` boolean DEFAULT FALSE, `types` set(\'student\', \'teacher\'), `remark` text, `group_id` int, CONSTRAINT `fk_group_id` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON UPDATE CASCADE ON DELETE CASCADE, UNIQUE KEY (`email`) ) ENGINE=InnoDB', $q); $this->assertQuery($q); $this->assertQuery($dropQuery); // drop again to test the if exists. }