@@ -26,7 +26,8 @@ export function resolveEventRepositoryForStore(
2626 organizationId : string
2727) : IEventRepository {
2828 if ( store === EVENT_STORE_TYPES . CLICKHOUSE || store === EVENT_STORE_TYPES . CLICKHOUSE_V2 ) {
29- return clickhouseFactory . getEventRepositoryForOrganizationSync ( store , organizationId ) . repository ;
29+ return clickhouseFactory . getEventRepositoryForOrganizationSync ( store , organizationId )
30+ . repository ;
3031 }
3132 return eventRepository ;
3233}
@@ -56,10 +57,8 @@ export async function getConfiguredEventRepository(
5657 ( organization . featureFlags as Record < string , unknown > | null ) ?? undefined
5758 ) ;
5859
59- const { repository : resolvedRepository } = await clickhouseFactory . getEventRepositoryForOrganization (
60- taskEventStore ,
61- organizationId
62- ) ;
60+ const { repository : resolvedRepository } =
61+ await clickhouseFactory . getEventRepositoryForOrganization ( taskEventStore , organizationId ) ;
6362
6463 if ( taskEventStore === EVENT_STORE_TYPES . CLICKHOUSE_V2 ) {
6564 return { repository : resolvedRepository , store : EVENT_STORE_TYPES . CLICKHOUSE_V2 } ;
@@ -78,45 +77,45 @@ export async function getEventRepository(
7877 parentStore : string | undefined
7978) : Promise < { repository : IEventRepository ; store : string } > {
8079 const taskEventStore = parentStore ?? ( await resolveTaskEventRepositoryFlag ( featureFlags ) ) ;
81- const { repository : resolvedRepository } = await clickhouseFactory . getEventRepositoryForOrganization (
82- taskEventStore ,
83- organizationId
84- ) ;
8580
86- if ( taskEventStore === "clickhouse_v2" ) {
87- return { repository : resolvedRepository , store : "clickhouse_v2" } ;
81+ // Support legacy Postgres store for self-hosters
82+ if ( taskEventStore === EVENT_STORE_TYPES . POSTGRES ) {
83+ return { repository : eventRepository , store : getTaskEventStore ( ) } ;
8884 }
8985
90- if ( taskEventStore === "clickhouse" ) {
91- return { repository : resolvedRepository , store : "clickhouse" } ;
92- }
86+ const { repository : resolvedRepository } =
87+ await clickhouseFactory . getEventRepositoryForOrganization ( taskEventStore , organizationId ) ;
9388
94- return { repository : eventRepository , store : getTaskEventStore ( ) } ;
89+ switch ( taskEventStore ) {
90+ case EVENT_STORE_TYPES . CLICKHOUSE_V2 : {
91+ return { repository : resolvedRepository , store : EVENT_STORE_TYPES . CLICKHOUSE_V2 } ;
92+ }
93+ case EVENT_STORE_TYPES . CLICKHOUSE : {
94+ return { repository : resolvedRepository , store : EVENT_STORE_TYPES . CLICKHOUSE } ;
95+ }
96+ default : {
97+ return { repository : eventRepository , store : getTaskEventStore ( ) } ;
98+ }
99+ }
95100}
96101
97102export async function getV3EventRepository (
98103 organizationId : string ,
99104 parentStore : string | undefined
100105) : Promise < { repository : IEventRepository ; store : string } > {
101106 if ( typeof parentStore === "string" ) {
102- const { repository : resolvedRepository } = await clickhouseFactory . getEventRepositoryForOrganization (
103- parentStore ,
104- organizationId
105- ) ;
107+ const { repository : resolvedRepository } =
108+ await clickhouseFactory . getEventRepositoryForOrganization ( parentStore , organizationId ) ;
106109 return { repository : resolvedRepository , store : parentStore } ;
107110 }
108111
109112 if ( env . EVENT_REPOSITORY_DEFAULT_STORE === "clickhouse_v2" ) {
110- const { repository : resolvedRepository } = await clickhouseFactory . getEventRepositoryForOrganization (
111- "clickhouse_v2" ,
112- organizationId
113- ) ;
113+ const { repository : resolvedRepository } =
114+ await clickhouseFactory . getEventRepositoryForOrganization ( "clickhouse_v2" , organizationId ) ;
114115 return { repository : resolvedRepository , store : "clickhouse_v2" } ;
115116 } else if ( env . EVENT_REPOSITORY_DEFAULT_STORE === "clickhouse" ) {
116- const { repository : resolvedRepository } = await clickhouseFactory . getEventRepositoryForOrganization (
117- "clickhouse" ,
118- organizationId
119- ) ;
117+ const { repository : resolvedRepository } =
118+ await clickhouseFactory . getEventRepositoryForOrganization ( "clickhouse" , organizationId ) ;
120119 return { repository : resolvedRepository , store : "clickhouse" } ;
121120 } else {
122121 return { repository : eventRepository , store : getTaskEventStore ( ) } ;
@@ -206,10 +205,11 @@ async function recordRunEvent(
206205 } ;
207206 }
208207
209- const { repository : $eventRepository } = await clickhouseFactory . getEventRepositoryForOrganization (
210- foundRun . taskEventStore ,
211- foundRun . runtimeEnvironment . organizationId
212- ) ;
208+ const { repository : $eventRepository } =
209+ await clickhouseFactory . getEventRepositoryForOrganization (
210+ foundRun . taskEventStore ,
211+ foundRun . runtimeEnvironment . organizationId
212+ ) ;
213213
214214 const { attributes, startTime, ...optionsRest } = options ;
215215
0 commit comments