Get all tenant IDs that have tenant configurations, sorted by creation time descending (newest first). Returns: List[str]: List of tenant IDs sorted by creation time (newest first)
()
| 141 | |
| 142 | |
| 143 | def get_all_tenant_ids(): |
| 144 | """ |
| 145 | Get all tenant IDs that have tenant configurations, sorted by creation time descending (newest first). |
| 146 | |
| 147 | Returns: |
| 148 | List[str]: List of tenant IDs sorted by creation time (newest first) |
| 149 | """ |
| 150 | with get_db_session() as session: |
| 151 | # Query tenant_ids grouped by tenant_id, ordered by maximum create_time (newest config creation) |
| 152 | result = session.query( |
| 153 | TenantConfig.tenant_id, |
| 154 | func.max(TenantConfig.create_time).label("max_create_time") |
| 155 | ).filter( |
| 156 | TenantConfig.delete_flag == "N" |
| 157 | ).group_by( |
| 158 | TenantConfig.tenant_id |
| 159 | ).order_by( |
| 160 | func.max(TenantConfig.create_time).desc() |
| 161 | ).all() |
| 162 | |
| 163 | return [row[0] for row in result] |