Skip to content

Commit

Permalink
Fix errors preventing queries from altering tables, columns and indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
jdarwood007 committed Aug 6, 2024
1 parent d1f67a0 commit b1773a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Maintenance/Database/Schema/DbIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public function __construct(

if (($this->type ?? null) !== 'primary') {
$this->name = $name ?? 'idx_' . trim(implode('_', preg_replace(['/\s*/', '/\(\d+\)/'], ['', ''], $this->columns)));
} else {
$this->name = $name ?? 'primary';
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions Maintenance/Database/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function create(array $parameters = [], string $if_exists = 'ignore'): bo
}

return Db::$db->create_table(
$this->name,
'{db_prefix}' . $this->name,
array_map('get_object_vars', $this->columns),
array_map('get_object_vars', $this->indexes),
$parameters,
Expand All @@ -116,7 +116,7 @@ public function create(array $parameters = [], string $if_exists = 'ignore'): bo
*/
public function drop(): bool
{
return Db::$db->drop_table($this->name);
return Db::$db->drop_table('{db_prefix}' . $this->name);
}

/**
Expand All @@ -130,7 +130,7 @@ public function drop(): bool
*/
public function getCurrentStructure(): array
{
return Db::$db->table_structure($this->name);
return Db::$db->table_structure('{db_prefix}' . $this->name);
}

/**
Expand All @@ -146,7 +146,7 @@ public function getCurrentStructure(): array
public function addColumn(Column $col, string $if_exists = 'update'): bool
{
return Db::$db->add_column(
$this->name,
'{db_prefix}' . $this->name,
get_object_vars($col),
[],
$if_exists,
Expand All @@ -166,7 +166,7 @@ public function addColumn(Column $col, string $if_exists = 'update'): bool
public function alterColumn(Column $col, ?string $old_name = null): bool
{
return Db::$db->change_column(
$this->name,
'{db_prefix}' . $this->name,
$old_name ?? $col->name,
get_object_vars($col),
);
Expand All @@ -183,7 +183,7 @@ public function alterColumn(Column $col, ?string $old_name = null): bool
public function dropColumn(Column $col): bool
{
return Db::$db->remove_column(
$this->name,
'{db_prefix}' . $this->name,
$col->name,
);
}
Expand All @@ -201,7 +201,7 @@ public function dropColumn(Column $col): bool
public function addIndex(DbIndex $index, string $if_exists = 'update'): bool
{
return Db::$db->add_index(
$this->name,
'{db_prefix}' . $this->name,
get_object_vars($index),
[],
$if_exists,
Expand Down Expand Up @@ -234,7 +234,7 @@ public function alterIndex(DbIndex $index): bool
public function dropIndex(DbIndex $index): bool
{
return Db::$db->remove_index(
$this->name,
'{db_prefix}' . $this->name,
$index->name,
);
}
Expand Down

0 comments on commit b1773a7

Please sign in to comment.