Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0fba68d861+83433b07ee,g16d25e1f1b+23bc9e47ac,g1ec0fe41b4+3ea9d11450,g1fd858c14a+9be2b0f3b9,g2440f9efcc+8c5ae1fdc5,g35bb328faa+8c5ae1fdc5,g4a4af6cd76+d25431c27e,g4d2262a081+c74e83464e,g53246c7159+8c5ae1fdc5,g55585698de+1e04e59700,g56a49b3a55+92a7603e7a,g60b5630c4e+1e04e59700,g67b6fd64d1+3fc8cb0b9e,g78460c75b0+7e33a9eb6d,g786e29fd12+668abc6043,g8352419a5c+8c5ae1fdc5,g8852436030+60e38ee5ff,g89139ef638+3fc8cb0b9e,g94187f82dc+1e04e59700,g989de1cb63+3fc8cb0b9e,g9d31334357+1e04e59700,g9f33ca652e+0a83e03614,gabe3b4be73+8856018cbb,gabf8522325+977d9fabaf,gb1101e3267+8b4b9c8ed7,gb89ab40317+3fc8cb0b9e,gc0af124501+57ccba3ad1,gcf25f946ba+60e38ee5ff,gd6cbbdb0b4+1cc2750d2e,gd794735e4e+7be992507c,gdb1c4ca869+be65c9c1d7,gde0f65d7ad+c7f52e58fe,ge278dab8ac+6b863515ed,ge410e46f29+3fc8cb0b9e,gf35d7ec915+97dd712d81,gf5e32f922b+8c5ae1fdc5,gf618743f1b+747388abfa,gf67bdafdda+3fc8cb0b9e,w.2025.18
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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