Skip to content

Commit e5e7075

Browse files
committed
Implemented a first working flow of projections handling
1 parent 59ee620 commit e5e7075

File tree

16 files changed

+59
-69
lines changed

16 files changed

+59
-69
lines changed

samples/from_crud_to_eventsourcing/.vscode/launch.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "Debug",
5+
"name": "Debug CRUD",
66
"type": "node",
77
"request": "launch",
88
"runtimeExecutable": "npm",
9-
"runtimeArgs": ["run-script", "start", "--", "--inspect-brk=9229"],
9+
"runtimeArgs": ["run-script", "start:crud", "--", "--inspect-brk=9229"],
1010
"port": 9229
1111
},
1212
{
13-
"name": "Debug Server",
13+
"name": "Debug Event-Sourced",
1414
"type": "node",
1515
"request": "launch",
1616
"runtimeExecutable": "npm",
17-
"runtimeArgs": ["run-script", "start:server", "--", "--inspect-brk=9229"],
17+
"runtimeArgs": [
18+
"run-script",
19+
"start:eventsourced",
20+
"--",
21+
"--inspect-brk=9229"
22+
],
1823
"port": 9229
1924
}
2025
]

samples/from_crud_to_eventsourcing/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ const convictConfig = convict({
2525
arg: 'DATABASE_URL',
2626
env: 'DATABASE_URL',
2727
},
28+
schemaName: {
29+
format: String,
30+
default: 'postgres',
31+
arg: 'DATABASE_SCHEMA',
32+
env: 'DATABASE_SCHEMA',
33+
},
2834
},
2935
});
3036

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"postgres": {
3+
"schemaName": "ecommerce"
4+
}
5+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"postgres": {
3+
"schemaName": "ecommerce"
4+
}
5+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"postgres": {
3+
"schemaName": "ecommerce"
4+
}
5+
}

samples/from_crud_to_eventsourcing/data.sql

Lines changed: 0 additions & 35 deletions
This file was deleted.

samples/from_crud_to_eventsourcing/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
"fix": "npm run fix:eslint && npm run fix:prettier",
1414
"fix:prettier": "prettier --write \"**/**/!(*.d).{ts,json,md}\"",
1515
"fix:eslint": "eslint **/*.ts --fix",
16+
"crud:setup": "run-s crud:migrate crud:generate",
1617
"crud:migrate": "pg-migrations apply --database postgres://postgres:Password12!@localhost:5432/postgres --directory ./src/crud/migrations/",
1718
"crud:generate": "npx @databases/pg-schema-cli --database postgres://postgres:Password12!@localhost:5432/postgres --schemaName ecommerce --directory src/crud/db/__generated__",
19+
"eventsourced:setup": "run-s eventsourced:migrate eventsourced:generate",
1820
"eventsourced:generate": "npx @databases/pg-schema-cli --database postgres://postgres:Password12!@localhost:5432/postgres --schemaName ecommerce --directory src/eventsourced/db/__generated__",
1921
"eventsourced:migrate": "pg-migrations apply --database postgres://postgres:Password12!@localhost:5432/postgres --directory ./src/eventsourced/migrations/ --ignore-error migration_file_edited"
2022
},

samples/from_crud_to_eventsourcing/src/core/postgres.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ import { DEFAULT_RETRY_OPTIONS, RetryOptions, retryPromise } from './retries';
99
let db: ConnectionPool;
1010

1111
export const getPostgres = (): ConnectionPool => {
12-
if (!config.postgres.connectionString) {
13-
throw 'Postgres connection string not set. Please define "DATABASE_URL" environment variable';
14-
}
15-
1612
if (!db) {
17-
db = createConnectionPool(config.postgres.connectionString);
13+
if (!config.postgres.connectionString) {
14+
throw 'Postgres connection string not set. Please define "DATABASE_URL" environment variable';
15+
}
16+
17+
if (!config.postgres.schemaName) {
18+
throw 'Postgres schema name string not set. Please define "DATABASE_SCHEMA" environment variable';
19+
}
20+
21+
db = createConnectionPool({
22+
connectionString: config.postgres.connectionString,
23+
schema: config.postgres.schemaName,
24+
});
1825
}
1926

2027
return db;

samples/from_crud_to_eventsourcing/src/crud/migrations/0001-initial_migration.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ CREATE TABLE "ecommerce"."cart"
2121
"content" TEXT NULL DEFAULT NULL
2222
);
2323

24+
CREATE UNIQUE INDEX "idx_cart_sessionId"
25+
ON "ecommerce"."cart" ("sessionId");
26+
2427
CREATE TABLE "ecommerce"."cart_item"
2528
(
2629
"id" BIGSERIAL PRIMARY KEY,

samples/from_crud_to_eventsourcing/src/eventsourced/core/subscriptions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export const SubscriptionToAll =
4747
console.error(`Received error: ${error ?? 'UNEXPECTED ERROR'}.`);
4848
}
4949
);
50+
console.info('Subscription is running');
51+
5052
return subscription;
5153
};
5254

0 commit comments

Comments
 (0)