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

Commit 4b9d69e

Browse files
committed
Complete description
1 parent 6c59a6f commit 4b9d69e

File tree

3 files changed

+26
-56
lines changed

3 files changed

+26
-56
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# POC Symfony 6
2-
Description for the poc (to completed).
1+
# POC Symfony 6 Multiple Databases
2+
A symfony example with usage of multiple databases with sqlite in this example (migrations can be edited for be used with mysql or postgresql). In this source code, you can look at:
33

4-
**Instructions for the construction of this repot** (to be removed in the poc): This package does not propose by default, some libraries because they do not seem useful for the majority of the pocs. However, you can install them manually if needed. Examples:
5-
6-
* HttpClient: `composer require symfony/http-client`
7-
* Mailer: `composer require symfony/mailer`
8-
* Notifier: `composer require symfony/notifier`
9-
* TestUnits: `composer require --dev symfony/test-pack`
4+
* migrations
5+
* src/Command
6+
* src/DataFixtures
7+
* src/Entity
8+
* src/Repository
109

10+
The sqlite databases are stored in var/ folder.
1111

1212
## Prerequisites
1313

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "jgauthi/template_symfony_starterpack",
3-
"description": "Symfony with some entities and base controller for create POC",
2+
"name": "jgauthi/poc_symfony6_multiple_database",
3+
"description": "A symfony example with usage of multiple databases",
44
"type": "project",
55
"license": "GPL-3.0-only",
66
"require": {

migrations/Main/Version20230208152927.php

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,25 @@ public function getDescription(): string
1919

2020
public function up(Schema $schema): void
2121
{
22-
// this up() migration is auto-generated, please modify it to your needs
23-
if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
24-
$this->addSql('CREATE TABLE category (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(100) NOT NULL, image VARCHAR(255) DEFAULT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
25-
$this->addSql('CREATE TABLE category_dossier (category_id INT NOT NULL, dossier_id INT NOT NULL, INDEX IDX_FA90A04912469DE2 (category_id), INDEX IDX_FA90A049611C0C56 (dossier_id), PRIMARY KEY(category_id, dossier_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
26-
$this->addSql('CREATE TABLE client (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, address VARCHAR(100) DEFAULT NULL, city VARCHAR(50) DEFAULT NULL, country VARCHAR(50) DEFAULT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
27-
$this->addSql('CREATE TABLE dossier (id INT AUTO_INCREMENT NOT NULL, client_id INT NOT NULL, author_id INT NOT NULL, title VARCHAR(255) NOT NULL, status INT DEFAULT 0 NOT NULL, content LONGTEXT NOT NULL, created_date DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_3D48E03719EB6921 (client_id), INDEX IDX_3D48E037F675F31B (author_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
28-
$this->addSql('CREATE TABLE `user` (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, roles VARCHAR(255) DEFAULT \'ROLE_COMMENTATOR\' NOT NULL COMMENT \'(DC2Type:simple_array)\', enabled TINYINT(1) DEFAULT 1 NOT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
29-
$this->addSql('ALTER TABLE category_dossier ADD CONSTRAINT FK_FA90A04912469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE');
30-
$this->addSql('ALTER TABLE category_dossier ADD CONSTRAINT FK_FA90A049611C0C56 FOREIGN KEY (dossier_id) REFERENCES dossier (id) ON DELETE CASCADE');
31-
$this->addSql('ALTER TABLE dossier ADD CONSTRAINT FK_3D48E03719EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE');
32-
$this->addSql('ALTER TABLE dossier ADD CONSTRAINT FK_3D48E037F675F31B FOREIGN KEY (author_id) REFERENCES user (id) ON DELETE CASCADE');
33-
} elseif ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
34-
$this->addSql('CREATE TABLE category (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title VARCHAR(100) NOT NULL, image VARCHAR(255) DEFAULT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL)');
35-
$this->addSql('CREATE TABLE category_dossier (category_id INTEGER NOT NULL, dossier_id INTEGER NOT NULL, PRIMARY KEY(category_id, dossier_id), CONSTRAINT FK_FA90A04912469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_FA90A049611C0C56 FOREIGN KEY (dossier_id) REFERENCES dossier (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
36-
$this->addSql('CREATE INDEX IDX_FA90A04912469DE2 ON category_dossier (category_id)');
37-
$this->addSql('CREATE INDEX IDX_FA90A049611C0C56 ON category_dossier (dossier_id)');
38-
$this->addSql('CREATE TABLE client (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, address VARCHAR(100) DEFAULT NULL, city VARCHAR(50) DEFAULT NULL, country VARCHAR(50) DEFAULT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL)');
39-
$this->addSql('CREATE TABLE dossier (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, client_id INTEGER NOT NULL, author_id INTEGER NOT NULL, title VARCHAR(255) NOT NULL, created_date DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL --(DC2Type:datetime_immutable)
40-
, status INTEGER DEFAULT 0 NOT NULL, content CLOB NOT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CONSTRAINT FK_3D48E03719EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_3D48E037F675F31B FOREIGN KEY (author_id) REFERENCES user (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
41-
$this->addSql('CREATE INDEX IDX_3D48E03719EB6921 ON dossier (client_id)');
42-
$this->addSql('CREATE INDEX IDX_3D48E037F675F31B ON dossier (author_id)');
43-
$this->addSql('CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, roles CLOB DEFAULT \'ROLE_COMMENTATOR\' NOT NULL --(DC2Type:simple_array)
44-
, enabled BOOLEAN DEFAULT 1 NOT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL)');
45-
} else {
46-
$this->abortIf(true, 'Migration can only be executed safely on \'mysql\' or \'sqlite\'.');
47-
}
22+
$this->addSql('CREATE TABLE category (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title VARCHAR(100) NOT NULL, image VARCHAR(255) DEFAULT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL)');
23+
$this->addSql('CREATE TABLE category_dossier (category_id INTEGER NOT NULL, dossier_id INTEGER NOT NULL, PRIMARY KEY(category_id, dossier_id), CONSTRAINT FK_FA90A04912469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_FA90A049611C0C56 FOREIGN KEY (dossier_id) REFERENCES dossier (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
24+
$this->addSql('CREATE INDEX IDX_FA90A04912469DE2 ON category_dossier (category_id)');
25+
$this->addSql('CREATE INDEX IDX_FA90A049611C0C56 ON category_dossier (dossier_id)');
26+
$this->addSql('CREATE TABLE client (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, address VARCHAR(100) DEFAULT NULL, city VARCHAR(50) DEFAULT NULL, country VARCHAR(50) DEFAULT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL)');
27+
$this->addSql('CREATE TABLE dossier (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, client_id INTEGER NOT NULL, author_id INTEGER NOT NULL, title VARCHAR(255) NOT NULL, created_date DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL --(DC2Type:datetime_immutable)
28+
, status INTEGER DEFAULT 0 NOT NULL, content CLOB NOT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CONSTRAINT FK_3D48E03719EB6921 FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_3D48E037F675F31B FOREIGN KEY (author_id) REFERENCES user (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
29+
$this->addSql('CREATE INDEX IDX_3D48E03719EB6921 ON dossier (client_id)');
30+
$this->addSql('CREATE INDEX IDX_3D48E037F675F31B ON dossier (author_id)');
31+
$this->addSql('CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, roles CLOB DEFAULT \'ROLE_COMMENTATOR\' NOT NULL --(DC2Type:simple_array)
32+
, enabled BOOLEAN DEFAULT 1 NOT NULL, last_update DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL)');
4833
}
4934

5035
public function down(Schema $schema): void
5136
{
52-
// this down() migration is auto-generated, please modify it to your needs
53-
if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
54-
$this->addSql('ALTER TABLE category_dossier DROP FOREIGN KEY FK_FA90A04912469DE2');
55-
$this->addSql('ALTER TABLE category_dossier DROP FOREIGN KEY FK_FA90A049611C0C56');
56-
$this->addSql('ALTER TABLE dossier DROP FOREIGN KEY FK_3D48E03719EB6921');
57-
$this->addSql('ALTER TABLE dossier DROP FOREIGN KEY FK_3D48E037F675F31B');
58-
$this->addSql('DROP TABLE category');
59-
$this->addSql('DROP TABLE category_dossier');
60-
$this->addSql('DROP TABLE client');
61-
$this->addSql('DROP TABLE dossier');
62-
$this->addSql('DROP TABLE `user`');
63-
} elseif ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
64-
$this->addSql('DROP TABLE category');
65-
$this->addSql('DROP TABLE category_dossier');
66-
$this->addSql('DROP TABLE client');
67-
$this->addSql('DROP TABLE dossier');
68-
$this->addSql('DROP TABLE `user`');
69-
} else {
70-
$this->abortIf(true, 'Migration can only be executed safely on \'mysql\' or \'sqlite\'.');
71-
}
37+
$this->addSql('DROP TABLE category');
38+
$this->addSql('DROP TABLE category_dossier');
39+
$this->addSql('DROP TABLE client');
40+
$this->addSql('DROP TABLE dossier');
41+
$this->addSql('DROP TABLE `user`');
7242
}
7343
}

0 commit comments

Comments
 (0)