Skip to content

Commit

Permalink
Readme: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Dec 11, 2024
1 parent 01b7fc7 commit 5d01d0e
Showing 1 changed file with 57 additions and 74 deletions.
131 changes: 57 additions & 74 deletions .docs/README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,58 @@
# Contributte Doctrine Migrations

[Doctrine/Migrations](https://www.doctrine-project.org/projects/migrations.html) for Nette Framework.
Integration of [Doctrine Migrations](https://www.doctrine-project.org/projects/migrations.html) for Nette Framework.

## Content

- [Setup](#setup)
- [Relying](#relying)
- [Installation](#installation)
- [Configuration](#configuration)
- [Minimal configuration](#minimal-configuration)
- [Advanced configuration](#advanced-configuration)
- [Usage](#usage)
- [3rd party](#3rd-party)
- [DBAL & ORM](#dbal--orm)
- [Examples](#examples)

## Setup
## Installation

Install package
Install package using composer.

```bash
composer require nettrine/migrations
```

Configure extension
Register prepared [compiler extension](https://doc.nette.org/en/dependency-injection/nette-container) in your `config.neon` file.

```yaml
```neon
extensions:
nettrine.migrations: Nettrine\Migrations\DI\MigrationsExtension
```

> [!NOTE]
> This is just **Migrations**, for **ORM** use [nettrine/orm](https://github.com/contributte/doctrine-orm) or **DBAL** use [nettrine/dbal](https://github.com/contributte/doctrine-dbal).
## Relying
Take advantage of enpowering this package with 2 extra packages:
- `doctrine/orm`
- `symfony/console`


### `doctrine/orm`

This package relies on `doctrine/orm`, use prepared [contributte/doctrine-orm](https://github.com/contributte/doctrine-orm) integration.
Doctrine ORM depends on Doctrine DBAL, use prepared [contributte/doctrine-dbal](https://github.com/contributte/doctrine-dbal) integration

```bash
composer require nettrine/dbal
composer require nettrine/orm
```

Without these packages the migrations can't be processed, because they need a database connection and entities information. Don't forget to configure Doctrine DBAL & ORM properly with [console bridge](https://github.com/contributte/doctrine-orm/tree/master/.docs#console-bridge). Some commands need special treatment.


### `symfony/console`

This package relies on `symfony/console`, use prepared [contributte/console](https://github.com/contributte/console) integration.
## Configuration

```bash
composer require contributte/console
```
### Minimal configuration

```yaml
extensions:
console: Contributte\Console\DI\ConsoleExtension(%consoleMode%)
```neon
nettrine.migrations:
directories:
App\Migrations: %appDir%/migrations
```

### Advanced configuration

## Configuration

**Schema definition**
Here is the list of all available options with their types.

```yaml
nettrine.migrations:
table: <string>
column: <string>
directories: <array>
directories: array<string, string>
versionsOrganization: <null|year|year_and_month>
customTemplate: <null|path>
```
**Under the hood**

Minimal configuration:

```yaml
nettrine.migrations:
directories:
App\Migrations: %appDir%/migrations
```


## Usage
Type `bin/console` in your terminal and there should be a `migrations` command group.
Expand All @@ -99,17 +66,17 @@ Type `bin/console` in your terminal and there should be a `migrations` command g
- `migrations:up-to-date`
- `migrations:version`

![Console Commands](https://raw.githubusercontent.com/nettrine/migrations/master/.docs/assets/console.png)

You are mostly going to need `migrations:diff` and `migrations:migrate`.


### Migration

This is an example of a migration class.
You can create a new migration by running the following command.

You can count on [Nette Dependency Injection](https://doc.nette.org/en/3.0/dependency-injection).
Injecting into properties or via `inject<>` method is also supported.
```bash
bin/console migrations:generate
```

In the migration file, you can use [dependency injection](https://doc.nette.org/en/3.0/dependency-injection). Injecting into properties or via `inject<>` method is also supported.

```php
<?php declare(strict_types = 1);
Expand All @@ -118,15 +85,13 @@ namespace App\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Nette\DI\Attributes\Inject;
final class Version20200000000001 extends AbstractMigration
{
/**
* @var MyCrypto
* @inject
*/
public $crypto;
#[Inject]
public DummyService $dummy;
public function up(Schema $schema): void
{
Expand All @@ -136,21 +101,39 @@ final class Version20200000000001 extends AbstractMigration
}
```

## DBAL & ORM

> [!TIP]
> Doctrine Migrations needs a database connection and entities information.
> Take a look at [nettrine/dbal](https://github.com/contributte/doctrine-dbal) and [nettrine/orm](https://github.com/contributte/doctrine-orm).

```bash
composer require nettrine/dbal
composer require nettrine/orm
```

### Console

> [!TIP]
> Doctrine DBAL needs Symfony Console to work. You can use `symfony/console` or [contributte/console](https://github.com/contributte/console).

## 3rd party
```bash
composer require contributte/console
```

**kdyby/doctrine**
```neon
extensions:
console: Contributte\Console\DI\ConsoleExtension(%consoleMode%)
```yaml
decorator:
Symfony\Component\Console\Command\Command:
tags: [kdyby.console.command]
Symfony\Component\Console\Helper\Helper:
tags: [kdyby.console.helper]
nettrine.dbal: Nettrine\DBAL\DI\DbalExtension
```

Since this moment when you type `bin/console`, there'll be registered commands from Doctrine DBAL.

![Console Commands](https://raw.githubusercontent.com/nettrine/dbal/master/.docs/assets/console.png)

## Examples

- https://github.com/contributte/playground (playground)
- https://contributte.org/examples.html (more examples)
> [!TIP]
> Take a look at more examples in [contributte/doctrine](https://github.com/contributte/doctrine/tree/master/.docs).

0 comments on commit 5d01d0e

Please sign in to comment.