LSST Applications 29.0.1,g0fba68d861+132dd21e0a,g107a963962+1bb9f809a9,g1fd858c14a+005be21cae,g21d47ad084+8a07b29876,g325378336f+5d73323c8f,g330003fc43+40b4eaffc6,g35bb328faa+fcb1d3bbc8,g36ff55ed5b+9c28a42a87,g4e0f332c67+5fbd1e3e73,g53246c7159+fcb1d3bbc8,g60b5630c4e+9c28a42a87,g67b6fd64d1+a38b34ea13,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g86c591e316+6b2b2d0295,g8852436030+bf14db0e33,g89139ef638+a38b34ea13,g8b8da53e10+e3777245af,g9125e01d80+fcb1d3bbc8,g989de1cb63+a38b34ea13,g9f1445be69+9c28a42a87,g9f33ca652e+52c8f07962,ga9baa6287d+9c28a42a87,ga9e4eb89a6+9f84bd6575,gabe3b4be73+1e0a283bba,gb037a4e798+f3cbcd26c0,gb1101e3267+e7be8da0f8,gb58c049af0+f03b321e39,gb89ab40317+a38b34ea13,gcf25f946ba+bf14db0e33,gd6cbbdb0b4+bce7f7457e,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+53d424b1ae,ge278dab8ac+222406d50a,ge410e46f29+a38b34ea13,ge80e9994a3+664d6357dc,gf67bdafdda+a38b34ea13
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