@entifix/sql 0.23.2 → 0.23.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,11 +7,23 @@ export declare const SQL_TRANSACTION_TABLES: {
|
|
|
7
7
|
readonly commandInbox: "entifix_command_inbox";
|
|
8
8
|
readonly idempotency: "entifix_idempotency";
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* The advisory lock the table creation holds, so two processes booting against
|
|
12
|
+
* one empty database create the tables one after the other.
|
|
13
|
+
*/
|
|
14
|
+
export declare const SQL_TRANSACTION_TABLES_LOCK = "entifix:transaction-tables";
|
|
10
15
|
/**
|
|
11
16
|
* Creates the outbox, the event and command inboxes and the idempotency table
|
|
12
17
|
* if they are missing. Idempotent, so a service runs it on every boot; Postgres
|
|
13
18
|
* dialect, because the outbox's claim rides `FOR UPDATE SKIP LOCKED` and an
|
|
14
19
|
* advisory lock.
|
|
20
|
+
*
|
|
21
|
+
* ⚠️ **Serialized, because `IF NOT EXISTS` is not.** Two sessions can both see
|
|
22
|
+
* a table missing, and the second `CREATE` then fails on `pg_type`'s unique
|
|
23
|
+
* index (`23505`) — which is what a service's HTTP replica and its runner did,
|
|
24
|
+
* booting together after a reset. The DDL runs in one transaction behind a
|
|
25
|
+
* transaction-scoped advisory lock: the second caller waits for the first to
|
|
26
|
+
* commit, then finds every table there.
|
|
15
27
|
*/
|
|
16
28
|
export declare const ensureSqlTransactionTables: (sql: SqlClient.SqlClient) => Effect.Effect<void, import("@entifix/core").StoreFailure, never>;
|
|
17
29
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/transactions/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAI5C,4EAA4E;AAC5E,eAAO,MAAM,sBAAsB;;;;;CAKzB,CAAC;AAEX
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/transactions/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAI5C,4EAA4E;AAC5E,eAAO,MAAM,sBAAsB;;;;;CAKzB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,2BAA2B,+BAA+B,CAAC;AAExE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0BAA0B,GAAI,KAAK,SAAS,CAAC,SAAS,qEA6ChE,CAAC"}
|
|
@@ -6,12 +6,24 @@ import { translateSqlError } from '../errors/translate-sql-error.js';
|
|
|
6
6
|
commandInbox: 'entifix_command_inbox',
|
|
7
7
|
idempotency: 'entifix_idempotency'
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* The advisory lock the table creation holds, so two processes booting against
|
|
11
|
+
* one empty database create the tables one after the other.
|
|
12
|
+
*/ export const SQL_TRANSACTION_TABLES_LOCK = 'entifix:transaction-tables';
|
|
9
13
|
/**
|
|
10
14
|
* Creates the outbox, the event and command inboxes and the idempotency table
|
|
11
15
|
* if they are missing. Idempotent, so a service runs it on every boot; Postgres
|
|
12
16
|
* dialect, because the outbox's claim rides `FOR UPDATE SKIP LOCKED` and an
|
|
13
17
|
* advisory lock.
|
|
18
|
+
*
|
|
19
|
+
* ⚠️ **Serialized, because `IF NOT EXISTS` is not.** Two sessions can both see
|
|
20
|
+
* a table missing, and the second `CREATE` then fails on `pg_type`'s unique
|
|
21
|
+
* index (`23505`) — which is what a service's HTTP replica and its runner did,
|
|
22
|
+
* booting together after a reset. The DDL runs in one transaction behind a
|
|
23
|
+
* transaction-scoped advisory lock: the second caller waits for the first to
|
|
24
|
+
* commit, then finds every table there.
|
|
14
25
|
*/ export const ensureSqlTransactionTables = (sql)=>Effect.gen(function*() {
|
|
26
|
+
yield* sql`SELECT pg_advisory_xact_lock(hashtext(${SQL_TRANSACTION_TABLES_LOCK}))`;
|
|
15
27
|
yield* sql`
|
|
16
28
|
CREATE TABLE IF NOT EXISTS entifix_outbox (
|
|
17
29
|
event_id text PRIMARY KEY,
|
|
@@ -51,6 +63,6 @@ import { translateSqlError } from '../errors/translate-sql-error.js';
|
|
|
51
63
|
response jsonb,
|
|
52
64
|
expires_at timestamptz NOT NULL
|
|
53
65
|
)`;
|
|
54
|
-
}).pipe(Effect.mapError((error)=>translateSqlError(error)));
|
|
66
|
+
}).pipe(sql.withTransaction, Effect.mapError((error)=>translateSqlError(error)));
|
|
55
67
|
|
|
56
68
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transactions/schema.ts"],"sourcesContent":["import { Effect } from 'effect';\nimport type { SqlClient } from 'effect/sql';\n\nimport { translateSqlError } from '../errors/translate-sql-error.js';\n\n/** The tables the outbox, the inboxes and the idempotency store live in. */\nexport const SQL_TRANSACTION_TABLES = {\n outbox: 'entifix_outbox',\n inbox: 'entifix_inbox',\n commandInbox: 'entifix_command_inbox',\n idempotency: 'entifix_idempotency',\n} as const;\n\n/**\n * Creates the outbox, the event and command inboxes and the idempotency table\n * if they are missing. Idempotent, so a service runs it on every boot; Postgres\n * dialect, because the outbox's claim rides `FOR UPDATE SKIP LOCKED` and an\n * advisory lock.\n */\nexport const ensureSqlTransactionTables = (sql: SqlClient.SqlClient) =>\n Effect.gen(function* () {\n yield* sql`\n CREATE TABLE IF NOT EXISTS entifix_outbox (\n event_id text PRIMARY KEY,\n aggregate_type text NOT NULL,\n aggregate_id text NOT NULL,\n version integer NOT NULL,\n event jsonb NOT NULL,\n sent boolean NOT NULL DEFAULT false,\n attempts integer NOT NULL DEFAULT 0,\n last_error text,\n quarantined boolean NOT NULL DEFAULT false,\n created_at timestamptz NOT NULL,\n lease_until timestamptz\n )`;\n yield* sql`\n CREATE INDEX IF NOT EXISTS entifix_outbox_pending\n ON entifix_outbox (created_at, version)\n WHERE NOT sent AND NOT quarantined`;\n yield* sql`\n CREATE TABLE IF NOT EXISTS entifix_inbox (\n consumer text NOT NULL,\n event_id text NOT NULL,\n claimed_at timestamptz NOT NULL DEFAULT now(),\n PRIMARY KEY (consumer, event_id)\n )`;\n yield* sql`\n CREATE TABLE IF NOT EXISTS entifix_command_inbox (\n command_id text PRIMARY KEY,\n claimed_at timestamptz NOT NULL DEFAULT now(),\n replay jsonb\n )`;\n yield* sql`\n CREATE TABLE IF NOT EXISTS entifix_idempotency (\n dedup_key text PRIMARY KEY,\n fingerprint text NOT NULL,\n state text NOT NULL,\n response jsonb,\n expires_at timestamptz NOT NULL\n )`;\n }).pipe(Effect.mapError(error => translateSqlError(error)));\n"],"names":["Effect","translateSqlError","SQL_TRANSACTION_TABLES","outbox","inbox","commandInbox","idempotency","ensureSqlTransactionTables","sql","gen","pipe","mapError","error"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAGhC,SAASC,iBAAiB,QAAQ,mCAAmC;AAErE,0EAA0E,GAC1E,OAAO,MAAMC,yBAAyB;IACpCC,QAAQ;IACRC,OAAO;IACPC,cAAc;IACdC,aAAa;AACf,EAAW;AAEX
|
|
1
|
+
{"version":3,"sources":["../../src/transactions/schema.ts"],"sourcesContent":["import { Effect } from 'effect';\nimport type { SqlClient } from 'effect/sql';\n\nimport { translateSqlError } from '../errors/translate-sql-error.js';\n\n/** The tables the outbox, the inboxes and the idempotency store live in. */\nexport const SQL_TRANSACTION_TABLES = {\n outbox: 'entifix_outbox',\n inbox: 'entifix_inbox',\n commandInbox: 'entifix_command_inbox',\n idempotency: 'entifix_idempotency',\n} as const;\n\n/**\n * The advisory lock the table creation holds, so two processes booting against\n * one empty database create the tables one after the other.\n */\nexport const SQL_TRANSACTION_TABLES_LOCK = 'entifix:transaction-tables';\n\n/**\n * Creates the outbox, the event and command inboxes and the idempotency table\n * if they are missing. Idempotent, so a service runs it on every boot; Postgres\n * dialect, because the outbox's claim rides `FOR UPDATE SKIP LOCKED` and an\n * advisory lock.\n *\n * ⚠️ **Serialized, because `IF NOT EXISTS` is not.** Two sessions can both see\n * a table missing, and the second `CREATE` then fails on `pg_type`'s unique\n * index (`23505`) — which is what a service's HTTP replica and its runner did,\n * booting together after a reset. The DDL runs in one transaction behind a\n * transaction-scoped advisory lock: the second caller waits for the first to\n * commit, then finds every table there.\n */\nexport const ensureSqlTransactionTables = (sql: SqlClient.SqlClient) =>\n Effect.gen(function* () {\n yield* sql`SELECT pg_advisory_xact_lock(hashtext(${SQL_TRANSACTION_TABLES_LOCK}))`;\n yield* sql`\n CREATE TABLE IF NOT EXISTS entifix_outbox (\n event_id text PRIMARY KEY,\n aggregate_type text NOT NULL,\n aggregate_id text NOT NULL,\n version integer NOT NULL,\n event jsonb NOT NULL,\n sent boolean NOT NULL DEFAULT false,\n attempts integer NOT NULL DEFAULT 0,\n last_error text,\n quarantined boolean NOT NULL DEFAULT false,\n created_at timestamptz NOT NULL,\n lease_until timestamptz\n )`;\n yield* sql`\n CREATE INDEX IF NOT EXISTS entifix_outbox_pending\n ON entifix_outbox (created_at, version)\n WHERE NOT sent AND NOT quarantined`;\n yield* sql`\n CREATE TABLE IF NOT EXISTS entifix_inbox (\n consumer text NOT NULL,\n event_id text NOT NULL,\n claimed_at timestamptz NOT NULL DEFAULT now(),\n PRIMARY KEY (consumer, event_id)\n )`;\n yield* sql`\n CREATE TABLE IF NOT EXISTS entifix_command_inbox (\n command_id text PRIMARY KEY,\n claimed_at timestamptz NOT NULL DEFAULT now(),\n replay jsonb\n )`;\n yield* sql`\n CREATE TABLE IF NOT EXISTS entifix_idempotency (\n dedup_key text PRIMARY KEY,\n fingerprint text NOT NULL,\n state text NOT NULL,\n response jsonb,\n expires_at timestamptz NOT NULL\n )`;\n }).pipe(\n sql.withTransaction,\n Effect.mapError(error => translateSqlError(error)),\n );\n"],"names":["Effect","translateSqlError","SQL_TRANSACTION_TABLES","outbox","inbox","commandInbox","idempotency","SQL_TRANSACTION_TABLES_LOCK","ensureSqlTransactionTables","sql","gen","pipe","withTransaction","mapError","error"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAGhC,SAASC,iBAAiB,QAAQ,mCAAmC;AAErE,0EAA0E,GAC1E,OAAO,MAAMC,yBAAyB;IACpCC,QAAQ;IACRC,OAAO;IACPC,cAAc;IACdC,aAAa;AACf,EAAW;AAEX;;;CAGC,GACD,OAAO,MAAMC,8BAA8B,6BAA6B;AAExE;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,6BAA6B,CAACC,MACzCT,OAAOU,GAAG,CAAC;QACT,OAAOD,GAAG,CAAC,sCAAsC,EAAEF,4BAA4B,EAAE,CAAC;QAClF,OAAOE,GAAG,CAAC;;;;;;;;;;;;;OAaR,CAAC;QACJ,OAAOA,GAAG,CAAC;;;0CAG2B,CAAC;QACvC,OAAOA,GAAG,CAAC;;;;;;OAMR,CAAC;QACJ,OAAOA,GAAG,CAAC;;;;;OAKR,CAAC;QACJ,OAAOA,GAAG,CAAC;;;;;;;OAOR,CAAC;IACN,GAAGE,IAAI,CACLF,IAAIG,eAAe,EACnBZ,OAAOa,QAAQ,CAACC,CAAAA,QAASb,kBAAkBa,SAC3C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/sql",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.4",
|
|
4
4
|
"description": "SQL adapter over @effect/sql: an entity repository with RSQL filter and sort translation, and a health probe.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -63,18 +63,18 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@swc/helpers": "0.5.23",
|
|
66
|
-
"@entifix/
|
|
67
|
-
"@entifix/
|
|
66
|
+
"@entifix/business": "0.23.4",
|
|
67
|
+
"@entifix/core": "0.23.4"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@effect/sql-pg": "4.0.7",
|
|
71
71
|
"effect": "4.0.7",
|
|
72
|
-
"@entifix/
|
|
73
|
-
"@entifix/
|
|
72
|
+
"@entifix/testing-unit": "0.23.4",
|
|
73
|
+
"@entifix/transactions": "0.23.4"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"effect": "^4.0.7",
|
|
77
|
-
"@entifix/transactions": "0.23.
|
|
77
|
+
"@entifix/transactions": "0.23.4"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"@entifix/transactions": {
|