LSST Applications g013ef56533+9b09c56ab3,g083dd6704c+a047e97985,g199a45376c+0ba108daf9,g19c4beb06c+f87d968cda,g1fd858c14a+0ebb8fe952,g210f2d0738+989426243d,g262e1987ae+b51a336e7c,g29ae962dfc+97650ea04b,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+deda572d24,g47891489e3+f459a6810c,g511e8cfd20+b3c771ffa5,g53246c7159+8c5ae1fdc5,g54cd7ddccb+890c8e1e5d,g5fd55ab2c7+7caddb52a2,g64539dfbff+989426243d,g67b6fd64d1+f459a6810c,g74acd417e5+866715c704,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+f459a6810c,g8c0b9db444+5bcd39efc6,g8d7436a09f+38cd1e2ebb,g8ea07a8fe4+81eaaadc04,g90f42f885a+34c0557caf,g9486f8a5af+4ba9141ddb,g97be763408+c9d9d08df4,gbf99507273+8c5ae1fdc5,gc2a301910b+989426243d,gca7fc764a6+f459a6810c,gd7ef33dd92+f459a6810c,gdab6d2f7ff+866715c704,ge410e46f29+f459a6810c,ge41e95a9f2+989426243d,geaed405ab2+e3b4b2a692,gf2b17d7741+8c5ae1fdc5,gf9a733ac38+8c5ae1fdc5,w.2025.42
LSST Data Management Base Package
Loading...
Searching...
No Matches
config.py
Go to the documentation of this file.
1# This file is part of dax_apdb.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22from __future__ import annotations
23
24__all__ = ["ApdbSqlConfig", "ApdbSqlConnectionConfig", "ApdbSqlPixelizationConfig"]
25
26from collections.abc import Iterable
27from typing import Any, ClassVar
28
29from pydantic import BaseModel, Field, field_validator
30
31from ..config import ApdbConfig
32
33
34class ApdbSqlConnectionConfig(BaseModel):
35 """Configuration of connection parameters."""
36
37 isolation_level: str | None = Field(
38 default=None,
39 description=(
40 "Transaction isolation level, if unset then backend-default value "
41 "is used, except for SQLite backend where we use READ_UNCOMMITTED. "
42 "Some backends may not support every allowed value."
43 ),
44 )
45
46 connection_pool: bool = Field(
47 default=True,
48 description=(
49 "If False then disable SQLAlchemy connection pool. Do not use connection pool when forking."
50 ),
51 )
52
53 connection_timeout: float | None = Field(
54 default=None,
55 description=(
56 "Maximum time to wait time for database lock to be released before "
57 "exiting. Defaults to sqlalchemy defaults if not set."
58 ),
59 )
60
61 extra_parameters: dict[str, Any] = Field(
62 default={}, description="Additional keyword parameters passed to connect() method verbatim."
63 )
64
65 @field_validator("isolation_level")
66 @classmethod
67 def check_isolation_level(cls, v: str) -> str:
68 allowed = {None, "READ_COMMITTED", "READ_UNCOMMITTED", "REPEATABLE_READ", "SERIALIZABLE"}
69 if v not in allowed:
70 raise ValueError(f"Unexpected value for isolation_level: {v}, allowed values: {allowed}")
71 return v
72
73
75 """Pixelization configuration for SQL-based APDB."""
76
77 htm_level: int = Field(
78 default=20,
79 description="HTM indexing level",
80 )
81
82 htm_max_ranges: int = Field(
83 default=64,
84 description="Max number of ranges in HTM envelope",
85 )
86
87 htm_index_column: str = Field(
88 default="pixelId",
89 description="Name of a HTM index column for DiaObject and DiaSource tables",
90 )
91
92
94 """APDB configuration class for SQL implementation (ApdbSql)."""
95
96 _implementation_type: ClassVar[str] = "sql"
97
98 db_url: str = Field(description="SQLAlchemy database connection URI.")
99
100 namespace: str | None = Field(
101 default=None,
102 description=(
103 "Namespace or schema name for all tables in APDB database. "
104 "Presently only works for PostgreSQL backend. If schema with this name does "
105 "not exist it will be created when APDB tables are created."
106 ),
107 )
108
109 connection_config: ApdbSqlConnectionConfig = Field(
110 default_factory=ApdbSqlConnectionConfig,
111 description="Database connection configuration",
112 )
113
114 pixelization: ApdbSqlPixelizationConfig = Field(
115 default_factory=ApdbSqlPixelizationConfig,
116 description="Configuration for pixelization.",
117 )
118
119 dia_object_index: str = Field(
120 default="baseline",
121 description=(
122 'Indexing mode for DiaObject table. Allowed value is one of "baseline", '
123 '"pix_id_iov", or "last_object_table".'
124 ),
125 )
126
127 ra_dec_columns: tuple[str, str] = Field(
128 default=("ra", "dec"),
129 description="Names of ra/dec columns in DiaObject table.",
130 )
131
132 dia_object_columns: list[str] = Field(
133 default=[],
134 description="List of columns to read from DiaObject, by default read all columns",
135 )
136
137 prefix: str = Field(
138 default="",
139 description="Prefix to add to table names and index names.",
140 )
141
142 @field_validator("ra_dec_columns")
143 @classmethod
144 def check_ra_dec(cls, v: Iterable[str]) -> tuple[str, str]:
145 # This validation method is needed in case we initialize model from
146 # JSON in strict mode, in that mode JSON list is rejected by default.
147 vtup = tuple(v)
148 if len(vtup) != 2:
149 raise ValueError("ra_dec_columns must have exactly two column names")
150 return vtup
151
152 @field_validator("dia_object_index")
153 @classmethod
154 def check_dia_object_index(cls, v: str) -> str:
155 allowed = {"baseline", "pix_id_iov", "last_object_table"}
156 if v not in allowed:
157 raise ValueError(f"Unexpected value for dia_object_index: {v}, allowed values: {allowed}")
158 return v
tuple[str, str] check_ra_dec(cls, Iterable[str] v)
Definition config.py:144