(options?: {
readonly prefix?: string | undefined
})
| 614 | // ------------------------------------------------------------------------------------------------- |
| 615 | |
| 616 | const migrations = (options?: { |
| 617 | readonly prefix?: string | undefined |
| 618 | }) => { |
| 619 | const prefix = options?.prefix ?? "cluster" |
| 620 | const table = (name: string) => `${prefix}_${name}` |
| 621 | const messagesTable = table("messages") |
| 622 | const repliesTable = table("replies") |
| 623 | |
| 624 | return Migrator.fromRecord({ |
| 625 | "0001_create_tables": Effect.gen(function*() { |
| 626 | const sql = (yield* SqlClient.SqlClient).withoutTransforms() |
| 627 | const messagesTableSql = sql(messagesTable) |
| 628 | const repliesTableSql = sql(repliesTable) |
| 629 | |
| 630 | yield* sql.onDialectOrElse({ |
| 631 | mssql: () => |
| 632 | sql` |
| 633 | IF OBJECT_ID(N'${messagesTableSql}', N'U') IS NULL |
| 634 | CREATE TABLE ${messagesTableSql} ( |
| 635 | id BIGINT PRIMARY KEY, |
| 636 | rowid BIGINT IDENTITY(1,1), |
| 637 | message_id VARCHAR(255), |
| 638 | shard_id VARCHAR(50) NOT NULL, |
| 639 | entity_type VARCHAR(150) NOT NULL, |
| 640 | entity_id VARCHAR(255) NOT NULL, |
| 641 | kind INT NOT NULL, |
| 642 | tag VARCHAR(50), |
| 643 | payload TEXT, |
| 644 | headers TEXT, |
| 645 | trace_id VARCHAR(32), |
| 646 | span_id VARCHAR(16), |
| 647 | sampled BIT, |
| 648 | processed BIT NOT NULL DEFAULT 0, |
| 649 | request_id BIGINT NOT NULL, |
| 650 | reply_id BIGINT, |
| 651 | last_reply_id BIGINT, |
| 652 | last_read DATETIME, |
| 653 | deliver_at BIGINT, |
| 654 | UNIQUE (message_id) |
| 655 | ) |
| 656 | `, |
| 657 | mysql: () => |
| 658 | sql` |
| 659 | CREATE TABLE IF NOT EXISTS ${messagesTableSql} ( |
| 660 | id BIGINT NOT NULL, |
| 661 | rowid BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, |
| 662 | message_id VARCHAR(255), |
| 663 | shard_id VARCHAR(50) NOT NULL, |
| 664 | entity_type VARCHAR(150) NOT NULL, |
| 665 | entity_id VARCHAR(255) NOT NULL, |
| 666 | kind INT NOT NULL, |
| 667 | tag VARCHAR(50), |
| 668 | payload TEXT, |
| 669 | headers TEXT, |
| 670 | trace_id VARCHAR(32), |
| 671 | span_id VARCHAR(16), |
| 672 | sampled BOOLEAN, |
| 673 | processed BOOLEAN NOT NULL DEFAULT FALSE, |
no test coverage detected