Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Fix init (#37)

Bill Yang416342e5082d
diff --git a/docker-compose.yml b/docker-compose.yml
index 2c31a7ea4..17a0037ea 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -11,6 +11,8 @@ services:
- clickhouse-data:/var/lib/clickhouse
environment:
- CLICKHOUSE_DB=analytics
+ - CLICKHOUSE_USER=default
+ - CLICKHOUSE_PASSWORD=frog
postgres:
image: postgres:latest
@@ -35,6 +37,7 @@ services:
- NODE_ENV=production
- CLICKHOUSE_HOST=http://clickhouse:8123
- CLICKHOUSE_DB=analytics
+ - CLICKHOUSE_PASSWORD=frog
- POSTGRES_HOST=postgres
- POSTGRES_PORT=5432
- POSTGRES_DB=analytics
diff --git a/server/src/db/clickhouse/clickhouse.ts b/server/src/db/clickhouse/clickhouse.ts
index 7576b6278..cd11a64ed 100644
--- a/server/src/db/clickhouse/clickhouse.ts
+++ b/server/src/db/clickhouse/clickhouse.ts
@@ -4,6 +4,7 @@ import { Session } from "../postgres/types.js";
export const clickhouse = createClient({
host: process.env.CLICKHOUSE_HOST,
database: process.env.CLICKHOUSE_DB,
+ password: process.env.CLICKHOUSE_PASSWORD,
});
export const initializeClickhouse = async () => {
@@ -11,7 +12,7 @@ export const initializeClickhouse = async () => {
await clickhouse.exec({
query: `
CREATE TABLE IF NOT EXISTS pageviews (
- site_id Uint16,
+ site_id UInt16,
timestamp DateTime,
session_id String,
user_id String,
@@ -34,14 +35,14 @@ export const initializeClickhouse = async () => {
ENGINE = MergeTree()
PARTITION BY toYYYYMM(timestamp)
ORDER BY (timestamp, session_id)
- `,
+ `,
});
// Create sessions table
await clickhouse.exec({
query: `
CREATE TABLE IF NOT EXISTS sessions (
- site_id Uint16,
+ site_id UInt16,
hostname String,
session_id String,
start_time DateTime,
diff --git a/server/src/db/postgres/postgres.ts b/server/src/db/postgres/postgres.ts
index 809b8b017..0b1b20e7c 100644
--- a/server/src/db/postgres/postgres.ts
+++ b/server/src/db/postgres/postgres.ts
@@ -104,10 +104,11 @@ export async function initializePostgres() {
);
`;
- const user =
+ const [{ count }]: { count: number }[] =
await sql`SELECT count(*) FROM "user" WHERE username = 'admin'`;
- if (user.length === 0) {
- auth!.api.signUpEmail({
+
+ if (Number(count) === 0) {
+ await auth!.api.signUpEmail({
body: {
username: "admin",
diff --git a/server/src/index.ts b/server/src/index.ts
index 74b5838ea..132d5a732 100644
--- a/server/src/index.ts
+++ b/server/src/index.ts
@@ -137,7 +137,7 @@ const start = async () => {
try {
console.info("Starting server...");
// Initialize the database
- await Promise.allSettled([initializeClickhouse(), initializePostgres()]);
+ await Promise.all([initializeClickhouse(), initializePostgres()]);
await loadAllowedDomains();
// Start the server
await server.listen({ port: 3001, host: "0.0.0.0" });