<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240103075035 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE IF NOT EXISTS oauth_clients (
id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL,
user_id BIGINT,
name varchar(255) NOT NULL,
secret varchar(100),
provider varchar(255),
redirect text NOT NULL,
personal_access_client tinyint(1) NOT NULL,
password_client tinyint(1) NOT NULL,
revoked tinyint(1) NOT NULL,
created_at timestamp,
updated_at timestamp,
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_bin` ENGINE = InnoDB');
$userIndexExists = $this->connection->fetchOne("
SELECT COUNT(*)
FROM information_schema.statistics
WHERE table_name = 'oauth_clients'
AND index_name = 'OAUTH_CLIENTS_USER_ID_INDEX'
AND column_name = 'user_id'
");
$idIndexExists = $this->connection->fetchOne("
SELECT COUNT(*)
FROM information_schema.statistics
WHERE table_name = 'oauth_clients'
AND index_name = 'OAUTH_CLIENTS_ID_INDEX'
AND column_name = 'id'
");
// Add index to user_id column
if (!$userIndexExists) {
$this->addSql('CREATE INDEX OAUTH_CLIENTS_USER_ID_INDEX ON oauth_clients (user_id);');
}
// Add index to id column
if (!$idIndexExists) {
$this->addSql('CREATE UNIQUE INDEX OAUTH_CLIENTS_ID_INDEX ON oauth_clients (id)');
}
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE oauth_clients');
}
}