From 0140f00c32c5377e0916ca3e4c4fa2c8b347bef4 Mon Sep 17 00:00:00 2001 From: PovilasKorop Date: Tue, 9 Nov 2021 11:05:49 +0200 Subject: [PATCH] Rename column --- README.md | 8 +++++ ...21_11_09_090003_create_companies_table.php | 32 ++++++++++++++++++ ..._090018_rename_name_in_companies_table.php | 33 +++++++++++++++++++ tests/Feature/MigrationsTest.php | 8 +++++ 4 files changed, 81 insertions(+) create mode 100644 database/migrations/task9/2021_11_09_090003_create_companies_table.php create mode 100644 database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php diff --git a/README.md b/README.md index e0758ae..72a597f 100644 --- a/README.md +++ b/README.md @@ -103,3 +103,11 @@ Test method `test_renamed_table()`. --- +## Task 9. Rename column + +Folder `database/migrations/task9` contains a migration for companies table. Later it was decided to rename the column from "companies.title" to "companies.name". Write the code for that, in the second migration file. + +Test method `test_renamed_column()`. + +--- + diff --git a/database/migrations/task9/2021_11_09_090003_create_companies_table.php b/database/migrations/task9/2021_11_09_090003_create_companies_table.php new file mode 100644 index 0000000..38f1330 --- /dev/null +++ b/database/migrations/task9/2021_11_09_090003_create_companies_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('title'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('companies'); + } +} diff --git a/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php b/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php new file mode 100644 index 0000000..f270c9e --- /dev/null +++ b/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php @@ -0,0 +1,33 @@ +insert(['name' => 'First']); $this->assertDatabaseHas(Company::class, ['name' => 'First']); } + + public function test_renamed_column() + { + Artisan::call('migrate:fresh', ['--path' => '/database/migrations/task9']); + + Company::create(['name' => 'First']); + $this->assertDatabaseHas(Company::class, ['name' => 'First']); + } }