autowisp.browser_interface.core.timestamp_triggers module

Class Inheritance Diagram

Inheritance diagram of FieldDoesNotExist

Keep modified current for writes that bypass Django’s ORM.

auto_now only fires where Django is doing the writing, and not even everywhere it is (see core.models.BuiModelBase). A per-table trigger covers the rest, and is installed for every model deriving from that base rather than per model, so a table added later cannot be missed.

Modelled on the project database’s update_<table>_timestamp triggers (autowisp/database/data_model/__init__.py), including the lesson its 0003_repair_timestamp_triggers revision had to teach: key the trigger on the primary key the model actually declares, never on an assumed id.

autowisp.browser_interface.core.timestamp_triggers._column = 'modified'

The column these triggers maintain. Models get it from core.models.BuiModelBase, but the trigger is installed on the strength of the column being present rather than of where it came from. That is both the honest test – the trigger maintains a column, not a class – and what keeps this module free of a model import, which at AppConfig import time would raise AppRegistryNotReady.

autowisp.browser_interface.core.timestamp_triggers._trigger_name(connection, model)[source]

Return the quoted trigger name for a model’s table.

autowisp.browser_interface.core.timestamp_triggers.drop_modified_triggers(sender, using, **_kwargs)[source]

Remove the triggers before an app’s migrations run.

Necessary, not tidiness: SQLite validates existing triggers when a table is altered, so a trigger naming modified makes any migration touching that column fail with “no such column: NEW.modified” – the same way an unparseable trigger blocked migrations of the project database until 0003_repair_timestamp_triggers. post_migrate puts them back, so the pair is what makes the schema alterable.

Parameters:
  • sender – The AppConfig whose migrations are about to run.

  • using (str) – Alias of the database they will run against.

Returns:

None

autowisp.browser_interface.core.timestamp_triggers.install_modified_triggers(sender, using, **_kwargs)[source]

Create the modified trigger for each of an app’s models.

Connected to post_migrate, so it runs after every migrate – which the browser interface performs on every launch – and therefore repairs a trigger that a schema change dropped. SQLite rebuilds a table to alter it, taking its triggers with it, so that is not hypothetical.

Parameters:
  • sender – The AppConfig whose migrations just ran.

  • using (str) – Alias of the database they ran against.

Returns:

None

autowisp.browser_interface.core.timestamp_triggers.timestamped_models(app_config)[source]

Yield the app’s concrete models that carry a modified column.