Skip to content

Commit 23be3d7

Browse files
authored
Merge pull request #427 from Scale3-Labs/ali/fix-self-hosting-issue
fix selfhosting missing team issue + add proper timeout to clickhouse…
2 parents b5aeab2 + 6289fbe commit 23be3d7

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

lib/auth/options.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ export const authOptions: NextAuthOptions = {
4545
});
4646
}
4747

48+
// Check if the user has a team, if not create one
49+
if (resp && !resp.teamId) {
50+
// Create a team for the admin
51+
const team = await prisma.team.create({
52+
data: {
53+
name: "Admin Team",
54+
},
55+
});
56+
57+
// Update the user with the teamId
58+
await prisma.user.update({
59+
where: { id: resp.id },
60+
data: { teamId: team.id },
61+
});
62+
}
63+
4864
if (resp) {
4965
// Any object returned will be saved in `user` property of the JWT
5066
const user = {

scripts/create-clickhouse-db.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,34 @@ import { loadEnvConfig } from "@next/env";
44
loadEnvConfig(process.cwd());
55

66
const chClient = createClient({
7-
database: "default",
8-
url: process.env.CLICK_HOUSE_HOST,
9-
username: process.env.CLICK_HOUSE_USER,
10-
password: process.env.CLICK_HOUSE_PASSWORD,
11-
compression: {
12-
response: true,
13-
},
14-
clickhouse_settings: {
15-
async_insert: 1,
16-
wait_for_async_insert: 1,
17-
},
7+
database: "default",
8+
url: process.env.CLICK_HOUSE_HOST,
9+
username: process.env.CLICK_HOUSE_USER,
10+
password: process.env.CLICK_HOUSE_PASSWORD,
11+
compression: {
12+
response: true,
13+
},
14+
clickhouse_settings: {
15+
async_insert: 1,
16+
wait_for_async_insert: 1,
17+
connect_timeout: 30000, // 30 seconds timeout
18+
},
19+
request_timeout: 30000, // 30 seconds timeout
20+
keep_alive: {
21+
enabled: true,
22+
idle_socket_ttl: 60000,
23+
},
1824
});
1925

2026
console.log("Creating Clickhouse DB if not exists...");
2127
chClient
22-
.query({
23-
query: `CREATE DATABASE IF NOT EXISTS ${process.env.CLICK_HOUSE_DATABASE_NAME}`,
24-
})
25-
.then((res) => {
26-
console.log(res.query_id);
27-
})
28-
.catch((err) => {
29-
console.error(err);
30-
process.exit(1);
31-
});
28+
.query({
29+
query: `CREATE DATABASE IF NOT EXISTS ${process.env.CLICK_HOUSE_DATABASE_NAME}`,
30+
})
31+
.then((res) => {
32+
console.log(res.query_id);
33+
})
34+
.catch((err) => {
35+
console.error(err);
36+
process.exit(1);
37+
});

0 commit comments

Comments
 (0)