You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/book/v6/installation/doctrine-orm.md
+48-8Lines changed: 48 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,36 @@
1
1
# Doctrine ORM
2
2
3
-
## Setup database
3
+
This step saves the database connection credentials in an API configuration file.
4
+
We do not cover the creation steps of the database itself.
4
5
5
-
Use an existing empty one or create a new **MariaDB**/**MySQL**database.
6
+
## Setup database
6
7
7
-
> Recommended collation: `utf8mb4_general_ci`.
8
+
Create a new **MariaDB**/**MySQL** database and set its collation to `utf8mb4_general_ci`.
9
+
10
+
Make sure you fill out the database credentials in `config/autoload/local.php` under `$databases['default']`.
11
+
Below is the item you need to focus on:
12
+
13
+
```php
14
+
$databases = [
15
+
'default' => [
16
+
'host' => 'localhost',
17
+
'dbname' => 'my_database',
18
+
'user' => 'my_user',
19
+
'password' => 'my_password',
20
+
'port' => 3306,
21
+
'driver' => 'pdo_mysql',
22
+
'charset' => 'utf8mb4',
23
+
'collate' => 'utf8mb4_general_ci',
24
+
],
25
+
// you can add more database connections into this array
26
+
];
27
+
```
8
28
9
-
With a database created, fill out the database connection params in `config/autoload/local.php` under `$databases['default']`.
29
+
> `my_database`, `my_user`, `my_password` are provided only as an example.
10
30
11
31
### Creating migrations
12
32
13
-
Create a new migration by running:
33
+
Create a database migration by executing the following command:
14
34
15
35
```shell
16
36
php ./vendor/bin/doctrine-migrations diff
@@ -20,17 +40,37 @@ The new migration file will be placed in `src/Core/src/App/src/Migration/`.
20
40
21
41
### Running migrations
22
42
23
-
Execute a new migration by running:
43
+
Run the database migrations by executing the following command:
24
44
25
45
```shell
26
46
php ./vendor/bin/doctrine-migrations migrate
27
47
```
28
48
29
-
This command will prompt you to confirm that you want to run it:
49
+
> If you have already run the migrations, you may get the below message:
50
+
51
+
```text
52
+
WARNING! You have x previously executed migrations in the database that are not registered migrations.
53
+
{migration list}
54
+
Are you sure you wish to continue? (y/n)
55
+
```
56
+
57
+
> In this case, you should double-check to make sure the new migrations are ok to run.
30
58
31
-
> WARNING! You are about to execute a migration in database "..." that could result in schema changes and data loss. Are you sure you wish to continue? (yes/no) [yes]:
59
+
When using an empty database, you will get this confirmation message:
60
+
61
+
```text
62
+
WARNING! You are about to execute a migration in database "<your_database_name>" that could result in schema changes and data loss. Are you sure you wish to continue? (yes/no)
63
+
```
32
64
33
65
Hit `Enter` to confirm the operation.
66
+
This will run all the migrations in chronological order.
67
+
Each migration will be logged in the `migrations` table to prevent running the same migration more than once, which is often not desirable.
68
+
69
+
If everything ran correctly, you will get this confirmation.
70
+
71
+
```text
72
+
[OK] Successfully migrated to version: Core\App\Migration\VersionYYYYMMDDHHMMSS
0 commit comments