Spaces:
Sleeping
Sleeping
“shubhamdhamal” commited on
Commit ·
b217afb
1
Parent(s): ad936e8
Nuclear option - DROP SCHEMA CASCADE to completely reset database
Browse files
start.sh
CHANGED
|
@@ -34,40 +34,29 @@ 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 |
-
db.session.rollback()
|
| 38 |
|
| 39 |
-
#
|
| 40 |
try:
|
| 41 |
-
print('
|
| 42 |
with db.engine.connect() as conn:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
FROM information_schema.table_constraints
|
| 47 |
-
WHERE constraint_schema = 'public'
|
| 48 |
-
AND constraint_type = 'UNIQUE'
|
| 49 |
-
\"\"\"))
|
| 50 |
-
constraints = result.fetchall()
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
conn.commit()
|
| 58 |
-
print(f' Dropped constraint: {constraint_name}')
|
| 59 |
-
except Exception as drop_error:
|
| 60 |
-
print(f' Could not drop {constraint_name}: {drop_error}')
|
| 61 |
-
conn.rollback()
|
| 62 |
-
except Exception as cleanup_error:
|
| 63 |
-
print(f'Constraint cleanup failed: {cleanup_error}')
|
| 64 |
-
|
| 65 |
-
try:
|
| 66 |
-
# Try to create tables
|
| 67 |
db.create_all()
|
| 68 |
-
print('✅ Database schema created!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
except Exception as create_error:
|
| 70 |
-
print(f'❌
|
| 71 |
raise
|
| 72 |
"
|
| 73 |
|
|
|
|
| 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 |
|
| 38 |
+
# Nuclear option: drop and recreate entire public schema
|
| 39 |
try:
|
| 40 |
+
print('Performing complete database reset...')
|
| 41 |
with db.engine.connect() as conn:
|
| 42 |
+
conn.execute(text('DROP SCHEMA public CASCADE'))
|
| 43 |
+
conn.commit()
|
| 44 |
+
print(' Schema dropped')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
conn.execute(text('CREATE SCHEMA public'))
|
| 47 |
+
conn.commit()
|
| 48 |
+
print(' Schema recreated')
|
| 49 |
+
|
| 50 |
+
# Now create all tables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
db.create_all()
|
| 52 |
+
print('✅ Database schema created successfully!')
|
| 53 |
+
|
| 54 |
+
# Verify it works
|
| 55 |
+
user_count = User.query.count()
|
| 56 |
+
print(f'✅ Verified: Database has {user_count} users')
|
| 57 |
+
|
| 58 |
except Exception as create_error:
|
| 59 |
+
print(f'❌ Database reset failed: {create_error}')
|
| 60 |
raise
|
| 61 |
"
|
| 62 |
|