LSST Applications g00d0e8bbd7+edbf708997,g03191d30f7+9ce8016dbd,g1955dfad08+0bd186d245,g199a45376c+5137f08352,g1fd858c14a+a888a50aa2,g262e1987ae+45f9aba685,g29ae962dfc+1c7d47a24f,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3fd5ace14f+eed17d2c67,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+c4107e45b5,g67b6fd64d1+6dc8069a4c,g74acd417e5+f452e9c21a,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+2025e9ce17,g7cc15d900a+2d158402f9,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d4809ba88+c4107e45b5,g8d7436a09f+e96c132b44,g8ea07a8fe4+db21c37724,g98df359435+aae6d409c1,ga2180abaac+edbf708997,gac66b60396+966efe6077,gb632fb1845+88945a90f8,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gca7fc764a6+6dc8069a4c,gd7ef33dd92+6dc8069a4c,gda68eeecaf+7d1e613a8d,gdab6d2f7ff+f452e9c21a,gdbb4c4dda9+c4107e45b5,ge410e46f29+6dc8069a4c,ge41e95a9f2+c4107e45b5,geaed405ab2+e194be0d2b,w.2025.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
legacy_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
24from lsst.pex.config import ChoiceField, Field, ListField
25
26from .. import legacy_config
27from . import config
28
29
31 """Legacy APDB configuration class for SQL implementation (ApdbSql)."""
32
33 db_url = Field[str](doc="SQLAlchemy database connection URI")
34 isolation_level = ChoiceField[str](
35 doc=(
36 "Transaction isolation level, if unset then backend-default value "
37 "is used, except for SQLite backend where we use READ_UNCOMMITTED. "
38 "Some backends may not support every allowed value."
39 ),
40 allowed={
41 "READ_COMMITTED": "Read committed",
42 "READ_UNCOMMITTED": "Read uncommitted",
43 "REPEATABLE_READ": "Repeatable read",
44 "SERIALIZABLE": "Serializable",
45 },
46 default=None,
47 optional=True,
48 )
49 connection_pool = Field[bool](
50 doc="If False then disable SQLAlchemy connection pool. Do not use connection pool when forking.",
51 default=True,
52 )
53 connection_timeout = Field[float](
54 doc=(
55 "Maximum time to wait time for database lock to be released before exiting. "
56 "Defaults to sqlalchemy defaults if not set."
57 ),
58 default=None,
59 optional=True,
60 )
61 sql_echo = Field[bool](doc="If True then pass SQLAlchemy echo option.", default=False)
62 dia_object_index = ChoiceField[str](
63 doc="Indexing mode for DiaObject table",
64 allowed={
65 "baseline": "Index defined in baseline schema",
66 "pix_id_iov": "(pixelId, objectId, iovStart) PK",
67 "last_object_table": "Separate DiaObjectLast table",
68 },
69 default="baseline",
70 )
71 htm_level = Field[int](doc="HTM indexing level", default=20)
72 htm_max_ranges = Field[int](doc="Max number of ranges in HTM envelope", default=64)
73 htm_index_column = Field[str](
74 default="pixelId", doc="Name of a HTM index column for DiaObject and DiaSource tables"
75 )
76 ra_dec_columns = ListField[str](default=["ra", "dec"], doc="Names of ra/dec columns in DiaObject table")
77 dia_object_columns = ListField[str](
78 doc="List of columns to read from DiaObject, by default read all columns", default=[]
79 )
80 prefix = Field[str](doc="Prefix to add to table names and index names", default="")
81 namespace = Field[str](
82 doc=(
83 "Namespace or schema name for all tables in APDB database. "
84 "Presently only works for PostgreSQL backend. "
85 "If schema with this name does not exist it will be created when "
86 "APDB tables are created."
87 ),
88 default=None,
89 optional=True,
90 )
91 timer = Field[bool](doc="If True then print/log timing information", default=False)
92
93 def validate(self) -> None:
94 super().validate()
95 if len(self.ra_dec_columns) != 2:
96 raise ValueError("ra_dec_columns must have exactly two column names")
97
98 def to_model(self) -> config.ApdbSqlConfig:
99 # Docstring inherited from base class.
100 connection_config = config.ApdbSqlConnectionConfig(
101 isolation_level=self.isolation_level,
102 connection_pool=self.connection_pool,
103 connection_timeout=self.connection_timeout,
104 )
105 if self.sql_echo:
106 connection_config.extra_parameters["echo"] = self.sql_echo
107 pixelization_config = config.ApdbSqlPixelizationConfig(
108 htm_level=self.htm_level,
109 htm_max_ranges=self.htm_max_ranges,
110 htm_index_column=self.htm_index_column,
111 )
112 new_config = config.ApdbSqlConfig(
113 schema_file=self.schema_file,
114 schema_name=self.schema_name,
115 read_sources_months=self.read_sources_months,
116 read_forced_sources_months=self.read_forced_sources_months,
117 enable_replica=self.use_insert_id,
118 replica_chunk_seconds=self.replica_chunk_seconds,
119 db_url=self.db_url,
120 namespace=self.namespace,
121 connection_config=connection_config,
122 pixelization=pixelization_config,
123 dia_object_index=self.dia_object_index,
124 ra_dec_columns=(self.ra_dec_columns[0], self.ra_dec_columns[1]),
125 dia_object_columns=list(self.dia_object_columns),
126 prefix=self.prefix,
127 )
128 return new_config