Skip to content

Commit 124bc33

Browse files
Create the database and tables
1 parent 5c2c952 commit 124bc33

14 files changed

+1144
-149
lines changed

AI Backlog/02 - Create the database and tables.md

Lines changed: 940 additions & 0 deletions
Large diffs are not rendered by default.

AI Backlog/README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
11
This folder contains discussions about the project with ChatGPT. I tried to keep the chronology, but it was not always possible. So in some places, there may be small gaps. But overall, if you read in order, everything should be clear.
22

3-
I use my own [script](https://gist.github.com/GreenWizard2015/7f8ed0b609983b40a97fe7d245345552) to convert chat to Markdown. Also, I often intentionally make errors and try to make the message as short as possible when communicating with AI to increase productivity.
3+
I use my own [script](https://gist.github.com/GreenWizard2015/7f8ed0b609983b40a97fe7d245345552) to convert chat to Markdown. Also, I often intentionally make errors and try to make the message as short as possible when communicating with AI to increase productivity.
4+
5+
## 00 - Software Architect Expert
6+
7+
Conversation: [00 - Software Architect Expert.md](00%20-%20Software%20Architect%20Expert.md)
8+
9+
A very good and comprehensive start. The evaluation of complexity is not entirely accurate but it is very close to reality.
10+
11+
## 01 - Set up the development environment
12+
13+
Conversation: [01 - Set up the development environment.md](01%20-%20Set%20up%20the%20development%20environment.md)
14+
15+
ChatGPT demonstrated good knowledge of Linux/Ubuntu and Laravel. There were some issues, but I managed to solve them solely by following its instructions.
16+
17+
## 02 - Create the database and tables
18+
19+
Conversation: [02 - Create the database and tables.md]
20+
21+
ChatGPT analysis of conversation:
22+
23+
```
24+
The dialogue between the human and AI in this conversation was primarily focused on writing tests for a country model in Laravel 8. The AI provided clear and concise instructions on how to write the tests, including the necessary imports, class structure, and methods to use. The AI also demonstrated a good understanding of the testing process, as well as the framework and its testing tools.
25+
26+
One of the strengths of the AI in this dialogue is its ability to provide detailed and accurate information in response to the human's questions. It also demonstrated the ability to adapt to changes in the human's requests, such as when the human asked for the code to be updated in a new format.
27+
28+
A weakness of the AI in this dialogue is that it sometimes provided more information than was needed or requested. This can make it difficult for the human to find the specific information they are looking for. Additionally, the AI sometimes used overly technical language which may be difficult for some users to understand.
29+
30+
The interaction between the human and AI in this dialogue was primarily focused on the human asking questions and the AI providing answers. The human was able to clearly state their needs and the AI was able to respond with relevant information. The human also provided feedback on the AI's responses, which allowed the AI to adjust its responses to better meet the human's needs.
31+
32+
To optimize this process, it would be beneficial to provide more context or background information in the human's initial question to help the AI better understand the human's needs. Additionally, the AI could be programmed to provide a summary of its response, which would make it easier for the human to quickly find the information they need. The AI can also be programmed to use simpler language, which would make it more accessible to a wider range of users.
33+
34+
The human in this dialogue wrote in a concise and terse manner, using shorthand and abbreviations. This may have slightly hindered the effectiveness of the interaction with the AI as the AI's understanding of the language may have been challenged by the shorthand and abbreviations used. It is possible that the human's communication style may have led to some confusion or misinterpretation on the part of the AI. To optimize this process, it would be beneficial for the human to use clear and complete language, and avoid using shorthand or abbreviations, so that the AI can understand the human's requests and respond appropriately.
35+
```
36+
37+
The AI responded following the Laravel 7 API, but version 8 was needed. The difference in the API led to confusion and loss of time. Additionally, I decided to write the simplest (and unnecessary) tests, which led to problems in the dialogue with the AI. I concluded that it is not worth solving several tasks in one dialogue. It is better to leave the details of the implementation to Copilot AI, as the interaction on the lowest level of implementation is much more efficient. It is also very effective to shorten the message text as AI easily understands it.
38+

backend/app/Models/Country.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@
88
class Country extends Model
99
{
1010
use HasFactory;
11+
12+
// fillable fields
13+
protected $fillable = [
14+
'name',
15+
];
16+
17+
public $timestamps = false;
18+
19+
public function users()
20+
{
21+
return $this->hasMany('App\User');
22+
}
1123
}

backend/app/Models/User.php

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,23 @@
22

33
namespace App\Models;
44

5-
use Illuminate\Contracts\Auth\MustVerifyEmail;
65
use Illuminate\Database\Eloquent\Factories\HasFactory;
7-
use Illuminate\Foundation\Auth\User as Authenticatable;
8-
use Illuminate\Notifications\Notifiable;
9-
use Laravel\Sanctum\HasApiTokens;
6+
use Illuminate\Database\Eloquent\Model;
107

11-
class User extends Authenticatable
8+
class User extends Model
129
{
13-
use HasApiTokens, HasFactory, Notifiable;
10+
use HasFactory;
1411

15-
/**
16-
* The attributes that are mass assignable.
17-
*
18-
* @var array<int, string>
19-
*/
12+
// fillable fields
2013
protected $fillable = [
21-
'name',
22-
'email',
23-
'password',
14+
'first_name',
15+
'last_name',
16+
'date_of_birth',
2417
];
2518

26-
/**
27-
* The attributes that should be hidden for serialization.
28-
*
29-
* @var array<int, string>
30-
*/
31-
protected $hidden = [
32-
'password',
33-
'remember_token',
34-
];
35-
36-
/**
37-
* The attributes that should be cast.
38-
*
39-
* @var array<string, string>
40-
*/
41-
protected $casts = [
42-
'email_verified_at' => 'datetime',
43-
];
19+
public $timestamps = false;
20+
21+
public function country() {
22+
return $this->belongsTo(Country::class);
23+
}
4424
}

backend/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"laravel/ui": "^3.4",
2020
"mockery/mockery": "^1.5",
2121
"nunomaduro/collision": "^5.10",
22-
"phpunit/phpunit": "^9.3"
22+
"phpunit/phpunit": "^9.5"
2323
},
2424
"autoload": {
2525
"psr-4": {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
class CountryFactory extends Factory
8+
{
9+
/**
10+
* Define the model's default state.
11+
*
12+
* @return array
13+
*/
14+
public function definition()
15+
{
16+
return [
17+
'name' => $this->faker->name,
18+
];
19+
}
20+
}

backend/database/factories/UserFactory.php

100755100644
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6-
use Illuminate\Support\Str;
76

87
class UserFactory extends Factory
98
{
@@ -15,25 +14,14 @@ class UserFactory extends Factory
1514
public function definition()
1615
{
1716
return [
18-
'name' => $this->faker->name(),
19-
'email' => $this->faker->unique()->safeEmail(),
20-
'email_verified_at' => now(),
21-
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
22-
'remember_token' => Str::random(10),
17+
'first_name' => $this->faker->firstName,
18+
'last_name' => $this->faker->lastName,
19+
// date of birth is a date between 18 and 65 years ago
20+
'date_of_birth' => $this->faker->dateTimeBetween('-65 years', '-18 years'),
21+
// country_id is referenced to the countries table
22+
'country_id' => function () {
23+
return \App\Models\Country::factory()->create()->id;
24+
},
2325
];
2426
}
25-
26-
/**
27-
* Indicate that the model's email address should be unverified.
28-
*
29-
* @return \Illuminate\Database\Eloquent\Factories\Factory
30-
*/
31-
public function unverified()
32-
{
33-
return $this->state(function (array $attributes) {
34-
return [
35-
'email_verified_at' => null,
36-
];
37-
});
38-
}
3927
}

backend/database/migrations/2014_10_12_100000_create_password_resets_table.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

backend/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

backend/database/migrations/2023_01_14_221601_create_countries_table.php renamed to backend/database/migrations/2023_01_15_155011_create_countries_table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class CreateCountriesTable extends Migration
1414
public function up()
1515
{
1616
Schema::create('countries', function (Blueprint $table) {
17-
$table->id();
18-
$table->timestamps();
17+
$table->increments('id')->unsigned();
18+
$table->string('name');
1919
});
2020
}
2121

@@ -28,4 +28,4 @@ public function down()
2828
{
2929
Schema::dropIfExists('countries');
3030
}
31-
}
31+
}

backend/database/migrations/2014_10_12_000000_create_users_table.php renamed to backend/database/migrations/2023_01_15_155013_create_users_table.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ public function up()
1515
{
1616
Schema::create('users', function (Blueprint $table) {
1717
$table->id();
18-
$table->string('name');
19-
$table->string('email')->unique();
20-
$table->timestamp('email_verified_at')->nullable();
21-
$table->string('password');
22-
$table->rememberToken();
23-
$table->timestamps();
18+
$table->string('first_name');
19+
$table->string('last_name');
20+
$table->date('date_of_birth');
21+
$table->integer('country_id')->unsigned();
22+
$table->foreign('country_id')->references('id')->on('countries');
2423
});
2524
}
2625

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use App\Models\Country;
6+
7+
class CountriesTest extends \Illuminate\Foundation\Testing\TestCase
8+
{
9+
use \Tests\CreatesApplication;
10+
use \Illuminate\Foundation\Testing\RefreshDatabase;
11+
use \Illuminate\Foundation\Testing\WithFaker;
12+
13+
public function testCountryCanBeCreated()
14+
{
15+
$name = $this->faker->word;
16+
$country = Country::factory()->make(['name' => $name]);
17+
$this->assertTrue($country->save());
18+
$this->assertDatabaseHas('countries', ['name' => $name]);
19+
}
20+
21+
public function testCountryCanBeUpdated()
22+
{
23+
$country = Country::factory()->create();
24+
$newName = $this->faker->word;
25+
$country->name = $newName;
26+
$this->assertTrue($country->save());
27+
$this->assertDatabaseHas('countries', ['name' => $newName]);
28+
}
29+
public function testCountryCanBeDeleted()
30+
{
31+
$country = Country::factory()->create();
32+
$this->assertTrue($country->delete());
33+
$this->assertDatabaseMissing('countries', ['id' => $country->id]);
34+
}
35+
}

0 commit comments

Comments
 (0)