Database Schema#
SkyPortal uses a PostgreSQL database to manage persistent state. This section documents the schema of the database and describes how the application interacts with it.
SQLAlchemy Model API Documentation#
The SkyPortal Python backend interacts with the PostgreSQL backend using the SQLAlchemy object relational mapper. Each database table is represented by a Python class, and each table Column is represented by a class attribute. This Section documents each of the SkyPortal and baselayer classes that are mapped to database tables.
- class baselayer.app.models.ACL(**kwargs)#
An access control list item representing a privilege within the application. ACLs are aggregated into collections called Roles which are assumed by Users. Examples of ACLs include Upload Data, Comment, and Manage Groups.
- Attributes:
- created_at
UTC time of insertion of object’s row into the database.
- id
ACL name.
- modified
UTC time the object’s row was last modified in the database.
- created_at#
UTC time of insertion of object’s row into the database.
- id#
ACL name.
- modified#
UTC time the object’s row was last modified in the database.
- class baselayer.app.models.AccessibleIfRelatedRowsAreAccessible(**properties_and_modes)#
- Attributes:
- properties_and_modes
Methods
select_accessible_rows(cls, user_or_token[, ...])Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- select_accessible_rows(cls, user_or_token, columns=None)#
Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- Parameters:
- clsbaselayer.app.models.DeclarativeMeta
The mapped class of the target table.
- user_or_tokenbaselayer.app.models.User or baselayer.app.models.Token
The User or Token to check.
- columnslist of sqlalchemy.Column, optional, default None
The columns to retrieve from the target table. If None, queries the mapped class directly and returns mapped instances.
- Returns:
- sqlalchemy select object
- class baselayer.app.models.AccessibleIfUserMatches(relationship_chain)#
- Attributes:
- relationship_chain
relationship_namesList of names of each relationship in the chain.
Methods
select_accessible_rows(cls, user_or_token[, ...])Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- property relationship_names#
List of names of each relationship in the chain.
- select_accessible_rows(cls, user_or_token, columns=None)#
Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- Parameters:
- clsbaselayer.app.models.DeclarativeMeta
The mapped class of the target table.
- user_or_tokenbaselayer.app.models.User or baselayer.app.models.Token
The User or Token to check.
- columnslist of sqlalchemy.Column, optional, default None
The columns to retrieve from the target table. If None, queries the mapped class directly and returns mapped instances.
- Returns:
- sqlalchemy select object
- baselayer.app.models.AsyncVerifiedSession(user_or_token)#
Async equivalent of VerifiedSession(). Yields an _AsyncVerifiedSession bound to the configured async engine.
- class baselayer.app.models.ComposedAccessControl(*access_controls, logic='and')#
- Attributes:
- access_controls
- logic
Methods
select_accessible_rows(cls, user_or_token[, ...])Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- select_accessible_rows(cls, user_or_token, columns=None)#
Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- Parameters:
- clsbaselayer.app.models.DeclarativeMeta
The mapped class of the target table.
- user_or_tokenbaselayer.app.models.User or baselayer.app.models.Token
The User or Token to check.
- columnslist of sqlalchemy.Column, optional, default None
The columns to retrieve from the target table. If None, queries the mapped class directly and returns mapped instances.
- Returns:
- sqlalchemy select object
- class baselayer.app.models.CronJobRun(**kwargs)#
A record of a run (or attempted run) of a cron job.
- Attributes:
- created_at
UTC time of insertion of object’s row into the database.
- exit_status
Exit status of cron job subprocess (e.g. 0 or 1).
- id
Unique object identifier.
- modified
UTC time the object’s row was last modified in the database.
- output
Cron job’s subprocess output, or exception string.
- script
Name of script being run.
- created_at#
UTC time of insertion of object’s row into the database.
- exit_status#
Exit status of cron job subprocess (e.g. 0 or 1).
- id#
Unique object identifier.
- modified#
UTC time the object’s row was last modified in the database.
- output#
Cron job’s subprocess output, or exception string.
- script#
Name of script being run.
- class baselayer.app.models.CustomUserAccessControl(query_or_query_generator)#
Methods
select_accessible_rows(cls, user_or_token[, ...])Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- select_accessible_rows(cls, user_or_token, columns=None)#
Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- Parameters:
- clsbaselayer.app.models.DeclarativeMeta
The mapped class of the target table.
- user_or_tokenbaselayer.app.models.User or baselayer.app.models.Token
The User or Token to check.
- columnslist of sqlalchemy.Column, optional, default None
The columns to retrieve from the target table. If None, queries the mapped class directly and returns mapped instances.
- Returns:
- sqlalchemy.Select object
- class baselayer.app.models.JoinModel#
Dummy class that join_models subclass. Provides an easy way to access all join_model mapped classes via the __subclasses__() method.
- class baselayer.app.models.Public#
A record accessible to anyone.
Methods
select_accessible_rows(cls, user_or_token[, ...])Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- select_accessible_rows(cls, user_or_token, columns=None)#
Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- Parameters:
- clsbaselayer.app.models.DeclarativeMeta
The mapped class of the target table.
- user_or_tokenbaselayer.app.models.User or baselayer.app.models.Token
The User or Token to check.
- columnslist of sqlalchemy.Column, optional, default None
The columns to retrieve from the target table. If None, queries the mapped class directly and returns mapped instances.
- Returns:
- sqlalchemy select object
- class baselayer.app.models.Restricted#
A record that can only be accessed by a System Admin.
Methods
select_accessible_rows(cls, user_or_token[, ...])Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- select_accessible_rows(cls, user_or_token, columns=None)#
Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- Parameters:
- clsbaselayer.app.models.DeclarativeMeta
The mapped class of the target table.
- user_or_tokenbaselayer.app.models.User or baselayer.app.models.Token
The User or Token to check.
- columnslist of sqlalchemy.Column, optional, default None
The columns to retrieve from the target table. If None, queries the mapped class directly and returns mapped instances.
- Returns:
- sqlalchemy.Select object
- class baselayer.app.models.Role(**kwargs)#
A collection of ACLs. Roles map Users to ACLs. One User may assume multiple Roles.
- Attributes:
- acls
ACLs associated with the Role.
- created_at
UTC time of insertion of object’s row into the database.
- id
Role name.
- modified
UTC time the object’s row was last modified in the database.
- users
Users who have this Role.
- acls#
ACLs associated with the Role.
- created_at#
UTC time of insertion of object’s row into the database.
- id#
Role name.
- modified#
UTC time the object’s row was last modified in the database.
- users#
Users who have this Role.
- class baselayer.app.models.RoleACL(**kwargs)#
Join table class mapping Roles to ACLs.
- Attributes:
- acl
- acl_id
- created_at
UTC time of insertion of object’s row into the database.
- id
Unique object identifier.
- modified
UTC time the object’s row was last modified in the database.
- role
- role_id
- create = <baselayer.app.models.AccessibleIfRelatedRowsAreAccessible object>#
- created_at#
UTC time of insertion of object’s row into the database.
- id#
Unique object identifier.
- modified#
UTC time the object’s row was last modified in the database.
- read = <baselayer.app.models.AccessibleIfRelatedRowsAreAccessible object>#
- class baselayer.app.models.Token(**kwargs)#
A command line token that can be used to programmatically access the API as a particular User.
- Attributes:
accessible_group_idsReturn a set of group IDs that the user or token has access to.
accessible_groupsReturn the list of Groups a User or Token has access to.
accessible_streamsReturn the list of Streams a User or Token has access to.
- acls
The ACLs granted to the Token.
- created_at
UTC time of insertion of object’s row into the database.
- created_by
The User that created the token.
- created_by_id
The ID of the User that created the Token.
groupsThe groups the Token owner is a member of.
- id
The value of the token. This field is used for authenticating as a User on the command line.
- is_admin
- is_system_admin
- modified
UTC time the object’s row was last modified in the database.
- name
The name of the token.
Methods
assert_group_accessible(group_id)Raise an error if the user or token does not have access to the given group.
is_readable_by(user_or_token)Return a boolean indicating whether this Token is readable by the specified User (or Token instance, if a token is passed).
- property accessible_group_ids#
Return a set of group IDs that the user or token has access to.
- property accessible_groups#
Return the list of Groups a User or Token has access to. For non-admin Users or Token owners, this corresponds to the Groups they are a member of. For System Admins, this corresponds to all Groups.
- property accessible_streams#
Return the list of Streams a User or Token has access to.
- acls#
The ACLs granted to the Token.
- assert_group_accessible(group_id)#
Raise an error if the user or token does not have access to the given group.
- Parameters:
- group_idint or str
The ID of the group to check.
- Raises:
- AccessError
If the user or token does not have access to the group.
- create = <baselayer.app.models.AccessibleIfUserMatches object>#
- created_at#
UTC time of insertion of object’s row into the database.
- created_by#
The User that created the token.
- created_by_id#
The ID of the User that created the Token.
- delete = <baselayer.app.models.AccessibleIfUserMatches object>#
- property groups#
The groups the Token owner is a member of.
- id#
The value of the token. This field is used for authenticating as a User on the command line.
- is_readable_by(user_or_token)#
Return a boolean indicating whether this Token is readable by the specified User (or Token instance, if a token is passed).
- Parameters:
- user_or_tokenbaselayer.app.models.User or baselayer.app.models.Token
The User or Token to check.
- Returns:
- readablebool
Whether this Token instance is readable by the User or Token.
- modified#
UTC time the object’s row was last modified in the database.
- name#
The name of the token.
- read = <baselayer.app.models.AccessibleIfUserMatches object>#
- update = <baselayer.app.models.AccessibleIfUserMatches object>#
- class baselayer.app.models.TokenACL(**kwargs)#
Join table mapping Tokens to ACLs
- Attributes:
- acl
- acl_id
- created_at
UTC time of insertion of object’s row into the database.
- id
Unique object identifier.
- modified
UTC time the object’s row was last modified in the database.
- token
- token_id
- create = <baselayer.app.models.AccessibleIfRelatedRowsAreAccessible object>#
- created_at#
UTC time of insertion of object’s row into the database.
- id#
Unique object identifier.
- modified#
UTC time the object’s row was last modified in the database.
- read = <baselayer.app.models.AccessibleIfRelatedRowsAreAccessible object>#
- class baselayer.app.models.User(**kwargs)#
An application user.
- Attributes:
accessible_group_idsReturn a set of group IDs that the user or token has access to.
accessible_groupsReturn the list of Groups a User or Token has access to.
accessible_streamsReturn the list of Streams a User or Token has access to.
- acls
ACLs granted to user, separate from role-level ACLs
- affiliations
The User’s affiliations (ex: Department of Mathematics, University X)
- annotations
- annotations_on_photometry
- annotations_on_spectra
- assignments
Objs the User has assigned to ObservingRuns.
- assistant_messages
- bio
A short biography of the user, or description for bot accounts.
- catalog_queries
The catalog queries this User has made.
- comments
- comments_on_earthquakes
- comments_on_gcns
- comments_on_shifts
- comments_on_spectra
- contact_email
The phone number at which the user prefers to receive communications.
- contact_phone
The email at which the user prefers to receive communications.
- created_at
UTC time of insertion of object’s row into the database.
- default_followup_requests
The default follow-up requests this User has made.
- default_gcntags
The default gcn tags this User has made.
- default_observationplan_requests
The default observation plan requests this User has made.
- earthquakeevents
The EarthquakeEvents saved by this user
- earthquakenotices
The EarthquakeNotices saved by this user
- expiration_date
The date until which the user’s account is valid. Users are set to view-only upon expiration.
- first_name
The User’s first name.
- followup_requests
The follow-up requests this User has made.
- gcn_event_objs
GcnEventObj rows this User has created.
- gcneventextractions
The gcneventextractions saved by this user
- gcnevents
The gcnevents saved by this user
- gcnnotices
The GcnNotices saved by this user
- gcnproperties
The gcnproperties saved by this user
- gcnreports
The gcnreports saved by this user
- gcnsummaries
The gcnsummaries saved by this user
- gcntags
The gcntags saved by this user
gravatar_urlThe Gravatar URL inferred from the user’s contact email, or, if the contact email is null, the username.
- group_admission_requests
User’s requests to join groups.
- groups
The Groups this User is a member of.
- id
Unique object identifier.
- is_admin
- is_bot
Whether or not the user account should be flagged as a bot account.
- is_system_admin
- last_name
The User’s last name.
- listings
The listings saved by this user
- localizationproperties
The localizationproperties saved by this user
- localizations
The localizations saved by this user
- localizationtags
The localizationtags saved by this user
- mmadetector_spectra
MMADetectorSpectra uploaded by this User.
- mmadetector_time_intervals
MMADetectorTimeInterval uploaded by this User.
- modified
UTC time the object’s row was last modified in the database.
- notifications
Notifications to be displayed on front-end associated with User
- oauth_uid
The user’s OAuth UID.
- observationplan_requests
The observation plan requests this User has made.
- observing_runs
Observing Runs this User has created.
permissionsList of the names of all of the user’s ACLs (role-level + individual).
- photometric_series
PhotometricSeries uploaded by this User.
- photometry
Photometry uploaded by this User.
- photometryvalidations
PhotometryValidation this User has created.
- preferences
The user’s application settings.
- recurring_apis
- reminders
- reminders_on_earthquakes
- reminders_on_gcns
- reminders_on_shifts
- reminders_on_spectra
- roles
The roles assumed by this user.
- saved_sources
- sharing_service_submissions
Sharing submissions this user has made (manual or automatic).
- shifts
The Shifts this User is a member of.
- single_user_group
- source_notifications
Source notifications the User has sent out.
- sources
The Sources accessible to this User.
- spectra
Spectra uploaded by this User.
- streams
The Streams this User has access to.
- survey_efficiency_for_observation_plan
The survey efficiency analyses on ObservationPlans this User has made.
- survey_efficiency_for_observations
The survey efficiency analyses on Observations this User has made.
- tokens
This user’s tokens.
- transaction_requests
The FacilityTransactionRequests initiated by this User.
- transactions
The FacilityTransactions initiated by this User.
- username
The user’s username.
Methods
assert_group_accessible(group_id)Raise an error if the user or token does not have access to the given group.
Boolean flag indicating whether the User is currently active.
Boolean flag indicating whether the User is currently authenticated.
The base model for User subclasses.
to_dict
- property accessible_group_ids#
Return a set of group IDs that the user or token has access to.
- property accessible_groups#
Return the list of Groups a User or Token has access to. For non-admin Users or Token owners, this corresponds to the Groups they are a member of. For System Admins, this corresponds to all Groups.
- property accessible_streams#
Return the list of Streams a User or Token has access to.
- acls#
ACLs granted to user, separate from role-level ACLs
- affiliations#
The User’s affiliations (ex: Department of Mathematics, University X)
- assert_group_accessible(group_id)#
Raise an error if the user or token does not have access to the given group.
- Parameters:
- group_idint or str
The ID of the group to check.
- Raises:
- AccessError
If the user or token does not have access to the group.
- assignments#
Objs the User has assigned to ObservingRuns.
- bio#
A short biography of the user, or description for bot accounts.
- catalog_queries#
The catalog queries this User has made.
- contact_email#
The phone number at which the user prefers to receive communications.
- contact_phone#
The email at which the user prefers to receive communications.
- created_at#
UTC time of insertion of object’s row into the database.
- default_followup_requests#
The default follow-up requests this User has made.
- default_gcntags#
The default gcn tags this User has made.
- default_observationplan_requests#
The default observation plan requests this User has made.
- delete = <baselayer.app.models.CustomUserAccessControl object>#
- earthquakeevents#
The EarthquakeEvents saved by this user
- earthquakenotices#
The EarthquakeNotices saved by this user
- expiration_date#
The date until which the user’s account is valid. Users are set to view-only upon expiration.
- first_name#
The User’s first name.
- followup_requests#
The follow-up requests this User has made.
- gcn_event_objs#
GcnEventObj rows this User has created.
- gcneventextractions#
The gcneventextractions saved by this user
- gcnevents#
The gcnevents saved by this user
- gcnnotices#
The GcnNotices saved by this user
- gcnproperties#
The gcnproperties saved by this user
- gcnreports#
The gcnreports saved by this user
- gcnsummaries#
The gcnsummaries saved by this user
- gcntags#
The gcntags saved by this user
- property gravatar_url#
The Gravatar URL inferred from the user’s contact email, or, if the contact email is null, the username.
- group_admission_requests#
User’s requests to join groups.
- groups#
The Groups this User is a member of.
- id#
Unique object identifier.
- is_active()#
Boolean flag indicating whether the User is currently active.
- is_authenticated()#
Boolean flag indicating whether the User is currently authenticated.
- is_bot#
Whether or not the user account should be flagged as a bot account.
- last_name#
The User’s last name.
- listings#
The listings saved by this user
- localizationproperties#
The localizationproperties saved by this user
- localizations#
The localizations saved by this user
- localizationtags#
The localizationtags saved by this user
- mmadetector_spectra#
MMADetectorSpectra uploaded by this User.
- mmadetector_time_intervals#
MMADetectorTimeInterval uploaded by this User.
- modified#
UTC time the object’s row was last modified in the database.
- notifications#
Notifications to be displayed on front-end associated with User
- oauth_uid#
The user’s OAuth UID.
- observationplan_requests#
The observation plan requests this User has made.
- observing_runs#
Observing Runs this User has created.
- property permissions#
List of the names of all of the user’s ACLs (role-level + individual).
- photometric_series#
PhotometricSeries uploaded by this User.
- photometry#
Photometry uploaded by this User.
- photometryvalidations#
PhotometryValidation this User has created.
- preferences#
The user’s application settings.
- roles#
The roles assumed by this user.
- sharing_service_submissions#
Sharing submissions this user has made (manual or automatic).
- shifts#
The Shifts this User is a member of.
- source_notifications#
Source notifications the User has sent out.
- sources#
The Sources accessible to this User.
- spectra#
Spectra uploaded by this User.
- streams#
The Streams this User has access to.
- survey_efficiency_for_observation_plan#
The survey efficiency analyses on ObservationPlans this User has made.
- survey_efficiency_for_observations#
The survey efficiency analyses on Observations this User has made.
- to_dict()#
Serialize this object to a Python dictionary.
- tokens#
This user’s tokens.
- transaction_requests#
The FacilityTransactionRequests initiated by this User.
- transactions#
The FacilityTransactions initiated by this User.
- update = <baselayer.app.models.CustomUserAccessControl object>#
- classmethod user_model()#
The base model for User subclasses.
- username#
The user’s username.
- class baselayer.app.models.UserACL(**kwargs)#
Join table mapping Users to ACLs
- Attributes:
- acl
- acl_id
- created_at
UTC time of insertion of object’s row into the database.
- id
Unique object identifier.
- modified
UTC time the object’s row was last modified in the database.
- user
- user_id
- create = <baselayer.app.models.AccessibleIfRelatedRowsAreAccessible object>#
- created_at#
UTC time of insertion of object’s row into the database.
- id#
Unique object identifier.
- modified#
UTC time the object’s row was last modified in the database.
- read = <baselayer.app.models.AccessibleIfRelatedRowsAreAccessible object>#
- class baselayer.app.models.UserAccessControl#
Logic for controlling user access to database records. Mapped classes can set their create, read, update, or delete attributes to subclasses of this class to ensure they are only accessed by users or tokens with the requisite permissions.
Methods
check_cls_for_attributes(cls, attrs)Check that a target class has the specified attributes.
select_accessible_rows(cls, user_or_token[, ...])Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
user_id_from_user_or_token(user_or_token)Return the user_id associated with a specified User or Token object.
- static check_cls_for_attributes(cls, attrs)#
Check that a target class has the specified attributes. If not, raise a TypeError.
- Parameters:
- clsbaselayer.app.models.DeclarativeMeta
The class to check.
- attrslist of str
The names of the attributes to check for.
- select_accessible_rows(cls, user_or_token, columns=None)#
Construct a Select object that, when executed, returns the rows of a specified table that are accessible to a specified user or token.
- Parameters:
- clsbaselayer.app.models.DeclarativeMeta
The mapped class of the target table.
- user_or_tokenbaselayer.app.models.User or baselayer.app.models.Token
The User or Token to check.
- columnslist of sqlalchemy.Column, optional, default None
The columns to retrieve from the target table. If None, queries the mapped class directly and returns mapped instances.
- Returns:
- sqlalchemy select object
- static user_id_from_user_or_token(user_or_token)#
Return the user_id associated with a specified User or Token object.
- Parameters:
- user_or_tokenbaselayer.app.models.User or baselayer.app.models.Token
The User or Token to check.
- Returns:
- user_id: int
The user_id associated with the User or Token object.
- class baselayer.app.models.UserRole(**kwargs)#
Join table mapping Users to Roles.
- Attributes:
- created_at
UTC time of insertion of object’s row into the database.
- id
Unique object identifier.
- modified
UTC time the object’s row was last modified in the database.
- role
- role_id
- user
- user_id
- create = <baselayer.app.models.AccessibleIfRelatedRowsAreAccessible object>#
- created_at#
UTC time of insertion of object’s row into the database.
- id#
Unique object identifier.
- modified#
UTC time the object’s row was last modified in the database.
- read = <baselayer.app.models.AccessibleIfRelatedRowsAreAccessible object>#
- async baselayer.app.models.async_bulk_verify(session, mode, collection, accessor)#
Async counterpart of bulk_verify. Runs the access-control leak check inside the supplied async session rather than the global sync DBSession.
- baselayer.app.models.bulk_verify(mode, collection, accessor)#
Vectorized permission check for a heterogeneous set of records. If an access leak is detected, it will be handled according to the security section of the application’s configuration.
- Parameters:
- modestr
The access mode to check. Can be create, read, update, or delete.
- collectioncollection of baselayer.app.models.Base.
The records to check. These records will be grouped by type, and a single database query will be issued to check access for each record type.
- accessorbaselayer.app.models.User or baselayer.app.models.Token
The user or token to check.
- baselayer.app.models.db_engine()#
The engine that init_db() bound DBSession to, or None before it runs.
- baselayer.app.models.group_by_type(collection)#
Group records by mapped class, so each class needs a single query.
- baselayer.app.models.inaccessible_pks_stmt(collection, accessible_rows, pk_cols)#
Build the statement selecting the primary keys of
collectionthat are missing fromaccessible_rows.Records are matched on every column of their primary key, so a composite key is checked like a surrogate
id.- Parameters:
- collectionlist of baselayer.app.models.Base
The records to check, all of the type whose PK columns are
pk_cols.- accessible_rowssqlalchemy select object
Query of the
pk_colsof the rows the accessor may access.- pk_colslist of sqlalchemy.Column
The primary key columns of the records.
- Returns:
- sqlalchemy select object
One row per inaccessible record, one column per primary key column.
- baselayer.app.models.join_model(join_table, model_1, model_2, column_1=None, column_2=None, fk_1='id', fk_2='id', base=<class 'sqlalchemy.orm.decl_api.Base'>, new_name=None, overlaps=None, index_created_at=True, composite_pk=False)#
Helper function to create a join table for a many-to-many relationship.
- Parameters:
- join_tablestr
Name of the new table to be created.
- model_1str
First model in the relationship.
- model_2str
Second model in the relationship.
- column_1str, optional
Name of the join table column corresponding to model_1. If None, then {table1`[:-1]_id} will be used (e.g., `user_id for users).
- column_2str, optional
Name of the join table column corresponding to model_2. If None, then {table2`[:-1]_id} will be used (e.g., `user_id for users).
- fk_1str, optional
Name of the column from model_1 that the foreign key should refer to.
- fk_2str, optional
Name of the column from model_2 that the foreign key should refer to.
- basesqlalchemy.ext.declarative.api.DeclarativeMeta
SQLAlchemy model base to subclass.
- new_name: str, optional
Name of the new model class. If None, then the name will be model_1.__name__ + model_2.__name__.
- overlapsstr or list of str, optional
Each relationship defined in this model will have, by default, overlaps=f”{table_1}, {table_2}”. If any additional overalapping relationships or columns need to be added, they can be given as a string or list of strings.
- index_created_atbool, optional
Whether to index the auto-added
created_atcolumn. Defaults to True.- composite_pkbool, optional
If True, use
(column_1, column_2)as the primary key instead of a surrogateidcolumn; the PK’s unique index replaces the forward index. Defaults to False.
- Returns:
- sqlalchemy.ext.declarative.api.DeclarativeMeta
SQLAlchemy association model class
- baselayer.app.models.new_async_session()#
The async counterpart of new_session(): a session of its own, with no access-control check. Close it when the work is done.
- baselayer.app.models.new_session()#
A session of its own, independent of the request-scoped DBSession.
For work running outside a web request, where sharing one session between callers would let one caller’s rollback discard another’s pending work. Applies no access-control check; close it when the work is done.
- baselayer.app.models.pending_rows(session)#
The rows of session to check, as (read, updated, deleted, new).
- baselayer.app.models.pks_of(rows, pk_cols)#
Collect the primary keys of the rows returned by inaccessible_pks_stmt.
- Parameters:
- rowslist of sqlalchemy.Row
The rows returned by inaccessible_pks_stmt.
- pk_colslist of sqlalchemy.Column
The primary key columns the rows were selected on.
- Returns:
- set
The primary keys, scalars for a single column and tuples for several.
- baselayer.app.models.primary_key_keys(cls)#
Return the attribute keys of
cls’s primary key columns.Most mapped classes use a single surrogate
id, but join tables may use a composite primary key (e.g.group_id+photometr_id). Access control joins on the primary key, so deriving it here keeps that logic PK-agnostic instead of assuming a column namedid.Uses
.mapper.primary_keyso it works for both mapped classes and aliased classes (anAliasedInsphas noprimary_keyof its own).
- baselayer.app.models.resolve_pooler(host, port, engine_args, pooler)#
Route the connection through a transaction pooler (pgbouncer/pgcat) when enabled, so backend connections stay bounded across all processes. Returns adjusted
(host, port, engine_args).
Entity Relationship Diagram#
The following entity relationship diagram visualizes the structure of the SkyPortal database. Drag to pan, scroll to zoom, and click a table to highlight the tables it is related to.