“shubhamdhamal” commited on
Commit
e39db35
·
1 Parent(s): a8e65d3

Rollback transaction after failed operations before retrying

Browse files
Files changed (1) hide show
  1. start.sh +4 -1
start.sh CHANGED
@@ -19,7 +19,6 @@ python -c "
19
  from web_app import create_app
20
  from web_app.models import db, User
21
  from config import Config
22
- import sqlalchemy
23
 
24
  print(f'SECRET_KEY set: {bool(Config.SECRET_KEY)}')
25
  print(f'IS_PRODUCTION: {Config.IS_PRODUCTION}')
@@ -34,12 +33,16 @@ with app.app_context():
34
  print(f'✅ Database working ({user_count} users)')
35
  except Exception as check_error:
36
  print(f'Database needs setup: {str(check_error)[:100]}')
 
 
37
  try:
38
  # Try to create tables
39
  db.create_all()
40
  print('✅ Database schema created!')
41
  except Exception as create_error:
42
  error_msg = str(create_error)
 
 
43
  # If error is just 'already exists', check if database actually works
44
  if 'already exists' in error_msg.lower():
45
  print('⚠️ Create returned already exists error, testing database...')
 
19
  from web_app import create_app
20
  from web_app.models import db, User
21
  from config import Config
 
22
 
23
  print(f'SECRET_KEY set: {bool(Config.SECRET_KEY)}')
24
  print(f'IS_PRODUCTION: {Config.IS_PRODUCTION}')
 
33
  print(f'✅ Database working ({user_count} users)')
34
  except Exception as check_error:
35
  print(f'Database needs setup: {str(check_error)[:100]}')
36
+ db.session.rollback() # Clear any failed transaction
37
+
38
  try:
39
  # Try to create tables
40
  db.create_all()
41
  print('✅ Database schema created!')
42
  except Exception as create_error:
43
  error_msg = str(create_error)
44
+ db.session.rollback() # Rollback failed transaction
45
+
46
  # If error is just 'already exists', check if database actually works
47
  if 'already exists' in error_msg.lower():
48
  print('⚠️ Create returned already exists error, testing database...')