Skip to content

Commit 64deaf7

Browse files
authored
Merge pull request #140 from dotkernel/issue-137-139
Issue #137-#139: Documented Doctrine table prefix feature and updated v6 evolution pattern page on MethodDeprecations
2 parents c7fd26b + 0c69a87 commit 64deaf7

File tree

3 files changed

+71
-58
lines changed

3 files changed

+71
-58
lines changed

docs/book/v6/installation/doctrine-orm.md

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ Below is the item you need to focus on:
1313
```php
1414
$databases = [
1515
'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',
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+
'table_prefix' => '',
2425
],
2526
// you can add more database connections into this array
2627
];
@@ -97,3 +98,58 @@ php ./bin/doctrine fixtures:execute --class=FixtureClassName
9798
```
9899

99100
More details on how fixtures work can be found on [dot-data-fixtures documentation](https://github.com/dotkernel/dot-data-fixtures#creating-fixtures)
101+
102+
### Prefixing table names
103+
104+
Note in the database configuration array the key called `table_prefix`.
105+
By default, it is an empty string, which means that all the tables will be named exactly the way they are configured in the entities.
106+
107+
```text
108+
├─ admin
109+
├─ admin_login
110+
├─ admin_role
111+
├─ admin_roles
112+
├─ doctrine_migration_versions
113+
├─ oauth_access_tokens
114+
├─ oauth_access_token_scopes
115+
├─ oauth_auth_codes
116+
├─ oauth_auth_code_scopes
117+
├─ oauth_clients
118+
├─ oauth_refresh_tokens
119+
├─ oauth_scopes
120+
├─ settings
121+
├─ user
122+
├─ user_avatar
123+
├─ user_detail
124+
├─ user_reset_password
125+
├─ user_role
126+
└─ user_roles
127+
```
128+
129+
Adding a prefix, for example `dot_`, all the table will be composed of the prefix and the original table name.
130+
131+
```text
132+
├─ dot_admin
133+
├─ dot_admin_login
134+
├─ dot_admin_role
135+
├─ dot_admin_roles
136+
├─ doctrine_migration_versions
137+
├─ dot_oauth_access_tokens
138+
├─ dot_oauth_access_token_scopes
139+
├─ dot_oauth_auth_codes
140+
├─ dot_oauth_auth_code_scopes
141+
├─ dot_oauth_clients
142+
├─ dot_oauth_refresh_tokens
143+
├─ dot_oauth_scopes
144+
├─ dot_settings
145+
├─ dot_user
146+
├─ dot_user_avatar
147+
├─ dot_user_detail
148+
├─ dot_user_reset_password
149+
├─ dot_user_role
150+
└─ dot_user_roles
151+
```
152+
153+
> The configured prefix is prepended as is, no intermediary character will be added.
154+
155+
> `doctrine_migration_versions` is an exception, being a special table handled by Doctrine Migrations.

docs/book/v6/transition-from-api-tools/api-tools-vs-dotkernel-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
| Authentication | HTTP Basic/Digest OAuth2.0 | OAuth2.0 |
1818
| CI/CD | Yes | Yes |
1919
| Unit Tests | Yes | Yes |
20-
| Endpoint Generator | Yes | Under development |
20+
| Code Generator | Yes | [dotkernel/dot-maker](https://www.dotkernel.com/headless-platform/dotmaker-generate-common-code-in-dotkernel/) |
2121
| PSR | PSR-7 | PSR-7, PSR-15 |

docs/book/v6/tutorials/api-evolution.md

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ API evolution: Updating an API while keeping it compatible for existing consumer
55
## How it works
66

77
In Dotkernel API we can mark an entire endpoint or a single method as deprecated using attributes on handlers.
8-
We use response headers to inform the consumers about the future changes by using 2 new headers:
8+
We use response headers to inform the consumers about the future changes by using two new headers:
99

1010
- `Link` - it's a link to the official documentation pointing out the changes that will take place.
1111
- `Sunset` - this header is a date, indicating when the deprecated resource will potentially become unresponsive.
@@ -17,7 +17,7 @@ We use response headers to inform the consumers about the future changes by usin
1717
1818
## Marking an entire endpoint as deprecated
1919

20-
When you want to mark an entire resource as deprecated you have to use the `ResourceDeprecation` attribute.
20+
When you want to mark an entire resource as deprecated, you have to use the `ResourceDeprecation` attribute.
2121

2222
```php
2323
...
@@ -56,60 +56,17 @@ Vary: Origin
5656

5757
## Marking a method as deprecated
5858

59-
Most of the time you want to deprecate only an endpoint, so you will need to use the `MethodDeprecation` attribute which has the same parameters, but it attaches to a handler method.
60-
61-
```php
62-
...
63-
class HomeHandler implements RequestHandlerInterface
64-
{
65-
...
66-
use Api\App\Attribute\MethodDeprecation;
67-
68-
#[MethodDeprecation(
69-
sunset: '2038-01-01',
70-
link: 'https://docs.dotkernel.org/api-documentation/v6/tutorials/api-evolution/',
71-
deprecationReason: 'Method deprecation example.',
72-
rel: 'sunset',
73-
type: 'text/html'
74-
)]
75-
public function get(): ResponseInterface
76-
{
77-
...
78-
}
79-
}
80-
```
81-
82-
Attaching the `MethodDeprecation` can only be done to HTTP verb methods (`GET`, `POST`, `PUT`, `PATCH` and `DELETE`).
83-
84-
If you followed along you can run the below curl:
85-
86-
```shell
87-
curl --head -X GET http://0.0.0.0:8080 -H "Content-Type: application/json"
88-
```
89-
90-
The response lists the **Sunset** and **Link** headers.
91-
92-
```shell
93-
HTTP/1.1 200 OK
94-
Host: 0.0.0.0:8080
95-
Date: Mon, 24 Jun 2024 10:54:57 GMT
96-
Connection: close
97-
X-Powered-By: PHP/6.4.20
98-
Content-Type: application/json
99-
Permissions-Policy: interest-cohort=()
100-
Sunset: 2038-01-01
101-
Link: https://docs.dotkernel.org/api-documentation/v6/tutorials/api-evolution/;rel="sunset";type="text/html"
102-
Vary: Origin
103-
```
59+
Since version 6, in Dotkernel API each handler is PSR-15 middleware responsible for handling a single request method.
60+
This means that each resource operation will have its own handler class.
61+
Therefore, `MethodDeprecation` no longer has a class method to attach to.
62+
Instead, you should use the `ResourceDeprecation` attribute on the handler class.
10463

10564
## NOTES
10665

10766
> If `Link` or `Sunset` do not have a value they will not appear in the response headers.
10867
10968
> `Sunset` has to be a **valid** date, otherwise it will throw an error.
11069
111-
> You **cannot** use both `ResourceDeprecation` and `MethodDeprecation` in the same handler.
112-
11370
> Deprecations can only be attached to handler classes that implement `RequestHandlerInterface`.
11471
11572
> The `rel` and `type` arguments are optional, they default to `sunset` and `text/html` if no value was provided and are `Link` related parts.

0 commit comments

Comments
 (0)