admin frontend elkezdése, járművek tisztázása, frontend fejleszts
This commit is contained in:
31
backend/scripts/check_constraint.py
Normal file
31
backend/scripts/check_constraint.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""Check and create the CheckConstraint for vehicle.assets table."""
|
||||
from app.database import engine_sync
|
||||
from sqlalchemy import text
|
||||
|
||||
with engine_sync.connect() as conn:
|
||||
# Check if constraint exists
|
||||
result = conn.execute(
|
||||
text("""
|
||||
SELECT conname, pg_get_constraintdef(oid)
|
||||
FROM pg_constraint
|
||||
WHERE conrelid = 'vehicle.assets'::regclass
|
||||
AND contype = 'c'
|
||||
""")
|
||||
).fetchall()
|
||||
print('Constraints on vehicle.assets:')
|
||||
for row in result:
|
||||
print(f' {row[0]}: {row[1]}')
|
||||
|
||||
if not result:
|
||||
print('No CheckConstraint found - creating it now...')
|
||||
conn.execute(
|
||||
text("""
|
||||
ALTER TABLE vehicle.assets
|
||||
ADD CONSTRAINT ck_asset_vin_or_plate_required
|
||||
CHECK (vin IS NOT NULL OR license_plate IS NOT NULL)
|
||||
""")
|
||||
)
|
||||
conn.commit()
|
||||
print('CheckConstraint created successfully!')
|
||||
else:
|
||||
print('CheckConstraint already exists.')
|
||||
Reference in New Issue
Block a user