Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/auth/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ export const authOptions: NextAuthOptions = {
});
}

// Check if the user has a team, if not create one
if (resp && !resp.teamId) {
// Create a team for the admin
const team = await prisma.team.create({
data: {
name: "Admin Team",
},
});

// Update the user with the teamId
await prisma.user.update({
where: { id: resp.id },
data: { teamId: team.id },
});
}

if (resp) {
// Any object returned will be saved in `user` property of the JWT
const user = {
Expand Down
48 changes: 27 additions & 21 deletions scripts/create-clickhouse-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,34 @@ import { loadEnvConfig } from "@next/env";
loadEnvConfig(process.cwd());

const chClient = createClient({
database: "default",
url: process.env.CLICK_HOUSE_HOST,
username: process.env.CLICK_HOUSE_USER,
password: process.env.CLICK_HOUSE_PASSWORD,
compression: {
response: true,
},
clickhouse_settings: {
async_insert: 1,
wait_for_async_insert: 1,
},
database: "default",
url: process.env.CLICK_HOUSE_HOST,
username: process.env.CLICK_HOUSE_USER,
password: process.env.CLICK_HOUSE_PASSWORD,
compression: {
response: true,
},
clickhouse_settings: {
async_insert: 1,
wait_for_async_insert: 1,
connect_timeout: 30000, // 30 seconds timeout
},
request_timeout: 30000, // 30 seconds timeout
keep_alive: {
enabled: true,
idle_socket_ttl: 60000,
},
});

console.log("Creating Clickhouse DB if not exists...");
chClient
.query({
query: `CREATE DATABASE IF NOT EXISTS ${process.env.CLICK_HOUSE_DATABASE_NAME}`,
})
.then((res) => {
console.log(res.query_id);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
.query({
query: `CREATE DATABASE IF NOT EXISTS ${process.env.CLICK_HOUSE_DATABASE_NAME}`,
})
.then((res) => {
console.log(res.query_id);
})
.catch((err) => {
console.error(err);
process.exit(1);
});