Skip to content

Commit

Permalink
feat(migration): use new migration system introduced in 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mrflos committed Aug 1, 2024
1 parent db649cf commit 1311d5e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions migrations/20240801105857_LoginssoAddSsoFieldToUserTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use YesWiki\Core\YesWikiMigration;

class LoginssoAddSsoFieldToUserTable extends YesWikiMigration
{
public function run()
{
$tableName = $this->dbService->prefixTable('users');

$columExist = $this->dbService->count(sprintf("SHOW COLUMNS FROM %s LIKE 'loginsso_id'", $tableName)) > 0;
if (!$columExist) {
$this->dbService->query(sprintf('ALTER TABLE %s ADD COLUMN loginsso_id VARCHAR(255) DEFAULT NULL', $tableName));
$this->dbService->query(sprintf('CREATE UNIQUE INDEX idx_loginsso_id ON %s(loginsso_id);', $tableName));

// Retro compatibility from previous versions
$this->dbService->query(sprintf('UPDATE %s SET loginsso_id=email', $tableName));
}

return $this->wiki->render('@loginsso/handlers/update/add_column.html.twig', [
'tableName' => $tableName,
'columnExist' => $columExist,
]);
}
}

0 comments on commit 1311d5e

Please sign in to comment.