Using Postgres and Hasura provides us with really cool tools to keep our data clean and organized with less code.
For example, we wouldn't want a user to be able to be marked as a project lead while not being assigned to a project. We could check for this in the site code when we make changes to the user's enrollment, but this is extra code and doesn't cover cases where data might be changed by other programs like a Discord bot.
Another example is determining a user's display name when the might have limited data available (first name but not last name, only first name, no names but rcs id, no names or rcs id, etc.). We can write a Python functions that takes in a user and determines the display name, but we probably want to use that functionality across more than just the site.
Instead, we can use Postgres constraints, triggers, functions and Hasura computed fields (as well as other features) to centralize some of that validation and helper logic in the database itself!
Suggested ideas:
[x] Create display_name computed field on users
[ ] Prevent is_project_lead = true and project_id is null at the same time
[ ] secondary_email is unique across all emails and secondary_emails
These would generally be written in SQL and have to be kept somewhere in source control. We would probably use Hasura SQL migrations and a repository like rcos/rcos-data which is currently being used for the self-hosted Hasura instance on DigitalOcean. We should discuss where this SQL would go, but in the meantime the work figuring out the SQL for these items can be done.
Using Postgres and Hasura provides us with really cool tools to keep our data clean and organized with less code.
For example, we wouldn't want a user to be able to be marked as a project lead while not being assigned to a project. We could check for this in the site code when we make changes to the user's enrollment, but this is extra code and doesn't cover cases where data might be changed by other programs like a Discord bot.
Another example is determining a user's display name when the might have limited data available (first name but not last name, only first name, no names but rcs id, no names or rcs id, etc.). We can write a Python functions that takes in a user and determines the display name, but we probably want to use that functionality across more than just the site.
Instead, we can use Postgres constraints, triggers, functions and Hasura computed fields (as well as other features) to centralize some of that validation and helper logic in the database itself!
Suggested ideas:
display_name
computed field onusers
is_project_lead = true
andproject_id is null
at the same timesecondary_email
is unique across allemail
s andsecondary_email
sThese would generally be written in SQL and have to be kept somewhere in source control. We would probably use Hasura SQL migrations and a repository like
rcos/rcos-data
which is currently being used for the self-hosted Hasura instance on DigitalOcean. We should discuss where this SQL would go, but in the meantime the work figuring out the SQL for these items can be done.