Пример #1
0
 public function install()
 {
     // create schema
     $schema = new Schema();
     $table = $schema->createTable($this->tableName);
     $table->addColumn('id', Type::INTEGER, array('autoincrement' => true));
     $table->addColumn('token', Type::STRING, array('length' => 128, 'unique' => true));
     $table->addColumn('userId', Type::INTEGER);
     $table->addColumn('expires', Type::BIGINT, array('unsigned' => true));
     $table->addIndex(array('token'));
     $table->addIndex(array('expires'));
     $table->setPrimaryKey(array('id'));
     // drop existing table
     if (in_array($this->tableName, $this->connection->getSchemaManager()->listTableNames())) {
         foreach ($schema->toDropSql($this->connection->getDatabasePlatform()) as $sql) {
             $this->connection->exec($sql);
         }
     }
     // create table
     foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
         $this->connection->exec($sql);
     }
 }