How to use the relstorage.adapters.postgresql.schema.PostgreSQLSchemaInstaller function in RelStorage

To help you get started, we’ve selected a few RelStorage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github newtdb / db / src / newt / db / _adapter.py View on Github external
cursor.execute(
        _newt_delete_on_state_delete_HP if keep_history else
        _newt_delete_on_state_delete)
    cursor.execute("""
    create trigger %s
      after delete on object_state for each row
      execute procedure newt_delete_on_state_delete();
    """ % DELETE_TRIGGER)

def create_newt(cursor, keep_history=None):
    keep_history = determine_keep_history(cursor, keep_history)
    cursor.execute(_newt_ddl)
    _create_newt_delete_trigger(cursor, keep_history)

class SchemaInstaller(
    relstorage.adapters.postgresql.schema.PostgreSQLSchemaInstaller):

    def create(self, cursor):
        super(SchemaInstaller, self).create(cursor)
        create_newt(cursor, self.keep_history)

    def update_schema(self, cursor, tables):
        if 'newt' not in tables:
            create_newt(cursor)
        if not trigger_exists(cursor, DELETE_TRIGGER):
            _create_newt_delete_trigger(cursor, self.keep_history)

    def drop_all(self):
        def callback(_conn, cursor):
            cursor.execute("drop table if exists newt")
            cursor.execute(
                "drop function if exists newt_delete_on_state_delete() cascade"