LSST Applications g0265f82a02+d6b5cd48b5,g02d81e74bb+80768bd682,g04242d3e92+8eaa23c173,g06b2ea86fd+734f9505a2,g2079a07aa2+14824f138e,g212a7c68fe+5f4fc2ea00,g2305ad1205+293ab1327e,g2bbee38e9b+d6b5cd48b5,g337abbeb29+d6b5cd48b5,g3ddfee87b4+8eaa23c173,g487adcacf7+abec5a19c5,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+97ef3b4495,g5a732f18d5+66d966b544,g5d7b63bc56+636c3c3fd8,g64a986408d+80768bd682,g858d7b2824+80768bd682,g8a8a8dda67+a6fc98d2e7,g99cad8db69+6282a5f541,g9ddcbc5298+d4bad12328,ga1e77700b3+246acaaf9c,ga8c6da7877+9e3c062e8e,gb0e22166c9+3863383f4c,gb6a65358fc+d6b5cd48b5,gba4ed39666+9664299f35,gbb8dafda3b+60f904e7bc,gc120e1dc64+1bf26d0180,gc28159a63d+d6b5cd48b5,gcf0d15dbbd+8eaa23c173,gd2a12a3803+f8351bc914,gdaeeff99f8+a38ce5ea23,ge79ae78c31+d6b5cd48b5,gee10cc3b42+a6fc98d2e7,gf1cff7945b+80768bd682,v24.1.5.rc1
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema Class Reference
Inheritance diagram for lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema:
lsst.dax.apdb.apdbSchema.ApdbSchema

Public Member Functions

 __init__ (self, sqlalchemy.engine.Engine engine, str dia_object_index, str htm_index_column, str schema_file, str schema_name="ApdbSchema", str prefix="", str|None namespace=None, bool use_insert_id=False)
 
bool empty (self)
 
None makeSchema (self, bool drop=False)
 
Table get_table (self, ApdbTables|ExtraTables table_enum)
 
list[Column] get_apdb_columns (self, ApdbTables|ExtraTables table_enum)
 
bool has_insert_id (self)
 

Static Public Attributes

tuple pixel_id_tables = (ApdbTables.DiaObject, ApdbTables.DiaObjectLast, ApdbTables.DiaSource)
 

Protected Member Functions

bool _check_insert_id (self)
 
Mapping[ApdbTables, Table] _make_apdb_tables (self, str mysql_engine="InnoDB")
 
Mapping[ExtraTables, Table] _make_extra_tables (self, Mapping[ApdbTables, Table] apdb_tables, str mysql_engine="InnoDB")
 
list[Column] _tableColumns (self, ApdbTables table_name)
 
list[sqlalchemy.schema.SchemaItem] _tableIndices (self, ApdbTables table_name)
 
list[Column] _insertIdColumns (self, ExtraTables table_enum)
 
list[Column] _tablePkColumns (self, ApdbTables table_enum)
 
list[sqlalchemy.schema.SchemaItem] _insertIdIndices (self, ExtraTables table_enum, sqlalchemy.schema.Table apdb_table, sqlalchemy.schema.Table parent_table)
 
type|sqlalchemy.types.TypeEngine _getDoubleType (cls, sqlalchemy.engine.Engine engine)
 

Protected Attributes

 _engine
 
 _dia_object_index
 
 _htm_index_column
 
 _prefix
 
 _use_insert_id
 
 _metadata
 
 _type_map
 
 _apdb_tables
 
 _extra_tables
 
 _has_insert_id
 
 _metadata_check
 

Detailed Description

Class for management of APDB schema.

Attributes
----------
objects : `sqlalchemy.Table`
    DiaObject table instance
objects_last : `sqlalchemy.Table`
    DiaObjectLast table instance, may be None
sources : `sqlalchemy.Table`
    DiaSource table instance
forcedSources : `sqlalchemy.Table`
    DiaForcedSource table instance
has_insert_id : `bool`
    If true then schema has tables for insert ID tracking.

Parameters
----------
engine : `sqlalchemy.engine.Engine`
    SQLAlchemy engine instance
dia_object_index : `str`
    Indexing mode for DiaObject table, see `ApdbSqlConfig.dia_object_index`
    for details.
htm_index_column : `str`
    Name of a HTM index column for DiaObject and DiaSource tables.
schema_file : `str`
    Name of the YAML schema file.
schema_name : `str`, optional
    Name of the schema in YAML files.
prefix : `str`, optional
    Prefix to add to all schema elements.
namespace : `str`, optional
    Namespace (or schema name) to use for all APDB tables.
use_insert_id : `bool`, optional

Definition at line 146 of file apdbSqlSchema.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema.__init__ ( self,
sqlalchemy.engine.Engine engine,
str dia_object_index,
str htm_index_column,
str schema_file,
str schema_name = "ApdbSchema",
str prefix = "",
str | None namespace = None,
bool use_insert_id = False )

Reimplemented from lsst.dax.apdb.apdbSchema.ApdbSchema.

Definition at line 186 of file apdbSqlSchema.py.

196 ):
197 super().__init__(schema_file, schema_name)
198
199 self._engine = engine
200 self._dia_object_index = dia_object_index
201 self._htm_index_column = htm_index_column
202 self._prefix = prefix
203 self._use_insert_id = use_insert_id
204
205 self._metadata = MetaData(schema=namespace)
206
207 # map YAML column types to SQLAlchemy
208 self._type_map = {
209 felis.types.Double: self._getDoubleType(engine),
210 felis.types.Float: sqlalchemy.types.Float,
211 felis.types.Timestamp: sqlalchemy.types.TIMESTAMP,
212 felis.types.Long: sqlalchemy.types.BigInteger,
213 felis.types.Int: sqlalchemy.types.Integer,
214 felis.types.Short: sqlalchemy.types.Integer,
215 felis.types.Byte: sqlalchemy.types.Integer,
216 felis.types.Binary: sqlalchemy.types.LargeBinary,
217 felis.types.Text: sqlalchemy.types.Text,
218 felis.types.String: sqlalchemy.types.CHAR,
219 felis.types.Char: sqlalchemy.types.CHAR,
220 felis.types.Unicode: sqlalchemy.types.CHAR,
221 felis.types.Boolean: sqlalchemy.types.Boolean,
222 }
223
224 # Add pixelId column and index to tables that need it
225 for table in self.pixel_id_tables:
226 tableDef = self.tableSchemas.get(table)
227 if not tableDef:
228 continue
229 column = simple.Column(
230 id=f"#{htm_index_column}",
231 name=htm_index_column,
232 datatype=felis.types.Long,
233 nullable=False,
234 value=None,
235 description="Pixelization index column.",
236 table=tableDef,
237 )
238 tableDef.columns.append(column)
239
240 # Adjust index if needed
241 if table == ApdbTables.DiaObject and self._dia_object_index == "pix_id_iov":
242 tableDef.primary_key.insert(0, column)
243
244 if table is ApdbTables.DiaObjectLast:
245 # use it as a leading PK column
246 tableDef.primary_key.insert(0, column)
247 else:
248 # make a regular index
249 name = f"IDX_{tableDef.name}_{htm_index_column}"
250 index = simple.Index(id=f"#{name}", name=name, columns=[column])
251 tableDef.indexes.append(index)
252
253 # generate schema for all tables, must be called last
254 self._apdb_tables = self._make_apdb_tables()
255 self._extra_tables = self._make_extra_tables(self._apdb_tables)
256
257 self._has_insert_id: bool | None = None
258 self._metadata_check: bool | None = None
259

Member Function Documentation

◆ _check_insert_id()

bool lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._check_insert_id ( self)
protected
Check whether database has tables for tracking insert IDs.

Definition at line 396 of file apdbSqlSchema.py.

396 def _check_insert_id(self) -> bool:
397 """Check whether database has tables for tracking insert IDs."""
398 inspector = inspect(self._engine)
399 db_tables = set(inspector.get_table_names(schema=self._metadata.schema))
400 return ExtraTables.DiaInsertId.table_name(self._prefix) in db_tables
401
daf::base::PropertySet * set
Definition fits.cc:931

◆ _getDoubleType()

type | sqlalchemy.types.TypeEngine lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._getDoubleType ( cls,
sqlalchemy.engine.Engine engine )
protected
DOUBLE type is database-specific, select one based on dialect.

Parameters
----------
engine : `sqlalchemy.engine.Engine`
    Database engine.

Returns
-------
type_object : `object`
    Database-specific type definition.

Definition at line 585 of file apdbSqlSchema.py.

585 def _getDoubleType(cls, engine: sqlalchemy.engine.Engine) -> type | sqlalchemy.types.TypeEngine:
586 """DOUBLE type is database-specific, select one based on dialect.
587
588 Parameters
589 ----------
590 engine : `sqlalchemy.engine.Engine`
591 Database engine.
592
593 Returns
594 -------
595 type_object : `object`
596 Database-specific type definition.
597 """
598 if engine.name == "mysql":
599 from sqlalchemy.dialects.mysql import DOUBLE
600
601 return DOUBLE(asdecimal=False)
602 elif engine.name == "postgresql":
603 from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION
604
605 return DOUBLE_PRECISION
606 elif engine.name == "oracle":
607 from sqlalchemy.dialects.oracle import DOUBLE_PRECISION
608
609 return DOUBLE_PRECISION
610 elif engine.name == "sqlite":
611 # all floats in sqlite are 8-byte
612 from sqlalchemy.dialects.sqlite import REAL
613
614 return REAL
615 else:
616 raise TypeError("cannot determine DOUBLE type, unexpected dialect: " + engine.name)

◆ _insertIdColumns()

list[Column] lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._insertIdColumns ( self,
ExtraTables table_enum )
protected
Return list of columns for insert ID tables.

Definition at line 532 of file apdbSqlSchema.py.

532 def _insertIdColumns(self, table_enum: ExtraTables) -> list[Column]:
533 """Return list of columns for insert ID tables."""
534 column_defs: list[Column] = [Column("insert_id", GUID, nullable=False)]
535 insert_id_tables = ExtraTables.insert_id_tables()
536 if table_enum in insert_id_tables:
537 column_defs += self._tablePkColumns(insert_id_tables[table_enum])
538 else:
539 assert False, "Above branches have to cover all enum values"
540 return column_defs
541

◆ _insertIdIndices()

list[sqlalchemy.schema.SchemaItem] lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._insertIdIndices ( self,
ExtraTables table_enum,
sqlalchemy.schema.Table apdb_table,
sqlalchemy.schema.Table parent_table )
protected
Return set of constraints/indices for insert ID tables.

Definition at line 551 of file apdbSqlSchema.py.

556 ) -> list[sqlalchemy.schema.SchemaItem]:
557 """Return set of constraints/indices for insert ID tables."""
558 index_defs: list[sqlalchemy.schema.SchemaItem] = []
559
560 # Special case for insert ID tables that are not in felis schema.
561 insert_id_tables = ExtraTables.insert_id_tables()
562 if table_enum in insert_id_tables:
563 # PK is the same as for original table
564 pk_names = [column.name for column in self._tablePkColumns(insert_id_tables[table_enum])]
565 index_defs.append(PrimaryKeyConstraint(*pk_names))
566 # Non-unique index on insert_id column.
567 name = self._prefix + table_enum.name + "_idx"
568 index_defs.append(Index(name, "insert_id"))
569 # Foreign key to original table
570 pk_columns = [apdb_table.columns[column] for column in pk_names]
571 index_defs.append(
572 ForeignKeyConstraint(pk_names, pk_columns, onupdate="CASCADE", ondelete="CASCADE")
573 )
574 # Foreign key to parent table
575 index_defs.append(
576 ForeignKeyConstraint(
577 ["insert_id"], [parent_table.columns["insert_id"]], onupdate="CASCADE", ondelete="CASCADE"
578 )
579 )
580 else:
581 assert False, "Above branches have to cover all enum values"
582 return index_defs
583

◆ _make_apdb_tables()

Mapping[ApdbTables, Table] lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._make_apdb_tables ( self,
str mysql_engine = "InnoDB" )
protected
Generate schema for regular tables.

Parameters
----------
mysql_engine : `str`, optional
    MySQL engine type to use for new tables.

Definition at line 402 of file apdbSqlSchema.py.

402 def _make_apdb_tables(self, mysql_engine: str = "InnoDB") -> Mapping[ApdbTables, Table]:
403 """Generate schema for regular tables.
404
405 Parameters
406 ----------
407 mysql_engine : `str`, optional
408 MySQL engine type to use for new tables.
409 """
410 tables = {}
411 for table_enum in ApdbTables:
412 if table_enum is ApdbTables.DiaObjectLast and self._dia_object_index != "last_object_table":
413 continue
414 if table_enum is ApdbTables.metadata and table_enum not in self.tableSchemas:
415 # Schema does not define metadata.
416 continue
417
418 columns = self._tableColumns(table_enum)
419 constraints = self._tableIndices(table_enum)
420 table = Table(
421 table_enum.table_name(self._prefix),
422 self._metadata,
423 *columns,
424 *constraints,
425 mysql_engine=mysql_engine,
426 )
427 tables[table_enum] = table
428
429 return tables
430

◆ _make_extra_tables()

Mapping[ExtraTables, Table] lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._make_extra_tables ( self,
Mapping[ApdbTables, Table] apdb_tables,
str mysql_engine = "InnoDB" )
protected
Generate schema for insert ID tables.

Definition at line 431 of file apdbSqlSchema.py.

433 ) -> Mapping[ExtraTables, Table]:
434 """Generate schema for insert ID tables."""
435 tables: dict[ExtraTables, Table] = {}
436 if not self._use_insert_id:
437 return tables
438
439 # Parent table needs to be defined first
440 column_defs = [
441 Column("insert_id", GUID, primary_key=True),
442 Column("insert_time", sqlalchemy.types.TIMESTAMP, nullable=False),
443 ]
444 parent_table = Table(
445 ExtraTables.DiaInsertId.table_name(self._prefix),
446 self._metadata,
447 *column_defs,
448 mysql_engine=mysql_engine,
449 )
450 tables[ExtraTables.DiaInsertId] = parent_table
451
452 for table_enum, apdb_enum in ExtraTables.insert_id_tables().items():
453 apdb_table = apdb_tables[apdb_enum]
454 columns = self._insertIdColumns(table_enum)
455 constraints = self._insertIdIndices(table_enum, apdb_table, parent_table)
456 table = Table(
457 table_enum.table_name(self._prefix),
458 self._metadata,
459 *columns,
460 *constraints,
461 mysql_engine=mysql_engine,
462 )
463 tables[table_enum] = table
464
465 return tables
466
std::vector< SchemaItem< Flag > > * items

◆ _tableColumns()

list[Column] lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._tableColumns ( self,
ApdbTables table_name )
protected
Return set of columns in a table

Parameters
----------
table_name : `ApdbTables`
    Name of the table.

Returns
-------
column_defs : `list`
    List of `Column` objects.

Definition at line 467 of file apdbSqlSchema.py.

467 def _tableColumns(self, table_name: ApdbTables) -> list[Column]:
468 """Return set of columns in a table
469
470 Parameters
471 ----------
472 table_name : `ApdbTables`
473 Name of the table.
474
475 Returns
476 -------
477 column_defs : `list`
478 List of `Column` objects.
479 """
480 # get the list of columns in primary key, they are treated somewhat
481 # specially below
482 table_schema = self.tableSchemas[table_name]
483
484 # convert all column dicts into alchemy Columns
485 column_defs: list[Column] = []
486 for column in table_schema.columns:
487 kwargs: dict[str, Any] = dict(nullable=column.nullable)
488 if column.value is not None:
489 kwargs.update(server_default=str(column.value))
490 if column in table_schema.primary_key:
491 kwargs.update(autoincrement=False)
492 ctype = self._type_map[column.datatype]
493 column_defs.append(Column(column.name, ctype, **kwargs))
494
495 return column_defs
496

◆ _tableIndices()

list[sqlalchemy.schema.SchemaItem] lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._tableIndices ( self,
ApdbTables table_name )
protected
Return set of constraints/indices in a table

Parameters
----------
table_name : `ApdbTables`
    Name of the table.
info : `dict`
    Additional options passed to SQLAlchemy index constructor.

Returns
-------
index_defs : `list`
    List of SQLAlchemy index/constraint objects.

Definition at line 497 of file apdbSqlSchema.py.

497 def _tableIndices(self, table_name: ApdbTables) -> list[sqlalchemy.schema.SchemaItem]:
498 """Return set of constraints/indices in a table
499
500 Parameters
501 ----------
502 table_name : `ApdbTables`
503 Name of the table.
504 info : `dict`
505 Additional options passed to SQLAlchemy index constructor.
506
507 Returns
508 -------
509 index_defs : `list`
510 List of SQLAlchemy index/constraint objects.
511 """
512 table_schema = self.tableSchemas[table_name]
513
514 # convert all index dicts into alchemy Columns
515 index_defs: list[sqlalchemy.schema.SchemaItem] = []
516 if table_schema.primary_key:
517 index_defs.append(PrimaryKeyConstraint(*[column.name for column in table_schema.primary_key]))
518 for index in table_schema.indexes:
519 name = self._prefix + index.name if index.name else ""
520 index_defs.append(Index(name, *[column.name for column in index.columns]))
521 for constraint in table_schema.constraints:
522 constr_name: str | None = None
523 if constraint.name:
524 constr_name = self._prefix + constraint.name
525 if isinstance(constraint, simple.UniqueConstraint):
526 index_defs.append(
527 UniqueConstraint(*[column.name for column in constraint.columns], name=constr_name)
528 )
529
530 return index_defs
531

◆ _tablePkColumns()

list[Column] lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._tablePkColumns ( self,
ApdbTables table_enum )
protected
Return a list of columns for table PK.

Definition at line 542 of file apdbSqlSchema.py.

542 def _tablePkColumns(self, table_enum: ApdbTables) -> list[Column]:
543 """Return a list of columns for table PK."""
544 table_schema = self.tableSchemas[table_enum]
545 column_defs: list[Column] = []
546 for column in table_schema.primary_key:
547 ctype = self._type_map[column.datatype]
548 column_defs.append(Column(column.name, ctype, nullable=False, autoincrement=False))
549 return column_defs
550

◆ empty()

bool lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema.empty ( self)
Return True if database schema is empty.

Returns
-------
empty : `bool`
    `True` if none of the required APDB tables exist in the database,
    `False` if all required tables exist.

Raises
------
InconsistentSchemaError
    Raised when some of the required tables exist but not all.

Definition at line 260 of file apdbSqlSchema.py.

260 def empty(self) -> bool:
261 """Return True if database schema is empty.
262
263 Returns
264 -------
265 empty : `bool`
266 `True` if none of the required APDB tables exist in the database,
267 `False` if all required tables exist.
268
269 Raises
270 ------
271 InconsistentSchemaError
272 Raised when some of the required tables exist but not all.
273 """
274 inspector = inspect(self._engine)
275 table_names = set(inspector.get_table_names(self._metadata.schema))
276
277 existing_tables = []
278 missing_tables = []
279 for table_enum in self._apdb_tables:
280 table_name = table_enum.table_name(self._prefix)
281 if table_name in table_names:
282 existing_tables.append(table_name)
283 else:
284 missing_tables.append(table_name)
285
286 if not missing_tables:
287 return False
288 elif not existing_tables:
289 return True
290 else:
291 raise InconsistentSchemaError(
292 f"Only some required APDB tables exist: {existing_tables}, missing tables: {missing_tables}"
293 )
294

◆ get_apdb_columns()

list[Column] lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema.get_apdb_columns ( self,
ApdbTables | ExtraTables table_enum )
Return list of columns defined for a table in APDB schema.

Returned list excludes columns that are implementation-specific, e.g.
``pixelId`` column is not include in the returned list.

Parameters
----------
table_enum : `ApdbTables` or `ExtraTables`
    Type of table.

Returns
-------
table : `list` [`sqlalchemy.schema.Column`]
    Table instance.

Raises
------
ValueError
    Raised if ``table_enum`` is not valid for this database.

Definition at line 362 of file apdbSqlSchema.py.

362 def get_apdb_columns(self, table_enum: ApdbTables | ExtraTables) -> list[Column]:
363 """Return list of columns defined for a table in APDB schema.
364
365 Returned list excludes columns that are implementation-specific, e.g.
366 ``pixelId`` column is not include in the returned list.
367
368 Parameters
369 ----------
370 table_enum : `ApdbTables` or `ExtraTables`
371 Type of table.
372
373 Returns
374 -------
375 table : `list` [`sqlalchemy.schema.Column`]
376 Table instance.
377
378 Raises
379 ------
380 ValueError
381 Raised if ``table_enum`` is not valid for this database.
382 """
383 table = self.get_table(table_enum)
384 exclude_columns = set()
385 if table_enum in self.pixel_id_tables:
386 exclude_columns.add(self._htm_index_column)
387 return [column for column in table.columns if column.name not in exclude_columns]
388

◆ get_table()

Table lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema.get_table ( self,
ApdbTables | ExtraTables table_enum )
Return SQLAlchemy table instance for a specified table type/enum.

Parameters
----------
table_enum : `ApdbTables` or `ExtraTables`
    Type of table to return.

Returns
-------
table : `sqlalchemy.schema.Table`
    Table instance.

Raises
------
ValueError
    Raised if ``table_enum`` is not valid for this database.

Definition at line 324 of file apdbSqlSchema.py.

324 def get_table(self, table_enum: ApdbTables | ExtraTables) -> Table:
325 """Return SQLAlchemy table instance for a specified table type/enum.
326
327 Parameters
328 ----------
329 table_enum : `ApdbTables` or `ExtraTables`
330 Type of table to return.
331
332 Returns
333 -------
334 table : `sqlalchemy.schema.Table`
335 Table instance.
336
337 Raises
338 ------
339 ValueError
340 Raised if ``table_enum`` is not valid for this database.
341 """
342 try:
343 if isinstance(table_enum, ApdbTables):
344 if table_enum is ApdbTables.metadata:
345 # There may be cases when schema is configured with the
346 # metadata table but database is still missing it. Check
347 # that table actually exists in the database. Note that
348 # this may interact with `makeSchema`.
349 if self._metadata_check is None:
350 inspector = inspect(self._engine)
351 table_name = table_enum.table_name(self._prefix)
352 self._metadata_check = inspector.has_table(table_name, schema=self._metadata.schema)
353 if not self._metadata_check:
354 # this will be caught below
355 raise LookupError("metadata table is missing")
356 return self._apdb_tables[table_enum]
357 else:
358 return self._extra_tables[table_enum]
359 except LookupError:
360 raise ValueError(f"Table type {table_enum} does not exist in the schema") from None
361

◆ has_insert_id()

bool lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema.has_insert_id ( self)
Whether insert ID tables are to be used (`bool`).

Definition at line 390 of file apdbSqlSchema.py.

390 def has_insert_id(self) -> bool:
391 """Whether insert ID tables are to be used (`bool`)."""
392 if self._has_insert_id is None:
393 self._has_insert_id = self._use_insert_id and self._check_insert_id()
394 return self._has_insert_id
395

◆ makeSchema()

None lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema.makeSchema ( self,
bool drop = False )
Create or re-create all tables.

Parameters
----------
drop : `bool`, optional
    If True then drop tables before creating new ones.

Definition at line 295 of file apdbSqlSchema.py.

295 def makeSchema(self, drop: bool = False) -> None:
296 """Create or re-create all tables.
297
298 Parameters
299 ----------
300 drop : `bool`, optional
301 If True then drop tables before creating new ones.
302 """
303 # Create namespace if it does not exist yet, for now this only makes
304 # sense for postgres.
305 if self._metadata.schema:
306 dialect = self._engine.dialect
307 quoted_schema = dialect.preparer(dialect).quote_schema(self._metadata.schema)
308 create_schema = DDL(
309 "CREATE SCHEMA IF NOT EXISTS %(schema)s", context={"schema": quoted_schema}
310 ).execute_if(dialect="postgresql")
311 event.listen(self._metadata, "before_create", create_schema)
312
313 # create all tables (optionally drop first)
314 if drop:
315 _LOG.info("dropping all tables")
316 self._metadata.drop_all(self._engine)
317 _LOG.info("creating all tables")
318 self._metadata.create_all(self._engine)
319
320 # Reset possibly cached value.
321 self._has_insert_id = None
322 self._metadata_check = None
323

Member Data Documentation

◆ _apdb_tables

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._apdb_tables
protected

Definition at line 254 of file apdbSqlSchema.py.

◆ _dia_object_index

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._dia_object_index
protected

Definition at line 200 of file apdbSqlSchema.py.

◆ _engine

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._engine
protected

Definition at line 199 of file apdbSqlSchema.py.

◆ _extra_tables

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._extra_tables
protected

Definition at line 255 of file apdbSqlSchema.py.

◆ _has_insert_id

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._has_insert_id
protected

Definition at line 321 of file apdbSqlSchema.py.

◆ _htm_index_column

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._htm_index_column
protected

Definition at line 201 of file apdbSqlSchema.py.

◆ _metadata

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._metadata
protected

Definition at line 205 of file apdbSqlSchema.py.

◆ _metadata_check

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._metadata_check
protected

Definition at line 322 of file apdbSqlSchema.py.

◆ _prefix

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._prefix
protected

Definition at line 202 of file apdbSqlSchema.py.

◆ _type_map

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._type_map
protected

Definition at line 208 of file apdbSqlSchema.py.

◆ _use_insert_id

lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema._use_insert_id
protected

Definition at line 203 of file apdbSqlSchema.py.

◆ pixel_id_tables

tuple lsst.dax.apdb.apdbSqlSchema.ApdbSqlSchema.pixel_id_tables = (ApdbTables.DiaObject, ApdbTables.DiaObjectLast, ApdbTables.DiaSource)
static

Definition at line 183 of file apdbSqlSchema.py.


The documentation for this class was generated from the following file: