Coverage for python / lsst / dax / apdb / sql / legacy_config.py: 0%

30 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-25 08:20 +0000

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 

30class ApdbSqlConfig(legacy_config.ApdbConfig): 

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