-
Notifications
You must be signed in to change notification settings - Fork 43
How to add a new table to the database
Bryan Hilbert edited this page Jan 12, 2023
·
1 revision
For new non-monitor database tables, here is a recipe for creating the table in the database. In this example, we're using the new FilesystemCharacteristics table, which is defined in database_interface.py as:
class FilesystemCharacteristics(base):
"""ORM for table containing instrument-specific lists of the number of
obervations corresponding to various instrument characteristics (e.g.
filters)
"""
# Name the table
__tablename__ = 'filesystem_characteristics'
# Define the columns
id = Column(Integer, primary_key=True, nullable=False)
date = Column(DateTime, nullable=False)
instrument = Column(Enum(*JWST_INSTRUMENT_NAMES, name='instrument_name_enum'), nullable=False)
filter_pupil = Column(ARRAY(String, dimensions=1))
obs_per_filter_pupil = Column(ARRAY(Integer, dimensions=1))
To create the new table:
from jwql.database.database_interface import FilesystemCharacteristics
from jwql.database.database_interface import load_connection
from jwql.utils.utils import get_config
connection_string = get_config()['connection_string']
session, base, engine, meta = load_connection(constring)
FilesystemCharacteristics.__table__.create(engine)