Skip to content
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

API for editing records within a view #470

Closed
kgodey opened this issue Jul 21, 2021 · 7 comments
Closed

API for editing records within a view #470

kgodey opened this issue Jul 21, 2021 · 7 comments
Labels
needs: unblocking Blocked by other work type: enhancement New feature or request work: backend Related to Python, Django, and simple SQL

Comments

@kgodey
Copy link
Contributor

kgodey commented Jul 21, 2021

Problem

Users may want to edit data in views.

Proposed solution

If a view is updatable, we want to support record creates, updates, and deletes via the /api/v0/views/<id>/records/ API. This should function similarly to the table records API.

If a view is not updatable, the records API should be read only. We should return whether a view is updatable in the top-level /api/v0/views/ API.

Additional context

@kgodey kgodey added needs: unblocking Blocked by other work type: enhancement New feature or request work: backend Related to Python, Django, and simple SQL work: database labels Jul 21, 2021
@kgodey kgodey added this to the 08. Working with Views milestone Jul 21, 2021
@mathemancer
Copy link
Contributor

We need to work on a good definition of "updatable" for views. For example, an "updatable" view would necessarily:

  • contain all non-nullable columns from any involved underlying tables,
  • contain only one copy of each contained column (or we'd need to somehow link those columns together so they can only be updated as one),
  • Contain only raw selects from underlying tables (or bijections from values resulting from underlying selects, but I suggest we avoid those for the time being). For example, you can't update a view that aggregates column values.

@kgodey
Copy link
Contributor Author

kgodey commented Jul 26, 2021

@mathemancer does the definition of updatable in the tutorial I linked to in the main issue work?

@mathemancer
Copy link
Contributor

mathemancer commented Jul 28, 2021

@mathemancer does the definition of updatable in the tutorial I linked to in the main issue work?

We could start there, but we'll need to add to the functionality eventually to get as many views as possible to be updatable. The PostgreSQL definition is pretty conservative.

We should also probably check on nullable columns, and duplicate columns, since these aren't shown in the definition and they create problems that make the view impossible to write to (in the former case) and give the possibility of trying to make impossible writes for logical consistency reasons (in the latter case).

BTW, here's the link to the page from the PostgreSQL docs that was cut-and-pasted by that infernal tutorial site: https://www.postgresql.org/docs/13/sql-createview.html

Finally, PostgreSQL doesn't actually mark the view as updatable in any visible way, so we'll need to make some checks ourselves regardless if we want to be able to know whether the view is updatable before trying it.

@kgodey
Copy link
Contributor Author

kgodey commented Jul 28, 2021

@mathemancer Thanks for the link, I've updated the link in the issue description. I did look for the information in the Postgres docs but apparently not very well.

For the scope of this issue, let's use the PostgreSQL definition. I'll create a separate issue for making more views updatable. I'm not sure if it's worth doing for the MVP yet, since there will be significant complexity involved.

@mathemancer
Copy link
Contributor

I did look for the information in the Postgres docs but apparently not very well.

Unfortunately, the PostgreSQL docs' SEO is not as strong as the tutorial site you linked. That site seems to wash the relevant docs page out of the first page of google results pretty regularly for me.

@github-actions
Copy link

This issue has not been updated in 90 days and is being marked as stale.

@github-actions github-actions bot added the stale label Oct 27, 2021
@pavish pavish removed the stale label Oct 28, 2021
@kgodey
Copy link
Contributor Author

kgodey commented Oct 30, 2021

I'm closing this issue. Backend work will be tracked in this issue once design work has been completed:

@kgodey kgodey closed this as completed Oct 30, 2021
@kgodey kgodey removed this from the [09] Working with Views milestone Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: unblocking Blocked by other work type: enhancement New feature or request work: backend Related to Python, Django, and simple SQL
Projects
No open projects
Development

No branches or pull requests

3 participants