2018-12-02 11:43:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Application\Migrations;
|
|
|
|
|
2023-08-05 17:35:09 +00:00
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
|
|
|
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
|
|
|
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
2018-12-02 11:43:05 +00:00
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
2024-02-19 00:30:12 +00:00
|
|
|
use Wallabag\Doctrine\WallabagMigration;
|
2018-12-02 11:43:05 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-05 10:39:51 +00:00
|
|
|
* Add 2fa OTP stuff.
|
2018-12-02 11:43:05 +00:00
|
|
|
*/
|
|
|
|
final class Version20181202073750 extends WallabagMigration
|
|
|
|
{
|
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
2023-08-05 17:35:09 +00:00
|
|
|
$platform = $this->connection->getDatabasePlatform();
|
|
|
|
|
|
|
|
switch (true) {
|
|
|
|
case $platform instanceof SqlitePlatform:
|
2018-12-05 10:39:51 +00:00
|
|
|
$this->addSql('DROP INDEX UNIQ_1D63E7E5C05FB297');
|
|
|
|
$this->addSql('DROP INDEX UNIQ_1D63E7E5A0D96FBF');
|
|
|
|
$this->addSql('DROP INDEX UNIQ_1D63E7E592FC23A8');
|
|
|
|
$this->addSql('CREATE TEMPORARY TABLE __temp__' . $this->getTable('user', true) . ' AS SELECT id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, name, created_at, updated_at, authCode, twoFactorAuthentication FROM ' . $this->getTable('user', true) . '');
|
|
|
|
$this->addSql('DROP TABLE ' . $this->getTable('user', true) . '');
|
|
|
|
$this->addSql('CREATE TABLE ' . $this->getTable('user', true) . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username VARCHAR(180) NOT NULL COLLATE BINARY, username_canonical VARCHAR(180) NOT NULL COLLATE BINARY, email VARCHAR(180) NOT NULL COLLATE BINARY, email_canonical VARCHAR(180) NOT NULL COLLATE BINARY, enabled BOOLEAN NOT NULL, password VARCHAR(255) NOT NULL COLLATE BINARY, last_login DATETIME DEFAULT NULL, password_requested_at DATETIME DEFAULT NULL, name CLOB DEFAULT NULL COLLATE BINARY, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, authCode INTEGER DEFAULT NULL, emailTwoFactor BOOLEAN NOT NULL, salt VARCHAR(255) DEFAULT NULL, confirmation_token VARCHAR(180) DEFAULT NULL, roles CLOB NOT NULL --(DC2Type:array)
|
2022-12-21 09:57:38 +00:00
|
|
|
, googleAuthenticatorSecret VARCHAR(255) DEFAULT NULL, backupCodes CLOB DEFAULT NULL --(DC2Type:json_array)
|
2018-12-05 10:39:51 +00:00
|
|
|
)');
|
|
|
|
$this->addSql('INSERT INTO ' . $this->getTable('user', true) . ' (id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, name, created_at, updated_at, authCode, emailTwoFactor) SELECT id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, name, created_at, updated_at, authCode, twoFactorAuthentication FROM __temp__' . $this->getTable('user', true) . '');
|
|
|
|
$this->addSql('DROP TABLE __temp__' . $this->getTable('user', true) . '');
|
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_1D63E7E5C05FB297 ON ' . $this->getTable('user', true) . ' (confirmation_token)');
|
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_1D63E7E5A0D96FBF ON ' . $this->getTable('user', true) . ' (email_canonical)');
|
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_1D63E7E592FC23A8 ON ' . $this->getTable('user', true) . ' (username_canonical)');
|
2018-12-03 05:51:06 +00:00
|
|
|
break;
|
2023-08-05 17:35:09 +00:00
|
|
|
case $platform instanceof MySQLPlatform:
|
2018-12-05 10:39:51 +00:00
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' ADD googleAuthenticatorSecret VARCHAR(191) DEFAULT NULL');
|
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' CHANGE twoFactorAuthentication emailTwoFactor BOOLEAN NOT NULL');
|
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' DROP trusted');
|
2022-12-21 09:57:38 +00:00
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' ADD backupCodes LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json_array)\'');
|
2018-12-03 05:51:06 +00:00
|
|
|
break;
|
2023-08-05 17:35:09 +00:00
|
|
|
case $platform instanceof PostgreSQLPlatform:
|
2018-12-05 10:39:51 +00:00
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' ADD googleAuthenticatorSecret VARCHAR(191) DEFAULT NULL');
|
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' RENAME COLUMN twofactorauthentication TO emailTwoFactor');
|
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' DROP trusted');
|
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' ADD backupCodes TEXT DEFAULT NULL');
|
2018-12-03 05:51:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-12-02 11:43:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
2023-08-05 17:35:09 +00:00
|
|
|
$platform = $this->connection->getDatabasePlatform();
|
|
|
|
|
|
|
|
switch (true) {
|
|
|
|
case $platform instanceof SqlitePlatform:
|
2018-12-05 10:39:51 +00:00
|
|
|
$this->addSql('DROP INDEX UNIQ_1D63E7E592FC23A8');
|
|
|
|
$this->addSql('DROP INDEX UNIQ_1D63E7E5A0D96FBF');
|
|
|
|
$this->addSql('DROP INDEX UNIQ_1D63E7E5C05FB297');
|
|
|
|
$this->addSql('CREATE TEMPORARY TABLE __temp__' . $this->getTable('user', true) . ' AS SELECT id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, name, created_at, updated_at, authCode, emailTwoFactor FROM "' . $this->getTable('user', true) . '"');
|
|
|
|
$this->addSql('DROP TABLE "' . $this->getTable('user', true) . '"');
|
|
|
|
$this->addSql('CREATE TABLE "' . $this->getTable('user', true) . '" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username VARCHAR(180) NOT NULL, username_canonical VARCHAR(180) NOT NULL, email VARCHAR(180) NOT NULL, email_canonical VARCHAR(180) NOT NULL, enabled BOOLEAN NOT NULL, password VARCHAR(255) NOT NULL, last_login DATETIME DEFAULT NULL, password_requested_at DATETIME DEFAULT NULL, name CLOB DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, authCode INTEGER DEFAULT NULL, twoFactorAuthentication BOOLEAN NOT NULL, salt VARCHAR(255) NOT NULL COLLATE BINARY, confirmation_token VARCHAR(255) DEFAULT NULL COLLATE BINARY, roles CLOB NOT NULL COLLATE BINARY, trusted CLOB DEFAULT NULL COLLATE BINARY)');
|
|
|
|
$this->addSql('INSERT INTO "' . $this->getTable('user', true) . '" (id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, name, created_at, updated_at, authCode, twoFactorAuthentication) SELECT id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, name, created_at, updated_at, authCode, emailTwoFactor FROM __temp__' . $this->getTable('user', true) . '');
|
|
|
|
$this->addSql('DROP TABLE __temp__' . $this->getTable('user', true) . '');
|
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_1D63E7E592FC23A8 ON "' . $this->getTable('user', true) . '" (username_canonical)');
|
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_1D63E7E5A0D96FBF ON "' . $this->getTable('user', true) . '" (email_canonical)');
|
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_1D63E7E5C05FB297 ON "' . $this->getTable('user', true) . '" (confirmation_token)');
|
2018-12-03 05:51:06 +00:00
|
|
|
break;
|
2023-08-05 17:35:09 +00:00
|
|
|
case $platform instanceof MySQLPlatform:
|
2018-12-05 10:39:51 +00:00
|
|
|
$this->addSql('ALTER TABLE `' . $this->getTable('user') . '` DROP googleAuthenticatorSecret');
|
|
|
|
$this->addSql('ALTER TABLE `' . $this->getTable('user') . '` CHANGE emailtwofactor twoFactorAuthentication BOOLEAN NOT NULL');
|
|
|
|
$this->addSql('ALTER TABLE `' . $this->getTable('user') . '` ADD trusted TEXT DEFAULT NULL');
|
|
|
|
$this->addSql('ALTER TABLE `' . $this->getTable('user') . '` DROP backupCodes');
|
2018-12-03 05:51:06 +00:00
|
|
|
break;
|
2023-08-05 17:35:09 +00:00
|
|
|
case $platform instanceof PostgreSQLPlatform:
|
2018-12-05 10:39:51 +00:00
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' DROP googleAuthenticatorSecret');
|
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' RENAME COLUMN emailTwoFactor TO twofactorauthentication');
|
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' ADD trusted TEXT DEFAULT NULL');
|
|
|
|
$this->addSql('ALTER TABLE ' . $this->getTable('user') . ' DROP backupCodes');
|
2018-12-03 05:51:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-12-02 11:43:05 +00:00
|
|
|
}
|
|
|
|
}
|