boardinghouse.backends.postgres.schema module

class boardinghouse.backends.postgres.schema.DatabaseSchemaEditor(connection, collect_sql=False, atomic=True)[source]

Bases: django.db.backends.postgresql.schema.DatabaseSchemaEditor

This Schema Editor alters behaviour in three ways.

  1. Remove duplicates of deferred sql statements. These are executed using self.execute() anyway, so they will get applied to all schemata as appropriate.
  2. Fire a signal during self.execute() so that listeners may choose to apply this statement to all schemata. This signal only fires for objects that are private objects.
  3. Change the mechanism for grabbing constraint names to also look in the template schema (instead of just public, as is hard-coded in the original method).
execute(sql, params=None)[source]

Executes the given SQL statement, with optional parameters.

boardinghouse.backends.postgres.schema.get_constraints(cursor, table_name, schema_name=None)[source]

Return all constraints for a given table

This function looks in the settings.PUBLIC_SCHEMA, and the supplied schema (defaulting to __template__ if none supplied) for all constraints that exist on the provided table name. The assumption is made that the same table will not exist in both schemata: if so, and the constraints differ between the two tables in any way, then the union of constraints will be returned.

This is an improvement on the django implementation in two ways: it runs in a single query, rather than three. It also allows for a different schema than public, which is hardcoded.

boardinghouse.backends.postgres.schema.get_table_and_schema(sql, cursor)[source]

Given an SQL statement, determine what the database object that is being operated upon is.

This logic is quite complex. If you find a case that does not work, please submit a bug report (or even better, pull request!)