1- import { ClickHouse } from "@internal/clickhouse" ;
2- import { Tracer } from "@internal/tracing" ;
3- import { Logger , LogLevel } from "@trigger.dev/core/logger" ;
4- import { TaskRunStatus } from "@trigger.dev/database" ;
5- import { PrismaClient } from "~/db.server" ;
1+ import { type ClickHouse } from "@internal/clickhouse" ;
2+ import { type Tracer } from "@internal/tracing" ;
3+ import { type Logger , type LogLevel } from "@trigger.dev/core/logger" ;
4+ import { type TaskRunStatus } from "@trigger.dev/database" ;
5+ import { type PrismaClient } from "~/db.server" ;
66
77export type RunsRepositoryOptions = {
88 clickhouse : ClickHouse ;
@@ -13,6 +13,7 @@ export type RunsRepositoryOptions = {
1313} ;
1414
1515export type ListRunsOptions = {
16+ organizationId : string ;
1617 projectId : string ;
1718 environmentId : string ;
1819 //filters
@@ -43,11 +44,14 @@ export class RunsRepository {
4344 async listRuns ( options : ListRunsOptions ) {
4445 const queryBuilder = this . options . clickhouse . taskRuns . queryBuilder ( ) ;
4546 queryBuilder
46- . where ( "environment_id = {environmentId : String}" , {
47- environmentId : options . environmentId ,
47+ . where ( "organization_id = {organizationId : String}" , {
48+ organizationId : options . organizationId ,
4849 } )
4950 . where ( "project_id = {projectId: String}" , {
5051 projectId : options . projectId ,
52+ } )
53+ . where ( "environment_id = {environmentId: String}" , {
54+ environmentId : options . environmentId ,
5155 } ) ;
5256
5357 if ( options . tasks && options . tasks . length > 0 ) {
@@ -115,17 +119,17 @@ export class RunsRepository {
115119 if ( options . page . direction === "forward" ) {
116120 queryBuilder
117121 . where ( "run_id < {runId: String}" , { runId : options . page . cursor } )
118- . orderBy ( "run_id DESC" )
122+ . orderBy ( "created_at DESC, run_id DESC" )
119123 . limit ( options . page . size + 1 ) ;
120124 } else {
121125 queryBuilder
122126 . where ( "run_id > {runId: String}" , { runId : options . page . cursor } )
123- . orderBy ( "run_id DESC" )
127+ . orderBy ( "created_at DESC, run_id DESC" )
124128 . limit ( options . page . size + 1 ) ;
125129 }
126130 } else {
127131 // Initial page - no cursor provided
128- queryBuilder . orderBy ( "run_id DESC" ) . limit ( options . page . size + 1 ) ;
132+ queryBuilder . orderBy ( "created_at DESC, run_id DESC" ) . limit ( options . page . size + 1 ) ;
129133 }
130134
131135 const [ queryError , result ] = await queryBuilder . execute ( ) ;
0 commit comments