Skip to content

Make delete recursive #89

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

Closed
Tracked by #38
ssweber opened this issue Feb 23, 2023 · 13 comments
Closed
Tracked by #38

Make delete recursive #89

ssweber opened this issue Feb 23, 2023 · 13 comments

Comments

@ssweber
Copy link
Collaborator

ssweber commented Feb 23, 2023

An issue for tables with grandchildren. Currently can be orphaned if parent is deleted. They will be in database, but hidden.

@ssweber ssweber mentioned this issue Feb 23, 2023
22 tasks
@PySimpleSQL
Copy link
Owner

PySimpleSQL commented Feb 23, 2023 via email

@ssweber
Copy link
Collaborator Author

ssweber commented Feb 23, 2023

Ah, yes that would be better! So we wouldn’t do delete just on CACADE, only for ON DELETE

@ssweber
Copy link
Collaborator Author

ssweber commented Mar 7, 2023

Was looking into this again… read https://stackoverflow.com/questions/29420910/using-foreign-keys-in-sqlite3-for-python

Do MySQL, Postgres work similarly?

connection = sqlite3.connect(DB_FILE)
connection.execute('PRAGMA foreign_keys = ON')
cursor = connection.cursor()

where we could just delete the parent and let the database handle the cascade if user adds “ON DELETE CASCADE” to their setup?

@ssweber
Copy link
Collaborator Author

ssweber commented Mar 7, 2023

Or did you want it to work even if they define the update_cascade, delete_cascade relationship outside of the database

@ssweber
Copy link
Collaborator Author

ssweber commented Mar 7, 2023

Btw, I tested SQLite enforcing foreign keys ( #134 ) and it worked well.

@ssweber
Copy link
Collaborator Author

ssweber commented Mar 7, 2023

You can enable this in user-code by calling:

driver = ss.Sqlite(":memory:", sql_commands=sql)  # Create a new database connection
frm = ss.Form(driver, bind_window=window)  # <=== Here is the magic!
driver.con.execute('PRAGMA foreign_keys = ON') ## Enable foreign-key constraints in Sqlite.

see my example

@ssweber ssweber mentioned this issue Mar 8, 2023
5 tasks
@ssweber
Copy link
Collaborator Author

ssweber commented Mar 12, 2023

Do you mind if I work on this? I have an idea I want to share with you when I get it a little firmed up. #137

@PySimpleSQL
Copy link
Owner

PySimpleSQL commented Mar 12, 2023 via email

@ssweber
Copy link
Collaborator Author

ssweber commented Mar 12, 2023

Definitely. Determining ON DELETE CACADE from SQLite was easy enough, will need some help for MySQL/Postgres. Hope to have something for you to look at by Monday or Tuesday.

What are your thoughts on recursion depth? I’m sorta wondering if we should only support 2-step deletes (self/child/grandchildren) and then if someone is deleting more that have more steps in the cascade, raise some kind of warning if they don’t have foreign key constraints turned On.

@ssweber
Copy link
Collaborator Author

ssweber commented Mar 12, 2023

The accepted answer to this Stack exchange was how I was planning on doing the grandchild records, and so I guess I could do another inner join to do great grandchildren, but I don’t know how or if we want to keep scaling that up. At some point you’d probably want to set a recursion limit 😅

@PySimpleSQL
Copy link
Owner

PySimpleSQL commented Mar 13, 2023 via email

@ssweber
Copy link
Collaborator Author

ssweber commented Mar 13, 2023

No rush! I’m going to use a DELETE_RECURSION_LIMIT: int = and try to setup logic as a loop.

Then we can setup a sensible limit and let users change it if need be

@ssweber
Copy link
Collaborator Author

ssweber commented Mar 13, 2023

#163

@ssweber ssweber closed this as completed Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants