Skip to content
This repository was archived by the owner on Dec 29, 2023. It is now read-only.

Commit e7115db

Browse files
committed
Install + configure DoctrineMigrationsMultipleDatabaseBundle
1 parent 16bf473 commit e7115db

File tree

12 files changed

+226
-16
lines changed

12 files changed

+226
-16
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ APP_SECRET=90b8b29bdd1babbcaafde6a1e2b7b15b
2727
# DATABASE_URL="mysql://db_user:db_password@localhost:3306/db_name?serverVersion=8.0"
2828
# DATABASE_URL="postgresql://symfony:ChangeMe@localhost:5432/app?serverVersion=14&charset=utf8"
2929
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
30+
DATABASE_URL_SECOND="sqlite:///%kernel.project_dir%/var/data2.db"
3031
###< doctrine/doctrine-bundle ###

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ composer install
3030
# (optional) Copy and edit configuration values ".env.local"
3131

3232
php bin/console doctrine:database:create
33+
php bin/console doctrine:database:create --connection=second
3334
php bin/console doctrine:migrations:migrate -n
3435

36+
3537
# Optional
3638
php bin/console doctrine:fixtures:load -n
3739
```
@@ -51,4 +53,8 @@ APP_ENV=test php -d variables_order=EGPCS -S 127.0.0.1:8000 -t public/
5153

5254
Alternatively, you can [configure a web server](https://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html) like Nginx or Apache to run the application.
5355

54-
Your commit is checked by several dev tools (like phpstan, php cs fixer...). These tools were managed by [Grumphp](https://github.com/phpro/grumphp), you can edit configuration on file [grumphp.yml](./grumphp.yml) or check manually with the command: `./vendor/bin/grumphp run`.
56+
Your commit is checked by several dev tools (like phpstan, php cs fixer...). These tools were managed by [Grumphp](https://github.com/phpro/grumphp), you can edit configuration on file [grumphp.yml](./grumphp.yml) or check manually with the command: `./vendor/bin/grumphp run`.
57+
58+
59+
## Development notes
60+
For make new migration, don't use the command `php bin/console make:migration` (no compatible with DoctrineMigrationsMultipleDatabaseBundle), instead use: `php bin/console doctrine:migrations:diff`.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"ext-ctype": "*",
99
"ext-iconv": "*",
1010
"ext-simplexml": "*",
11+
"avaibooksports/doctrine-migrations-multiple-database-bundle": "^0.4.1",
1112
"doctrine/annotations": "*",
1213
"doctrine/doctrine-bundle": "*",
1314
"doctrine/doctrine-migrations-bundle": "*",

composer.lock

Lines changed: 63 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/bundles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
Vich\UploaderBundle\VichUploaderBundle::class => ['all' => true],
1515
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
1616
Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => ['all' => true],
17+
AvaiBookSports\Bundle\MigrationsMutlipleDatabase\DoctrineMigrationsMultipleDatabaseBundle::class => ['all' => true],
1718
];

config/packages/doctrine.yaml

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,47 @@ parameters:
44
# environment variables are not available yet.
55
# You should not need to change this value.
66
env(DATABASE_URL): ''
7+
env(DATABASE_URL_SECOND): ''
78

89
doctrine:
910
dbal:
10-
url: '%env(resolve:DATABASE_URL)%'
11+
default_connection: default
12+
connections:
13+
default:
14+
url: '%env(resolve:DATABASE_URL)%'
15+
default_table_options:
16+
charset: utf8
17+
collate: utf8_unicode_ci
18+
second:
19+
url: '%env(resolve:DATABASE_URL_SECOND)%'
20+
default_table_options:
21+
charset: utf8
22+
collate: utf8_unicode_ci
1123

12-
# IMPORTANT: You MUST configure your server version,
13-
# either here or in the DATABASE_URL env var (see .env file)
14-
#server_version: '13'
1524
orm:
16-
auto_generate_proxy_classes: true
17-
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
18-
auto_mapping: true
19-
mappings:
20-
App:
21-
is_bundle: false
22-
dir: '%kernel.project_dir%/src/Entity'
23-
prefix: 'App\Entity'
24-
alias: App
25+
auto_generate_proxy_classes: false # true on BB-Api
26+
default_entity_manager: default
27+
entity_managers:
28+
default:
29+
connection: default
30+
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
31+
mappings:
32+
App:
33+
is_bundle: false
34+
type: attribute
35+
dir: '%kernel.project_dir%/src/Entity/'
36+
prefix: 'App\Entity'
37+
alias: App
38+
second:
39+
connection: second
40+
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
41+
mappings:
42+
Second:
43+
is_bundle: false
44+
type: attribute
45+
dir: '%kernel.project_dir%/src/Entity2/'
46+
prefix: 'App\Entity2'
47+
alias: Second
2548

2649
when@prod:
2750
doctrine:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
doctrine_migrations_multiple_database:
2+
entity_managers:
3+
default:
4+
migrations_paths:
5+
DoctrineMigrations\Main: '%kernel.project_dir%/migrations/Main'
6+
second:
7+
migrations_paths:
8+
DoctrineMigrations\Second: '%kernel.project_dir%/migrations/Second'

config/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ services:
2121
exclude:
2222
- '../src/DependencyInjection/'
2323
- '../src/Entity/'
24+
- '../src/Entity2/'
2425
- '../src/Kernel.php'
2526

2627
# add more service definitions when explicit configuration is needed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace DoctrineMigrations;
4+
namespace DoctrineMigrations\Main;
55

66
use Doctrine\DBAL\Platforms\{MySqlPlatform, SqlitePlatform};
77
use Doctrine\DBAL\Schema\Schema;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace DoctrineMigrations\Second;
5+
6+
use Doctrine\DBAL\Schema\Schema;
7+
use Doctrine\Migrations\AbstractMigration;
8+
9+
/**
10+
* Auto-generated Migration: Please modify to your needs!
11+
*/
12+
final class Version20230711133824 extends AbstractMigration
13+
{
14+
public function getDescription(): string
15+
{
16+
return '';
17+
}
18+
19+
public function up(Schema $schema): void
20+
{
21+
// this up() migration is auto-generated, please modify it to your needs
22+
$this->addSql('CREATE TABLE todolist (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title VARCHAR(100) NOT NULL, description CLOB NOT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL)');
23+
}
24+
25+
public function down(Schema $schema): void
26+
{
27+
// this down() migration is auto-generated, please modify it to your needs
28+
$this->addSql('DROP TABLE todolist');
29+
}
30+
}

0 commit comments

Comments
 (0)