> normally I'd ask what are the conditions under which this row might be 
> deleted.


In our application, "item" rows can be combined via a "merger" transaction, 
where one item absorbs the data from other items that are deleted after the 
merger. Eventually, an item may get "registered" whereby it's reg_number 
field is assigned a unique number (from an external source), which renders 
it "permanent", where it can receive merged data, but can no longer itself 
be merged-into another item. The intentional deletion of a registered item 
would be an unprecedented event (hasn't yet happened in 200+ years), which 
would require a manual transaction which would require setting the 
reg_number field to NULL, then deleting the item. However, accidental 
deletion *could* happen due to a bug or a faulty data ingest, hence our 
need for delete protection. 

Mike, Thanks for your suggestion of using a database trigger and for the 
code showing how to implement a Core event (which may come in useful in 
another context). We'll do this one via a database trigger. BTW, We're 
using PostgreSQL (9.5); can we build the trigger creation/deletion into an 
alembic migration module? (sorry, probably off-topic)

On Thursday, February 9, 2017 at 12:19:26 PM UTC-7, Роберт Шотланд wrote:
>
> I have a table 'item' that contains a nullable 'reg_number' field that, if 
> it contains a non-null value, the row must not be deleted. I would normally 
> implement a SQL delete-trigger to do this, except we would prefer to 
> maintain a pure SQLAlchemy environment.What would be the best way of 
> implement this using the ORM?
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to