Skip to content

Commit 047ba3c

Browse files
committed
Add database migration templates for default saga stores
Available as - raw sql - doctrine migration - phinx migration
1 parent 744da49 commit 047ba3c

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
use Doctrine\Migrations\AbstractMigration;
7+
8+
final class Version20251002195234 extends AbstractMigration
9+
{
10+
public function up(Schema $schema): void
11+
{
12+
$this->addSql(
13+
<<<'SQL'
14+
CREATE TABLE `saga_store` (
15+
`saga_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
16+
`saga_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
17+
`payload` json NOT NULL,
18+
`created_at` timestamp(6) NOT NULL,
19+
`updated_at` timestamp(6) NULL DEFAULT NULL,
20+
PRIMARY KEY (`saga_id`, `saga_name`)
21+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
22+
SQL
23+
);
24+
}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Phinx\Migration\AbstractMigration;
6+
7+
final class V20251002194212 extends AbstractMigration
8+
{
9+
public function change(): void
10+
{
11+
$this->table('saga_store', ['id' => false, 'primary_key' => ['saga_id', 'saga_name']])
12+
->addColumn('saga_id', 'string', ['limit' => 50, 'null' => false])
13+
->addColumn('saga_name', 'string', ['null' => false])
14+
->addColumn('payload', 'json', ['null' => false])
15+
->addColumn('created_at', 'timestamp', ['limit' => 6, 'null' => false])
16+
->addColumn('updated_at', 'timestamp', ['limit' => 6, 'null' => true])
17+
->create();
18+
}
19+
}

resources/schema.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ CREATE TABLE `event_store_relation` (
1414
PRIMARY KEY (`event_id`,`domain_tag`),
1515
CONSTRAINT `event_store_relation_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `event_store` (`id`)
1616
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
17+
18+
CREATE TABLE `saga_store` (
19+
`saga_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
20+
`saga_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
21+
`payload` json NOT NULL,
22+
`created_at` timestamp(6) NOT NULL,
23+
`updated_at` timestamp(6) NULL DEFAULT NULL,
24+
PRIMARY KEY (`saga_id`, `saga_name`)
25+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

0 commit comments

Comments
 (0)