This package contains basic stuff for db actions.
2011 by AG DSN.
A tzinfo factory compatible with psycopg2.tz.FixedOffsetTimezone
,
that checks if the provided UTC offset is zero and returns
datetime.timezone.utc
. If the offset is not zero an
psycopg2.DataError
is raised.
This class is implemented as a singleton that always returns the same instance.
A Cursor factory that sets the
psycopg2.extensions.cursor.tzinfo_factory
to
UTCTZInfoFactory
.
The C implementation of the cursor class does not use the proper Python attribute lookup, therefore we have to set the instance variable rather than use a class attribute.
Create all models in the database.
Drop all models from the database.
Dummy module to get all the mapped stuff in one namespace. This is necessary for things like sqlalchemy-schemadisplay.
2011 by AG DSN.
A known address.
Addresses differ from most other entities such as users or rooms in the following ways:
Their identity is provided by their value, i.e. if two addresses have equal values, they should be identitcal
Their existence is justified solely by the reference of another object. At no point in time should there be any unreferenced address records in the db.
They should be immutable: This implies that editing e.g. the street of a user’s address should not change the street of the corresponding room’s address. This implies that addresses are stateless, i.e. have no life cycle.
Establishing these consistencies requires triggers.
This module contains base stuff for all models.
2011 by AG DSN.
Base class for all database models.
Refers to the _schema.MetaData
collection that will be used
for new _schema.Table
objects.
See also
Refers to the _orm.registry
in use where new
_orm.Mapper
objects will be associated.
MappedAsDataclass, but with metaclass which includes our custom metaclass.
This exists because the following does not work:
from sqlalchemy import
class Foo(MappedAsDataclass, ModelBase):
...
The reason is that MappedAsDataclass implements its functionality with its own metaclass. However, since classes can only have one metaclass, the metaclass of MappedAsDataclass subclasses`DeclarativeMeta`.
In our case, this is not sufficient, since our ModelBase uses a custom metaclass _ModelMeta for the (legacy) .q shorthand; to fix this, we create a new metaclass inheriting from both type(MappedAsDataclass) and _ModelMeta.
Abstract base class for database models with an Integer primary column,
named id
.
Extends SQLALchemy’s DropConstraint with support for IF EXISTS
Arguments of the function. A function
identifier of new_function(integer, integer)
would
result in arguments=['integer', 'integer']
.
Definition
Represents a CREATE FUNCTION DDL statement
Represents a DROP FUNCTION DDL statement
Compile a CREATE FUNCTION DDL statement for PostgreSQL
Compile a DROP FUNCTION DDL statement for PostgreSQL
Represents a CREATE RULE DDL statement
Represents a DROP RULE DDL statement
Compile a CREATE RULE DDL statement for PostgreSQL.
Compile a DROP RULE DDL statement for PostgreSQL
Represents a CREATE CONSTRAINT TRIGGER DDL statement
Represents a DROP TRIGGER DDL statement.
Compile a CREATE CONSTRAINT TRIGGER DDL statement for PostgreSQL
Compile a CREATE CONSTRAINT TRIGGER DDL statement for PostgreSQL
Compile a DROP TRIGGER DDL statement for PostgreSQL
the query it represents
Ensures that create DDL statements are registered with SQLAlchemy in the order they were added to the manager and registers the drop DDL statements in the reverse order.
Example usage:
>>> from sqlalchemy import MetaData, Table, Column as C, Integer as I, String as S
>>> table = Table('table', MetaData(), C('id', I, primary_key=True), C('name', S))
>>> manager = DDLManager()
>>> view = View('my_view', "select concat(name, ' hat das Spiel verloren') from table")
>>> manager.add_view(table, view)
>>> # … do other stuff
>>> manager.register()
Check transaction constraints.
Transaction must be balanced, an account mustn’t be referenced by more than one split and it must consist of at least two splits. :raises: IllegalTransactionError if transaction contains errors
Add support for various functions present in Postgres to the SQLite SQLAlchemy dialect.
Indicate if this HasCacheKey
instance should make use of the
cache key generation scheme used by its immediate superclass.
The attribute defaults to None
, which indicates that a construct has
not yet taken into account whether or not its appropriate for it to
participate in caching; this is functionally equivalent to setting the
value to False
, except that a warning is also emitted.
This flag can be set to True
on a particular class, if the SQL that
corresponds to the object does not change based on attributes which
are local to this class, and not its superclass.
See also
Enabling Caching Support for Custom Constructs - General guideslines for setting the
HasCacheKey.inherit_cache
attribute for third-party or user
defined SQL constructs.
Indicate if this HasCacheKey
instance should make use of the
cache key generation scheme used by its immediate superclass.
The attribute defaults to None
, which indicates that a construct has
not yet taken into account whether or not its appropriate for it to
participate in caching; this is functionally equivalent to setting the
value to False
, except that a warning is also emitted.
This flag can be set to True
on a particular class, if the SQL that
corresponds to the object does not change based on attributes which
are local to this class, and not its superclass.
See also
Enabling Caching Support for Custom Constructs - General guideslines for setting the
HasCacheKey.inherit_cache
attribute for third-party or user
defined SQL constructs.
Indicate if this HasCacheKey
instance should make use of the
cache key generation scheme used by its immediate superclass.
The attribute defaults to None
, which indicates that a construct has
not yet taken into account whether or not its appropriate for it to
participate in caching; this is functionally equivalent to setting the
value to False
, except that a warning is also emitted.
This flag can be set to True
on a particular class, if the SQL that
corresponds to the object does not change based on attributes which
are local to this class, and not its superclass.
See also
Enabling Caching Support for Custom Constructs - General guideslines for setting the
HasCacheKey.inherit_cache
attribute for third-party or user
defined SQL constructs.
A switch with a name and mgmt-ip
A Switch is directly tied to a Host because instead of having an id column, the primary key is host_id, a foreign key on a Host.
A logical network interface (hence the single MAC address).
This means many net interfaces can be connected to the same switch port.
It has to be bound to a UserHost, not another kind of host (like Switch)
This module contains the classes LogEntry, UserLogEntry, TrafficVolume.
2011 by AG DSN.
A patch panel port that may or not be connected to a switch
This module contains model descriptions concerning properties, groups, and memberships.
A sqlalchemy func wrapper for the evaluate_properties PSQL function.
See sqlalchemy.sql.selectable.FromClause.table_valued.
This module contains the session stuff for db actions.
2011 by AG DSN.
The task model
The task model needs to hold three types of data:
Metadata (creation, status, …)
A type (e.g. USER_MOVE)
the parameters_json json dict.
The parameters should actually be accessed via parameters
,
as this already takes care of validation and (de-)serialization.
The type field is essentially only needed for filtering in a query.
(Lazily) deserialized dict corresponding to the parameters.
The deserialization happens according to what schema is referenced in self.schema.
A sqlalchemy func wrapper for the evaluate_properties PSQL function.
See sqlalchemy.sql.selectable.FromClause.table_valued.
gets PY TYPE, returns DB TYPE
Provide the functionality of the @> operator for Intervals.
other¶ – can be an interval, a tz-aware datetime, or column-like sql expressions with these types.
If any .contains() call does not work, you can add support here.
A sqlalchemy type decorator corresponding to datetime types with time zone.
In other words, a mapped_column(DateTimeTz) produces python objects of type
pycroft.helpers.utc.DateTimeTz
.
This module contains the UnixAccount
and UnixTombstone
classes.
A tombstone for uids and logins, preventing their re-use.
A tombstone relates to a pycroft.model.user.User
and UnixAccount
via three relationships, as depicted in the ER diagram below.
The hash is stored in the generated column
User.login_hash
,
which has a foreign key on the Tombstone
.
Furthermore, the associated UnixAccount has a uid,
which also points to a Tombstone
.
There is a trigger which checks that if both of these objects exist, they point to the same tombstone.
The lifecycle of a tombstone is restricted by
check_unix_tombstone_lifecycle_func
.
Trigger function ensuring proper tombstone lifecycle (see UnixTombstone
).
Trigger function ensuring automatic generation of a tombstone
on UnixAccount
inserts.
Trigger function ensuring automatic generation of a tombstone
on User
updates.
Trigger function checking whether User
and associated UnixAccount
refer to the same Tombstone
.
See Tombstone
for an illustration.
This module contains the class User.
2011 by AG DSN.
Auto-generated sha512 hash of login
.
Whether the user’s address differs from their room’s address.
If no room is assigned, returns False
.
This is a relationship to the current_property view filtering out the entries with denied=True.
This is a relationship to the current_property view ignoring the denied attribute.
A type-agnostic property giving the granted properties as a set of string.
Utilized in the web component’s access control mechanism.
return the cleartext wifi password (without crypt prefix) if available.
None if the wifi_passwd_hash is not set or is not cleartext.