missing_dag_ids = dag_ids.difference(existing_dags)
        for missing_dag_id in missing_dag_ids:
            orm_dag = DagModel(dag_id=missing_dag_id)
            dag = dag_by_ids[missing_dag_id]
            if dag.is_paused_upon_creation is not None:
                orm_dag.is_paused = dag.is_paused_upon_creation
            orm_dag.tags = []
            log.info("Creating ORM DAG for %s", dag.dag_id)
            session.add(orm_dag)
            orm_dags.append(orm_dag)
        
        most_recent_subq = (
            session.query(DagRun.dag_id, func.max(DagRun.execution_date).label("max_execution_date"))
            .filter(
                DagRun.dag_id.in_(existing_dags),
                or_(DagRun.run_type == DagRunType.BACKFILL_JOB, DagRun.run_type == DagRunType.SCHEDULED),
            )
            .group_by(DagRun.dag_id)
            .subquery()
        )
        most_recent_runs_iter = session.query(DagRun).filter(
            DagRun.dag_id == most_recent_subq.c.dag_id,
            DagRun.execution_date == most_recent_subq.c.max_execution_date,
        )
        most_recent_runs = {run.dag_id: run for run in most_recent_runs_iter}
        
        num_active_runs = DagRun.active_runs_of_dags(dag_ids=existing_dags, session=session)
        filelocs = []
        for orm_dag in sorted(orm_dags, key=lambda d: d.dag_id):
            dag = dag_by_ids[orm_dag.dag_id]