Skip to content

Commit

Permalink
Fix up migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
te-online committed Dec 2, 2023
1 parent 4e84284 commit 9125899
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version3009Date20231202210000 extends SimpleMigrationStep
{
class Version3009Date20230918152200 extends SimpleMigrationStep {
/** @var IDBConnection */
private $db;

public function __construct(IDBConnection $db)
{
public function __construct(IDBConnection $db) {
$this->db = $db;
}

Expand All @@ -29,8 +27,7 @@ public function __construct(IDBConnection $db)
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void
{
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
Expand All @@ -39,30 +36,21 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper
{
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable("timemanager_share");

$table->addColumn("recipient_id", "string", [
"notnull" => true,
"notnull" => false,
"length" => 64,
]);
$table->addColumn("recipient_type", "string", [
"notnull" => true,
"notnull" => false,
"length" => 64,
]);

$table->dropIndex("timemanager_share_with_index");
$table->addIndex(["recipient_id", "recipient_type"], "timemanager_share_with_index");
$table->dropIndex("timemanager_share_unique_index");
$table->addUniqueIndex(
["object_uuid", "entity_type", "author_user_id", "recipient_id", "recipient_type"],
"timemanager_share_unique_index"
);

return $schema;
}

Expand All @@ -71,8 +59,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void
{
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$query = $this->db->getQueryBuilder();
$query->update("timemanager_share")
->set("recipient_id", "recipient_user_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,19 @@

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version3009Date20231202211500 extends SimpleMigrationStep
{
/** @var IDBConnection */
private $db;

public function __construct(IDBConnection $db)
{
$this->db = $db;
}

class Version3009Date20230918152300 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void
{
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
Expand All @@ -39,13 +28,27 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper
{
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable("timemanager_share");

$table->changeColumn("recipient_id", [
"notnull" => true
]);
$table->changeColumn("recipient_type", [
"notnull" => true
]);

$table->dropIndex("timemanager_share_with_index");
$table->addIndex(["recipient_id", "recipient_type"], "timemanager_share_with_index");
$table->dropIndex("timemanager_share_unique_index");
$table->addUniqueIndex(
["object_uuid", "entity_type", "author_user_id", "recipient_id", "recipient_type"],
"timemanager_share_unique_index"
);

$table->dropColumn("recipient_user_id");

return $schema;
Expand All @@ -56,7 +59,6 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void
{
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}

0 comments on commit 9125899

Please sign in to comment.