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']); + } }