From 57f6333ea3ca62beca8fac2e9d5a878bb60dcd47 Mon Sep 17 00:00:00 2001 From: PovilasKorop Date: Tue, 9 Nov 2021 10:58:48 +0200 Subject: [PATCH] Task 8 - rename table --- README.md | 8 +++++ ...2021_11_09_085417_create_company_table.php | 32 +++++++++++++++++++ ...21_11_09_085453_rename_companies_table.php | 28 ++++++++++++++++ tests/Feature/MigrationsTest.php | 9 ++++++ 4 files changed, 77 insertions(+) create mode 100644 database/migrations/task8/2021_11_09_085417_create_company_table.php create mode 100644 database/migrations/task8/2021_11_09_085453_rename_companies_table.php diff --git a/README.md b/README.md index 0165eb5..e0758ae 100644 --- a/README.md +++ b/README.md @@ -95,3 +95,11 @@ Test method `test_automatic_value()`. --- +## Task 8. Rename table + +Folder `database/migrations/task8` contains a migration for company table. Later it was decided to rename the table from "company" to "companies". Write the code for that, in the second migration file. + +Test method `test_renamed_table()`. + +--- + diff --git a/database/migrations/task8/2021_11_09_085417_create_company_table.php b/database/migrations/task8/2021_11_09_085417_create_company_table.php new file mode 100644 index 0000000..1999962 --- /dev/null +++ b/database/migrations/task8/2021_11_09_085417_create_company_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('companies'); + } +} diff --git a/database/migrations/task8/2021_11_09_085453_rename_companies_table.php b/database/migrations/task8/2021_11_09_085453_rename_companies_table.php new file mode 100644 index 0000000..dc4ae6f --- /dev/null +++ b/database/migrations/task8/2021_11_09_085453_rename_companies_table.php @@ -0,0 +1,28 @@ +assertEquals('My company', $company->name); } + + public function test_renamed_table() + { + Artisan::call('migrate:fresh', ['--path' => '/database/migrations/task8']); + + DB::table('companies')->insert(['name' => 'First']); + $this->assertDatabaseHas(Company::class, ['name' => 'First']); + } }