Skip to content

Commit e7f9d77

Browse files
committed
Add (My)SQL schema for necessary rdbms tables
Including migrations for popular libraries: doctrine and phinx
1 parent 59520f6 commit e7f9d77

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
use Doctrine\Migrations\AbstractMigration;
7+
8+
final class Version20241009183226 extends AbstractMigration
9+
{
10+
public function up(Schema $schema): void
11+
{
12+
$this->addSql(
13+
<<<'SQL'
14+
CREATE TABLE `event_store` (
15+
`id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
16+
`event_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
17+
`payload` json NOT NULL,
18+
`metadata` json NOT NULL,
19+
`applied_at` timestamp(6) NOT NULL,
20+
PRIMARY KEY (`id`),
21+
KEY `event_name` (`event_name`)
22+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
23+
SQL
24+
);
25+
26+
$this->addSql(
27+
<<<'SQL'
28+
CREATE TABLE `event_store_relation` (
29+
`event_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
30+
`domain_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
31+
PRIMARY KEY (`event_id`,`domain_id`),
32+
CONSTRAINT `event_store_relation_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `event_store` (`id`)
33+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
34+
SQL
35+
);
36+
}
37+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Phinx\Migration\AbstractMigration;
6+
7+
final class V20241210193448 extends AbstractMigration
8+
{
9+
public function change(): void
10+
{
11+
$this->table('event_store', ['id' => false, 'primary_key' => 'id'])
12+
->addColumn('id', 'string', ['limit' => 50, 'null' => false])
13+
->addColumn('event_name', 'string', ['limit' => 100, 'null' => false])
14+
->addColumn('payload', 'json', ['null' => false])
15+
->addColumn('metadata', 'json', ['null' => false])
16+
->addColumn('applied_at', 'timestamp', ['limit' => 6, 'null' => false])
17+
->addIndex('event_name')
18+
->create();
19+
}
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Phinx\Migration\AbstractMigration;
6+
7+
final class V20241210194054 extends AbstractMigration
8+
{
9+
public function change(): void
10+
{
11+
$this->table('event_store_relation', ['id' => false, 'primary_key' => ['event_id', 'domain_id']])
12+
->addColumn('event_id', 'string', ['limit' => 50, 'null' => false])
13+
->addColumn('domain_id', 'string', ['limit' => 50, 'null' => false])
14+
->addForeignKey('event_id', 'event_store', 'id')
15+
->create();
16+
}
17+
}

resources/schema.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CREATE TABLE `event_store` (
2+
`id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
3+
`event_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
4+
`payload` json NOT NULL,
5+
`metadata` json NOT NULL,
6+
`applied_at` timestamp(6) NOT NULL,
7+
PRIMARY KEY (`id`),
8+
KEY `event_name` (`event_name`)
9+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
10+
11+
CREATE TABLE `event_store_relation` (
12+
`event_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
13+
`domain_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
14+
PRIMARY KEY (`event_id`,`domain_id`),
15+
CONSTRAINT `event_store_relation_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `event_store` (`id`)
16+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

0 commit comments

Comments
 (0)