Update entrypoint.sh

This commit is contained in:
2025-06-23 09:46:21 +02:00
parent 405cc83ba1
commit 7ec3027410

View File

@@ -71,8 +71,25 @@ with app.app_context():
# Create admin user if it doesn't exist
print('Creating admin user...')
try:
admin = User.query.filter_by(email='administrator@docupulse.com').first()
if not admin:
# Check for admin user by both username and email to avoid constraint violations
admin_by_username = User.query.filter_by(username='administrator').first()
admin_by_email = User.query.filter_by(email='administrator@docupulse.com').first()
if admin_by_username and admin_by_email and admin_by_username.id == admin_by_email.id:
print('Admin user already exists (found by both username and email).')
print('Admin credentials:')
print('Email: administrator@docupulse.com')
print('Password: changeme')
elif admin_by_username or admin_by_email:
print('WARNING: Found partial admin user data:')
if admin_by_username:
print(f' - Found user with username "administrator" (ID: {admin_by_username.id})')
if admin_by_email:
print(f' - Found user with email "administrator@docupulse.com" (ID: {admin_by_email.id})')
print('Admin credentials:')
print('Email: administrator@docupulse.com')
print('Password: changeme')
else:
print('Admin user not found, creating new admin user...')
admin = User(
username='administrator',
@@ -93,15 +110,26 @@ with app.app_context():
print('Admin credentials:')
print('Email: administrator@docupulse.com')
print('Password: changeme')
except Exception as e:
except Exception as commit_error:
db.session.rollback()
log_error('Failed to commit admin user creation', e)
raise
else:
print('Admin user already exists.')
if 'duplicate key value violates unique constraint' in str(commit_error):
print('WARNING: Admin user creation failed due to duplicate key constraint.')
print('This might indicate a race condition or the user was created by another process.')
print('Checking for existing admin user again...')
# Check again after the failed commit
admin_by_username = User.query.filter_by(username='administrator').first()
admin_by_email = User.query.filter_by(email='administrator@docupulse.com').first()
if admin_by_username or admin_by_email:
print('Admin user now exists (likely created by another process).')
print('Admin credentials:')
print('Email: administrator@docupulse.com')
print('Password: changeme')
else:
log_error('Admin user creation failed and user still not found', commit_error)
raise
else:
log_error('Failed to commit admin user creation', commit_error)
raise
except Exception as e:
log_error('Error during admin user creation/check', e)
raise