2023-08-15 23:36:56 +02:00
< ? php
declare ( strict_types = 1 );
namespace DoctrineMigrations ;
2023-09-18 16:36:08 +02:00
use App\Migration\AbstractMultiPlatformMigration ;
2023-08-15 23:36:56 +02:00
use Doctrine\DBAL\Schema\Schema ;
use Doctrine\Migrations\AbstractMigration ;
/**
* Auto - generated Migration : Please modify to your needs !
*/
2023-09-18 16:36:08 +02:00
final class Version20230816213201 extends AbstractMultiPlatformMigration
2023-08-15 23:36:56 +02:00
{
public function getDescription () : string
{
2023-09-18 16:36:08 +02:00
return 'Add table for API tokens' ;
2023-08-15 23:36:56 +02:00
}
2023-09-18 16:36:08 +02:00
public function mySQLUp ( Schema $schema ) : void
2023-08-15 23:36:56 +02:00
{
2023-08-17 00:17:02 +02:00
$this -> addSql ( 'CREATE TABLE api_tokens (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, valid_until DATETIME DEFAULT NULL, token VARCHAR(68) NOT NULL, level SMALLINT NOT NULL, last_time_used DATETIME DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, UNIQUE INDEX UNIQ_2CAD560E5F37A13B (token), INDEX IDX_2CAD560EA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB' );
2023-08-15 23:36:56 +02:00
$this -> addSql ( 'ALTER TABLE api_tokens ADD CONSTRAINT FK_2CAD560EA76ED395 FOREIGN KEY (user_id) REFERENCES `users` (id)' );
}
2023-09-18 16:36:08 +02:00
public function mySQLDown ( Schema $schema ) : void
2023-08-15 23:36:56 +02:00
{
$this -> addSql ( 'ALTER TABLE api_tokens DROP FOREIGN KEY FK_2CAD560EA76ED395' );
$this -> addSql ( 'DROP TABLE api_tokens' );
}
2023-09-18 16:36:08 +02:00
public function sqLiteUp ( Schema $schema ) : void
{
$this -> addSql ( 'CREATE TABLE api_tokens (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id INTEGER DEFAULT NULL, name VARCHAR(255) NOT NULL, valid_until DATETIME DEFAULT NULL, token VARCHAR(68) NOT NULL, level SMALLINT NOT NULL, last_time_used DATETIME DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CONSTRAINT FK_2CAD560EA76ED395 FOREIGN KEY (user_id) REFERENCES "users" (id) NOT DEFERRABLE INITIALLY IMMEDIATE)' );
$this -> addSql ( 'CREATE UNIQUE INDEX UNIQ_2CAD560E5F37A13B ON api_tokens (token)' );
$this -> addSql ( 'CREATE INDEX IDX_2CAD560EA76ED395 ON api_tokens (user_id)' );
}
public function sqLiteDown ( Schema $schema ) : void
{
$this -> addSql ( 'DROP TABLE api_tokens' );
}
2023-08-15 23:36:56 +02:00
}