app/DoctrineMigrations/Version20240103075035.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20240103075035 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->addSql('CREATE TABLE IF NOT EXISTS oauth_clients (
  19.             id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL,
  20.             user_id BIGINT,
  21.             name varchar(255) NOT NULL,
  22.             secret varchar(100),
  23.             provider varchar(255),
  24.             redirect text NOT NULL,
  25.             personal_access_client tinyint(1) NOT NULL,
  26.             password_client tinyint(1) NOT NULL,
  27.             revoked tinyint(1) NOT NULL,
  28.             created_at timestamp,
  29.             updated_at timestamp,
  30.             PRIMARY KEY(id)
  31.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_bin` ENGINE = InnoDB');
  32.         $userIndexExists $this->connection->fetchOne("
  33.                 SELECT COUNT(*)
  34.                 FROM information_schema.statistics
  35.                 WHERE table_name = 'oauth_clients'
  36.                     AND index_name = 'OAUTH_CLIENTS_USER_ID_INDEX'
  37.                     AND column_name = 'user_id'
  38.                 ");
  39.         $idIndexExists $this->connection->fetchOne("
  40.                 SELECT COUNT(*)
  41.                 FROM information_schema.statistics
  42.                 WHERE table_name = 'oauth_clients'
  43.                     AND index_name = 'OAUTH_CLIENTS_ID_INDEX'
  44.                     AND column_name = 'id'
  45.                 ");
  46.         // Add index to user_id column
  47.         if (!$userIndexExists) {
  48.             $this->addSql('CREATE INDEX OAUTH_CLIENTS_USER_ID_INDEX ON oauth_clients (user_id);');
  49.         }
  50.         // Add index to id column
  51.         if (!$idIndexExists) {
  52.             $this->addSql('CREATE UNIQUE INDEX OAUTH_CLIENTS_ID_INDEX ON oauth_clients (id)');
  53.         }
  54.     }
  55.     public function down(Schema $schema): void
  56.     {
  57.         // this down() migration is auto-generated, please modify it to your needs
  58.         $this->addSql('DROP TABLE oauth_clients');
  59.     }
  60. }