|
1 | 1 | # Doctrine ORM |
2 | 2 |
|
| 3 | +This step saves the database connection credentials in an Admin configuration file. |
| 4 | +We do not cover the creation steps of the database itself. |
| 5 | + |
3 | 6 | ## Setup database |
4 | 7 |
|
5 | | -Make sure you fill out the database credentials in `config/autoload/local.php` under `$databases['default']`. |
| 8 | +Create a new MySQL database and set its collation to `utf8mb4_general_ci`. |
6 | 9 |
|
7 | | -Create a new MySQL database - set collation to `utf8mb4_general_ci` |
| 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 | +> `my_database`, `my_user`, `my_password` are provided only as an example. |
| 14 | +
|
| 15 | +```php |
| 16 | +$databases = [ |
| 17 | + 'default' => [ |
| 18 | + 'host' => 'localhost', |
| 19 | + 'dbname' => 'my_database', |
| 20 | + 'user' => 'my_user', |
| 21 | + 'password' => 'my_password', |
| 22 | + 'port' => 3306, |
| 23 | + 'driver' => 'pdo_mysql', |
| 24 | + 'charset' => 'utf8mb4', |
| 25 | + 'collate' => 'utf8mb4_general_ci', |
| 26 | + ], |
| 27 | + // you can add more database connections into this array |
| 28 | +]; |
| 29 | +``` |
8 | 30 |
|
9 | 31 | ## Running migrations |
10 | 32 |
|
11 | 33 | Run the database migrations by using the following command: |
12 | 34 |
|
13 | 35 | ```shell |
14 | | -php bin/doctrine-migrations migrate |
| 36 | +php vendor/bin/doctrine-migrations migrate |
15 | 37 | ``` |
16 | 38 |
|
17 | | -This command will prompt you to confirm that you want to run it. |
| 39 | +Note: If you have already run the migrations, you may get this message. |
| 40 | +You should double-check to make sure the new migrations are ok to run. |
18 | 41 |
|
19 | | -> 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]: |
| 42 | +```shell |
| 43 | +WARNING! You have x previously executed migrations in the database that are not registered migrations. |
| 44 | + {migration list} |
| 45 | +Are you sure you wish to continue? (y/n) |
| 46 | +``` |
20 | 47 |
|
21 | | -Hit `Enter` to confirm the operation. |
| 48 | +When using an empty database, you will get this confirmation message instead. |
22 | 49 |
|
23 | | -## Executing fixtures |
| 50 | +```shell |
| 51 | +WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n) |
| 52 | +``` |
24 | 53 |
|
25 | | -**Fixtures are used to seed the database with initial values and should be executed after migrating the database.** |
| 54 | +Again, submit `y` to run all the migrations in chronological order. |
| 55 | +Each migration will be logged in the `migrations` table to prevent running the same migration more than once, which is often not desirable. |
26 | 56 |
|
27 | | -To list all the fixtures, run: |
| 57 | +If everything ran correctly, you will get this confirmation. |
28 | 58 |
|
29 | 59 | ```shell |
30 | | -php bin/doctrine fixtures:list |
| 60 | +[OK] Successfully migrated to version: Admin\Migrations\Version20240627134952 |
31 | 61 | ``` |
32 | 62 |
|
33 | | -This will output all the fixtures in the order of execution. |
| 63 | +> The migration name `Version20240627134952` may differ in future Admin updates. |
34 | 64 |
|
35 | | -To execute all fixtures, run: |
| 65 | +## Fixtures |
| 66 | + |
| 67 | +Run this command to populate the admin tables with the default values: |
36 | 68 |
|
37 | 69 | ```shell |
38 | 70 | php bin/doctrine fixtures:execute |
39 | 71 | ``` |
40 | 72 |
|
41 | | -To execute a specific fixture, run: |
| 73 | +You should see our galloping horse in the command line. |
42 | 74 |
|
43 | 75 | ```shell |
44 | | -php bin/doctrine fixtures:execute --class=FixtureClassName |
| 76 | +Executing Admin\Fixtures\AdminRoleLoader |
| 77 | +Executing Admin\Fixtures\AdminLoader |
| 78 | +Fixtures have been loaded. |
| 79 | + .'' |
| 80 | + ._.-.___.' (`\ |
| 81 | + //( ( `' |
| 82 | + '/ )\ ).__. ) |
| 83 | + ' <' `\ ._/'\ |
| 84 | + ` \ \ |
45 | 85 | ``` |
46 | | - |
47 | | -More details on how fixtures work can be found here: https://github.com/dotkernel/dot-data-fixtures#creating-fixtures |
|
0 commit comments