|
@@ -667,7 +667,7 @@ class DefinitionService
|
667
|
667
|
|
668
|
668
|
public function updateTable(String $tableName, /* object */ $changes): bool
|
669
|
669
|
{
|
670
|
|
- $table = $this->reflection->getTable($tableName);
|
|
670
|
+ $table = $database->get($tableName);
|
671
|
671
|
$newTable = ReflectedTable::fromJson((object) array_merge((array) $table->jsonSerialize(), (array) $changes));
|
672
|
672
|
if ($table->getName() != $newTable->getName()) {
|
673
|
673
|
if (!$this->db->definition()->renameTable($table->getName(), $newTable->getName())) {
|
|
@@ -679,7 +679,7 @@ class DefinitionService
|
679
|
679
|
|
680
|
680
|
public function updateColumn(String $tableName, String $columnName, /* object */ $changes): bool
|
681
|
681
|
{
|
682
|
|
- $table = $this->reflection->getTable($tableName);
|
|
682
|
+ $table = $database->get($tableName);
|
683
|
683
|
$column = $table->get($columnName);
|
684
|
684
|
|
685
|
685
|
$newColumn = ReflectedColumn::fromJson((object) array_merge((array) $column->jsonSerialize(), (array) $changes));
|
|
@@ -780,7 +780,7 @@ class DefinitionService
|
780
|
780
|
|
781
|
781
|
public function removeColumn(String $tableName, String $columnName)
|
782
|
782
|
{
|
783
|
|
- $table = $this->reflection->getTable($tableName);
|
|
783
|
+ $table = $database->get($tableName);
|
784
|
784
|
$newColumn = $table->get($columnName);
|
785
|
785
|
if ($newColumn->getPk()) {
|
786
|
786
|
$newColumn->setPk(false);
|
|
@@ -901,10 +901,11 @@ class ColumnController
|
901
|
901
|
public function getTable(Request $request): Response
|
902
|
902
|
{
|
903
|
903
|
$tableName = $request->getPathSegment(2);
|
904
|
|
- if (!$this->reflection->hasTable($tableName)) {
|
|
904
|
+ $database = $this->reflection->getDatabase();
|
|
905
|
+ if (!$database->exists($tableName)) {
|
905
|
906
|
return $this->responder->error(ErrorCode::TABLE_NOT_FOUND, $tableName);
|
906
|
907
|
}
|
907
|
|
- $table = $this->reflection->getTable($tableName);
|
|
908
|
+ $table = $database->get($tableName);
|
908
|
909
|
return $this->responder->success($table);
|
909
|
910
|
}
|
910
|
911
|
|
|
@@ -912,10 +913,11 @@ class ColumnController
|
912
|
913
|
{
|
913
|
914
|
$tableName = $request->getPathSegment(2);
|
914
|
915
|
$columnName = $request->getPathSegment(3);
|
915
|
|
- if (!$this->reflection->hasTable($tableName)) {
|
|
916
|
+ $database = $this->reflection->getDatabase();
|
|
917
|
+ if (!$database->exists($tableName)) {
|
916
|
918
|
return $this->responder->error(ErrorCode::TABLE_NOT_FOUND, $tableName);
|
917
|
919
|
}
|
918
|
|
- $table = $this->reflection->getTable($tableName);
|
|
920
|
+ $table = $database->get($tableName);
|
919
|
921
|
if (!$table->exists($columnName)) {
|
920
|
922
|
return $this->responder->error(ErrorCode::COLUMN_NOT_FOUND, $columnName);
|
921
|
923
|
}
|
|
@@ -926,7 +928,8 @@ class ColumnController
|
926
|
928
|
public function updateTable(Request $request): Response
|
927
|
929
|
{
|
928
|
930
|
$tableName = $request->getPathSegment(2);
|
929
|
|
- if (!$this->reflection->hasTable($tableName)) {
|
|
931
|
+ $database = $this->reflection->getDatabase();
|
|
932
|
+ if (!$database->exists($tableName)) {
|
930
|
933
|
return $this->responder->error(ErrorCode::TABLE_NOT_FOUND, $tableName);
|
931
|
934
|
}
|
932
|
935
|
$success = $this->definition->updateTable($tableName, $request->getBody());
|
|
@@ -940,10 +943,11 @@ class ColumnController
|
940
|
943
|
{
|
941
|
944
|
$tableName = $request->getPathSegment(2);
|
942
|
945
|
$columnName = $request->getPathSegment(3);
|
943
|
|
- if (!$this->reflection->hasTable($tableName)) {
|
|
946
|
+ $database = $this->reflection->getDatabase();
|
|
947
|
+ if (!$database->exists($tableName)) {
|
944
|
948
|
return $this->responder->error(ErrorCode::TABLE_NOT_FOUND, $tableName);
|
945
|
949
|
}
|
946
|
|
- $table = $this->reflection->getTable($tableName);
|
|
950
|
+ $table = $database->get($tableName);
|
947
|
951
|
if (!$table->exists($columnName)) {
|
948
|
952
|
return $this->responder->error(ErrorCode::COLUMN_NOT_FOUND, $columnName);
|
949
|
953
|
}
|
|
@@ -970,11 +974,12 @@ class ColumnController
|
970
|
974
|
public function addColumn(Request $request): Response
|
971
|
975
|
{
|
972
|
976
|
$tableName = $request->getPathSegment(2);
|
973
|
|
- if (!$this->reflection->hasTable($tableName)) {
|
|
977
|
+ $database = $this->reflection->getDatabase();
|
|
978
|
+ if (!$database->exists($tableName)) {
|
974
|
979
|
return $this->responder->error(ErrorCode::TABLE_NOT_FOUND, $tableName);
|
975
|
980
|
}
|
976
|
981
|
$columnName = $request->getBody()->name;
|
977
|
|
- $table = $this->reflection->getTable($tableName);
|
|
982
|
+ $table = $database->get($tableName);
|
978
|
983
|
if ($table->exists($columnName)) {
|
979
|
984
|
return $this->responder->error(ErrorCode::COLUMN_ALREADY_EXISTS, $columnName);
|
980
|
985
|
}
|
|
@@ -988,7 +993,8 @@ class ColumnController
|
988
|
993
|
public function removeTable(Request $request): Response
|
989
|
994
|
{
|
990
|
995
|
$tableName = $request->getPathSegment(2);
|
991
|
|
- if (!$this->reflection->hasTable($tableName)) {
|
|
996
|
+ $database = $this->reflection->getDatabase();
|
|
997
|
+ if (!$database->exists($tableName)) {
|
992
|
998
|
return $this->responder->error(ErrorCode::TABLE_NOT_FOUND, $tableName);
|
993
|
999
|
}
|
994
|
1000
|
$success = $this->definition->removeTable($tableName);
|
|
@@ -1002,10 +1008,11 @@ class ColumnController
|
1002
|
1008
|
{
|
1003
|
1009
|
$tableName = $request->getPathSegment(2);
|
1004
|
1010
|
$columnName = $request->getPathSegment(3);
|
1005
|
|
- if (!$this->reflection->hasTable($tableName)) {
|
|
1011
|
+ $database = $this->reflection->getDatabase();
|
|
1012
|
+ if (!$database->exists($tableName)) {
|
1006
|
1013
|
return $this->responder->error(ErrorCode::TABLE_NOT_FOUND, $tableName);
|
1007
|
1014
|
}
|
1008
|
|
- $table = $this->reflection->getTable($tableName);
|
|
1015
|
+ $table = $database->get($tableName);
|
1009
|
1016
|
if (!$table->exists($columnName)) {
|
1010
|
1017
|
return $this->responder->error(ErrorCode::COLUMN_NOT_FOUND, $columnName);
|
1011
|
1018
|
}
|