From 8296ef0662b56eb47fa357f01a5fee2c23ae1c6c Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Thu, 3 Sep 2020 11:15:16 +0200 Subject: [PATCH] Migrations: Default to unsignedInteger in changeReferences() --- .../2018_10_01_000000_create_users_tables.php | 3 +-- .../2019_10_15_000000_create_news_table.php | 6 ++---- .../2019_11_12_000000_create_news_comments_table.php | 6 ++---- .../2019_11_25_000000_create_messages_table.php | 6 ++---- .../2019_11_29_000000_create_questions_table.php | 6 ++---- db/migrations/ChangesReferences.php | 12 +++++++++--- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/db/migrations/2018_10_01_000000_create_users_tables.php b/db/migrations/2018_10_01_000000_create_users_tables.php index c7937bed..0d6e0a3b 100644 --- a/db/migrations/2018_10_01_000000_create_users_tables.php +++ b/db/migrations/2018_10_01_000000_create_users_tables.php @@ -160,8 +160,7 @@ class CreateUsersTables extends Migration 'User', 'UID', 'users', - 'id', - 'unsignedInteger' + 'id' ); } diff --git a/db/migrations/2019_10_15_000000_create_news_table.php b/db/migrations/2019_10_15_000000_create_news_table.php index e4c48db0..99448c5d 100644 --- a/db/migrations/2019_10_15_000000_create_news_table.php +++ b/db/migrations/2019_10_15_000000_create_news_table.php @@ -38,8 +38,7 @@ class CreateNewsTable extends Migration 'PreviousNews', 'ID', 'news', - 'id', - 'unsignedInteger' + 'id' ); $this->schema->drop('PreviousNews'); } @@ -59,8 +58,7 @@ class CreateNewsTable extends Migration 'new_news', 'id', 'News', - 'ID', - 'unsignedInteger' + 'ID' ); $this->schema->drop('new_news'); diff --git a/db/migrations/2019_11_12_000000_create_news_comments_table.php b/db/migrations/2019_11_12_000000_create_news_comments_table.php index ac080c38..66a3b96a 100644 --- a/db/migrations/2019_11_12_000000_create_news_comments_table.php +++ b/db/migrations/2019_11_12_000000_create_news_comments_table.php @@ -30,8 +30,7 @@ class CreateNewsCommentsTable extends Migration 'NewsComments', 'ID', 'news_comments', - 'id', - 'unsignedInteger' + 'id' ); $this->schema->drop('NewsComments'); } @@ -48,8 +47,7 @@ class CreateNewsCommentsTable extends Migration 'news_comments', 'id', 'NewsComments', - 'ID', - 'unsignedInteger' + 'ID' ); $this->schema->drop('news_comments'); diff --git a/db/migrations/2019_11_25_000000_create_messages_table.php b/db/migrations/2019_11_25_000000_create_messages_table.php index e2c0f253..ce1eee9c 100644 --- a/db/migrations/2019_11_25_000000_create_messages_table.php +++ b/db/migrations/2019_11_25_000000_create_messages_table.php @@ -38,8 +38,7 @@ class CreateMessagesTable extends Migration 'PreviousMessages', 'ID', 'messages', - 'id', - 'unsignedInteger' + 'id' ); $this->schema->drop('PreviousMessages'); } @@ -59,8 +58,7 @@ class CreateMessagesTable extends Migration 'new_messages', 'id', 'Messages', - 'ID', - 'unsignedInteger' + 'ID' ); $this->schema->drop('new_messages'); diff --git a/db/migrations/2019_11_29_000000_create_questions_table.php b/db/migrations/2019_11_29_000000_create_questions_table.php index d0674931..f39965e4 100644 --- a/db/migrations/2019_11_29_000000_create_questions_table.php +++ b/db/migrations/2019_11_29_000000_create_questions_table.php @@ -37,8 +37,7 @@ class CreateQuestionsTable extends Migration 'PreviousQuestions', 'QID', 'questions', - 'id', - 'unsignedInteger' + 'id' ); $this->schema->drop('PreviousQuestions'); } @@ -58,8 +57,7 @@ class CreateQuestionsTable extends Migration 'new_questions', 'id', 'Questions', - 'QID', - 'unsignedInteger' + 'QID' ); $this->schema->drop('new_questions'); diff --git a/db/migrations/ChangesReferences.php b/db/migrations/ChangesReferences.php index b5b39ac3..95420f19 100644 --- a/db/migrations/ChangesReferences.php +++ b/db/migrations/ChangesReferences.php @@ -14,8 +14,13 @@ trait ChangesReferences * @param string $targetColumn * @param string $type */ - protected function changeReferences($fromTable, $fromColumn, $targetTable, $targetColumn, $type) - { + protected function changeReferences( + string $fromTable, + string $fromColumn, + string $targetTable, + string $targetColumn, + string $type = 'unsignedInteger' + ) { $references = $this->getReferencingTables($fromTable, $fromColumn); foreach ($references as $reference) { @@ -41,9 +46,10 @@ trait ChangesReferences /** * @param string $table * @param string $column + * * @return array */ - protected function getReferencingTables($table, $column): array + protected function getReferencingTables(string $table, string $column): array { return $this->schema ->getConnection()