Skip to content

Commit b35e2ed

Browse files
committed
feat: add test for multiple Yates clients operating in the same DB
1 parent 0d00e29 commit b35e2ed

File tree

46 files changed

+8727
-19
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+8727
-19
lines changed

.github/workflows/npm-audit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
secrets: inherit
1919
with:
2020
reviewers-list: ${{ vars.BACKEND_REVIEWER_LIST }}
21-
node-version: '20'
21+
node-version: '22'

.github/workflows/npm-pack-check.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ jobs:
1818
uses: actions/setup-node@v3
1919
with:
2020
registry-url: https://registry.npmjs.org/
21-
node-version: 20
21+
node-version: 22
2222

2323
# Install dependencies so that prepublish scripts work as expected
2424
- name: Install deps
2525
run: npm ci
2626

27+
- name: Generate base client for types
28+
run: npm run generate
29+
2730
- name: Build package
2831
run: npm run build
2932

.github/workflows/publish-beta.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/setup-node@v3
2121
with:
2222
registry-url: https://registry.npmjs.org/
23-
node-version: 20
23+
node-version: 22
2424

2525
# Use a cache for dependencies
2626
- uses: actions/cache@v4

.github/workflows/release-please.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
if: ${{ steps.release.outputs.release_created }}
2424
- uses: actions/setup-node@v3
2525
with:
26-
node-version: 20
26+
node-version: 22
2727
registry-url: "https://registry.npmjs.org"
2828
if: ${{ steps.release.outputs.release_created }}
2929
- run: npm i

.github/workflows/unit-test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ jobs:
99
- uses: actions/checkout@v3
1010
- uses: actions/setup-node@v1
1111
with:
12-
node-version: 20
12+
node-version: 22
1313
- run: npm ci
14+
- run: npm run generate
1415
- run: npm test
1516
- run: npm run test:types

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,5 @@ tags
257257

258258
dist/
259259
.npmrc
260-
*.tgz
260+
*.tgz
261+
prisma/generated

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
33
"files": {
4-
"ignore": ["dist", "coverage", "package.json"]
4+
"ignore": ["dist", "coverage", "package.json", "prisma/secondary/generated"]
55
},
66
"organizeImports": {
77
"enabled": true

docker-compose.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ services:
1717
- internal
1818
environment:
1919
- DATABASE_URL=postgresql://postgres:postgres@db:5432/yates?connection_limit=30
20+
- DATABASE_URL_2=postgresql://postgres:postgres@db:5432/yates_2?connection_limit=30
2021

2122
db:
2223
image: postgres:11
24+
volumes:
25+
- ./docker-init:/docker-entrypoint-initdb.d
2326
restart: always
2427
environment:
2528
POSTGRES_USER: postgres
2629
POSTGRES_PASSWORD: postgres
27-
POSTGRES_DB: yates
30+
POSTGRES_MULTIPLE_DATABASES: yates,yates_2
2831
ports:
2932
- 5432:5432
3033
networks:

docker-init/setup-databases.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# Borrowed from https://github.com/mrts/docker-postgresql-multiple-databases
3+
# This script creates multiple Postgres databases, so we can test multi-tenant setups
4+
5+
set -e
6+
set -u
7+
8+
function create_user_and_database() {
9+
local database=$1
10+
echo " Creating user and database '$database'"
11+
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
12+
CREATE USER $database;
13+
CREATE DATABASE $database;
14+
GRANT ALL PRIVILEGES ON DATABASE $database TO $database;
15+
EOSQL
16+
}
17+
18+
if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
19+
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
20+
for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
21+
create_user_and_database $db
22+
done
23+
echo "Multiple databases created"
24+
fi

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
"images"
1010
],
1111
"scripts": {
12-
"generate": "prisma generate",
12+
"generate": "prisma generate --schema prisma/primary/schema.prisma && prisma generate --schema prisma/secondary/schema.prisma",
1313
"build": "rimraf dist && tsc -p tsconfig.build.json",
1414
"test": "npm run lint",
1515
"lint": "biome check .",
1616
"lint:fix": "biome check . --apply",
1717
"test:types": "tsc --noEmit",
1818
"test:integration": "jest --runInBand test/integration",
1919
"test:compose:integration": "docker compose -f docker-compose.yml --profile with-sut up db sut --exit-code-from sut",
20-
"setup": "prisma generate && prisma migrate dev",
20+
"setup": "prisma generate --schema prisma/primary/schema.prisma && prisma migrate dev --schema prisma/primary/schema.prisma && prisma generate --schema prisma/secondary/schema.prisma && prisma migrate dev --schema prisma/secondary/schema.prisma",
2121
"prepublishOnly": "npm run build"
2222
},
2323
"author": "Cerebrum <[email protected]> (https://cerebrum.com)",

0 commit comments

Comments
 (0)