-
Notifications
You must be signed in to change notification settings - Fork 2.1k
datastore triggers #3428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
datastore triggers #3428
Conversation
👍 |
…atastore-triggers
@amercader this is feature complete with test coverage now. |
For issues on #3414 please report them there and I'll fix on that branch and merge back into this one. |
need to fix quantified code error and exceptions aren't being caught by upsert. |
@amercader this is ready for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff @wardi, see only my minor comments
# Make a copy of the Pylons config, so we can restore it in teardown. | ||
cls._original_config = dict(config) | ||
cls._apply_config_changes(config) | ||
cls._get_test_app() | ||
for plugin in getattr(cls, '_load_plugins', []): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this!
or "for_each" parameters from triggers list. | ||
''' | ||
existing = connection.execute( | ||
u'SELECT tgname FROM pg_trigger WHERE tgrelid = %s::regclass', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use datastore_helpers.identifier
here? Maybe not, I'm not familiar with ::regclass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the execute() call is quoting the resource_id parameter for us. I use identifier
when I can't avoid hand-rolling sql.
ckanext/datastore/logic/action.py
Outdated
:param triggers: triggers to apply to this table, eg: [ | ||
{"function": "trigger_clean_reference"}, | ||
{"function": "trigger_check_codes"}] | ||
:type triggers: list of dictionaries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add a note that says that these triggers can be created with :py:func:`datastore_function_create`
so docs are linked. Are they limited to the ones created via this action? Or can you invoke triggers manually created on Postgres?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion. You can use any postgresql function that returns type trigger
, whether created by datastore_function_create or manually.
Thanks @amercader ! |
Triggers are great for cleaning data, enforcing validation and/or keeping modification records as data is being loaded. Using triggers instead of validation logic at the python level lets us enforce those rules regardless of how the data is loaded (bulk loading data straight to postgres is very nice for large datasets)