Skip to content

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

Merge branch 'master' into umami-import

Edward Cuie7096995edcf
diff --cc server/src/db/clickhouse/clickhouse.ts
index 2b5683c56,60c9b95c6..4e53bb45f
--- a/server/src/db/clickhouse/clickhouse.ts
+++ b/server/src/db/clickhouse/clickhouse.ts
@@@ -59,7 -59,7 +59,8 @@@ export const initializeClickhouse = asy
ADD COLUMN IF NOT EXISTS ttfb Nullable(Float64),
ADD COLUMN IF NOT EXISTS ip Nullable(String),
ADD COLUMN IF NOT EXISTS timezone LowCardinality(String) DEFAULT '',
- ADD COLUMN IF NOT EXISTS identified_user_id String DEFAULT ''
++ ADD COLUMN IF NOT EXISTS identified_user_id String DEFAULT '',
+ ADD COLUMN IF NOT EXISTS import_id Nullable(UUID)
`,
});
diff --cc server/src/db/postgres/schema.ts
index a0655e6db,4901d01b8..1cacb6fe2
--- a/server/src/db/postgres/schema.ts
+++ b/server/src/db/postgres/schema.ts
@@@ -525,33 -524,39 +526,70 @@@ export const gscConnections = pgTable("
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow().notNull(),
});
+ // User profiles - stores identified user traits (email, name, custom fields)
+ export const userProfiles = pgTable(
+ "user_profiles",
+ {
+ siteId: integer("site_id")
+ .notNull()
+ .references(() => sites.siteId, { onDelete: "cascade" }),
+ userId: text("user_id").notNull(), // The identified user ID from identify() call
+ traits: jsonb("traits").$type<Record<string, unknown>>().default({}),
+ createdAt: timestamp("created_at", { mode: "string" }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow().notNull(),
+ },
+ (table) => [
+ primaryKey({ columns: [table.siteId, table.userId] }),
+ index("user_profiles_site_idx").on(table.siteId),
+ ]
+ );
+
+ // User aliases - maps anonymous IDs to identified users (multi-device support)
+ export const userAliases = pgTable(
+ "user_aliases",
+ {
+ id: serial("id").primaryKey().notNull(),
+ siteId: integer("site_id")
+ .notNull()
+ .references(() => sites.siteId, { onDelete: "cascade" }),
+ anonymousId: text("anonymous_id").notNull(), // Hash of IP+UserAgent (device fingerprint)
+ userId: text("user_id").notNull(), // The identified user ID
+ createdAt: timestamp("created_at", { mode: "string" }).defaultNow().notNull(),
+ },
+ (table) => [
+ unique("user_aliases_site_anon_unique").on(table.siteId, table.anonymousId),
+ index("user_aliases_user_idx").on(table.siteId, table.userId),
+ index("user_aliases_anon_idx").on(table.siteId, table.anonymousId),
+ ]
+ );
++
+export const importPlatforms = ["umami"] as const;
+
+export const importPlatformEnum = pgEnum("import_platform_enum", importPlatforms);
+
+export const importStatus = pgTable(
+ "import_status",
+ {
+ importId: uuid("import_id").primaryKey().notNull().defaultRandom(),
+ siteId: integer("site_id").notNull(),
+ organizationId: text("organization_id").notNull(),
+ platform: importPlatformEnum("platform").notNull(),
+ importedEvents: integer("imported_events").notNull().default(0),
+ skippedEvents: integer("skipped_events").notNull().default(0),
+ invalidEvents: integer("invalid_events").notNull().default(0),
+ startedAt: timestamp("started_at", { mode: "string" }).notNull().defaultNow(),
+ completedAt: timestamp("completed_at", { mode: "string" }),
+ },
+ table => [
+ foreignKey({
+ columns: [table.siteId],
+ foreignColumns: [sites.siteId],
+ name: "import_status_site_id_sites_site_id_fk",
+ }),
+ foreignKey({
+ columns: [table.organizationId],
+ foreignColumns: [organization.id],
+ name: "import_status_organization_id_organization_id_fk",
+ }),
+ ]
+);