Skip to content

Commit 50d9066

Browse files
committed
chore: generate database fixtures
Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
1 parent b0cc5eb commit 50d9066

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

migrations/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
FROM node:slim AS builder
2+
3+
COPY generate-fixtures.js /generate-fixtures.js
4+
RUN node /generate-fixtures.js > /fixtures.sql
5+
16
FROM postgres:14.2-bullseye
27

38
COPY *.sql /docker-entrypoint-initdb.d/
4-
9+
COPY --from=builder /fixtures.sql /docker-entrypoint-initdb.d/99999999999999-fixtures.sql

migrations/generate-fixtures.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const crypto = require('crypto');
2+
3+
const USER_COUNT = 1_000_000;
4+
const LIST_COUNT = 1_000_000;
5+
const TASK_COUNT = 1_000_000;
6+
7+
const randomStr = (len = 32) =>
8+
crypto.randomBytes(len).toString('hex');
9+
10+
for (let user_index = 0; user_index < USER_COUNT; user_index++) {
11+
const user_id = crypto.randomUUID();
12+
const user_login = randomStr();
13+
console.log(`INSERT INTO account (id, login) VALUES ('${user_id}','user_${user_index}');`);
14+
15+
for (let list_index = 0; list_index < LIST_COUNT; list_index++) {
16+
const list_id = crypto.randomUUID();
17+
const list_name = randomStr();
18+
console.log(`INSERT INTO list (id, account_id, name) VALUES ('${list_id}','${user_id}','${list_name}');`);
19+
20+
for (let task_index = 0; task_index < TASK_COUNT; task_index++) {
21+
const task_name = randomStr();
22+
const task_description = randomStr(20);
23+
console.log(`INSERT INTO task (list_id, name, description) VALUES ('${list_id}','${task_name}','${task_description}');`);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)