Skip to content

Commit 023a20f

Browse files
committed
Add script to add test user to db
1 parent 62821ed commit 023a20f

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

scripts/users.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// This is a script to add a user to the DB: entries in the users and private_users table
2+
// Run with:
3+
// export ENVIRONMENT=DEV && ./../scripts/build_api.sh && npx tsx users.ts
4+
5+
import {createSupabaseDirectClient} from "shared/lib/supabase/init";
6+
import {insert} from "shared/lib/supabase/utils";
7+
import {PrivateUser} from "common/lib/user";
8+
import {getDefaultNotificationPreferences} from "common/lib/user-notification-preferences";
9+
import {randomString} from "common/lib/util/random";
10+
11+
(async () => {
12+
13+
const userId = '...'
14+
const email = '...'
15+
const name = '...'
16+
const username = '...'
17+
const ip = '...'
18+
const deviceToken = randomString()
19+
const pg = createSupabaseDirectClient()
20+
21+
const user = {
22+
// avatarUrl,
23+
isBannedFromPosting: false,
24+
link: {},
25+
}
26+
27+
const privateUser: PrivateUser = {
28+
id: userId,
29+
email,
30+
initialIpAddress: ip,
31+
initialDeviceToken: deviceToken,
32+
notificationPreferences: getDefaultNotificationPreferences(),
33+
blockedUserIds: [],
34+
blockedByUserIds: [],
35+
}
36+
37+
await pg.tx(async (tx) => {
38+
39+
const newUserRow = await insert(tx, 'users', {
40+
id: userId,
41+
name,
42+
username,
43+
data: user,
44+
})
45+
46+
console.log(newUserRow)
47+
48+
const newPrivateUserRow = await insert(tx, 'private_users', {
49+
id: userId,
50+
data: privateUser,
51+
})
52+
53+
console.log(newPrivateUserRow)
54+
55+
})
56+
57+
process.exit(0)
58+
})()

0 commit comments

Comments
 (0)