mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-10-27 07:14:08 +09:00
Replaces the 29 hand-written cascade='all, delete-orphan' declarations from c1d4c0af/1704d60b/79a78c3c with a single mapper hook (_delete_cascade_policy): at configure time, every one-to-many whose child FK is NOT NULL gets the delete cascade automatically — with a NOT NULL FK the children cannot outlive the parent, so the only choice is cascade or crash. New models (extensions included — registering one re-fires the hook) are covered with zero ceremony; nothing to remember. Relationships where the parent delete should be REFUSED instead opt out in the module's DELIBERATELY_UNCASCADED registry with their justification (User.applications guarded by delete_user's 409, CloudProvider.servers with no delete path). The sweep test now proves the door works rather than policing model authors, and pins the registry so it can only shrink. Model files revert to their pre-fix text: delete semantics live in one place instead of twenty. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
from datetime import datetime
|
|
from app import db
|
|
from app.models.mixins import SerializableMixin
|
|
|
|
|
|
class ImageUpdateCheck(SerializableMixin, db.Model):
|
|
"""Result of comparing an application's running image digest against the
|
|
current digest for the same tag in its registry."""
|
|
__tablename__ = 'image_update_checks'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
application_id = db.Column(db.Integer, db.ForeignKey('applications.id'), nullable=False, index=True)
|
|
image_ref = db.Column(db.String(500), nullable=False)
|
|
current_digest = db.Column(db.String(128)) # sha256:... running locally
|
|
latest_digest = db.Column(db.String(128)) # sha256:... currently in the registry
|
|
update_available = db.Column(db.Boolean, default=False, nullable=False)
|
|
status = db.Column(db.String(20), default='pending') # pending, completed, failed
|
|
error_message = db.Column(db.Text)
|
|
checked_at = db.Column(db.DateTime, default=datetime.utcnow)
|
|
|
|
application = db.relationship('Application', backref=db.backref(
|
|
'image_update_checks', lazy='dynamic',
|
|
order_by='ImageUpdateCheck.checked_at.desc()'))
|
|
|