0
# Database Models
1
2
ORM models for DAGs, tasks, runs, connections, and metadata storage with SQLAlchemy integration. These models represent Airflow's database schema and provide programmatic access to workflow metadata.
3
4
## Capabilities
5
6
### Core Database Models
7
8
Base ORM models and database configuration.
9
10
```python { .api }
11
class Base:
12
"""SQLAlchemy base class for all Airflow models."""
13
14
__tablename__: str
15
__table_args__: Dict[str, Any]
16
17
ID_LEN: int = 250 # Standard ID field length
18
19
class DagModel(Base):
20
"""ORM model for DAG metadata."""
21
22
dag_id: str
23
is_active: bool
24
is_paused: bool
25
last_parsed_time: Optional[datetime]
26
last_pickled: Optional[datetime]
27
last_expired: Optional[datetime]
28
scheduler_lock: Optional[bool]
29
pickle_id: Optional[int]
30
fileloc: str
31
owners: str
32
description: Optional[str]
33
default_view: str
34
schedule_interval: Optional[str]
35
tags: List[str]
36
```
37
38
### Task and Run Models
39
40
Models for task instances and DAG runs.
41
42
```python { .api }
43
class TaskInstance(Base):
44
"""ORM model for task instance execution."""
45
46
task_id: str
47
dag_id: str
48
run_id: str
49
execution_date: datetime
50
start_date: Optional[datetime]
51
end_date: Optional[datetime]
52
duration: Optional[float]
53
state: Optional[str]
54
try_number: int
55
max_tries: int
56
hostname: str
57
unixname: str
58
job_id: Optional[int]
59
pool: str
60
pool_slots: int
61
queue: str
62
priority_weight: int
63
operator: str
64
queued_dttm: Optional[datetime]
65
pid: Optional[int]
66
executor_config: Optional[Dict]
67
68
class DagRun(Base):
69
"""ORM model for DAG run instances."""
70
71
dag_id: str
72
execution_date: datetime
73
run_id: str
74
state: str
75
run_type: str
76
external_trigger: bool
77
start_date: Optional[datetime]
78
end_date: Optional[datetime]
79
creating_job_id: Optional[int]
80
```
81
82
### Resource and Configuration Models
83
84
Models for resource pools, connections, and variables.
85
86
```python { .api }
87
class Pool(Base):
88
"""ORM model for resource pools."""
89
90
pool: str
91
slots: int
92
description: str
93
94
class Connection(Base):
95
"""ORM model for connection configurations."""
96
97
conn_id: str
98
conn_type: str
99
description: Optional[str]
100
host: Optional[str]
101
schema: Optional[str]
102
login: Optional[str]
103
password: Optional[str]
104
port: Optional[int]
105
extra: Optional[str]
106
107
class Variable(Base):
108
"""ORM model for Airflow variables."""
109
110
key: str
111
val: Optional[str]
112
description: Optional[str]
113
is_encrypted: bool
114
```
115
116
## Types
117
118
```python { .api }
119
from typing import Optional, Dict, Any, List
120
from datetime import datetime
121
from sqlalchemy.ext.declarative import declarative_base
122
123
ModelType = type[Base]
124
```