-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_db.py
More file actions
55 lines (43 loc) · 1.75 KB
/
create_db.py
File metadata and controls
55 lines (43 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
"""
Database creation script for Dustbin
Creates all tables with the correct schema including new columns
"""
from app import app, db, User, Paste
def create_database():
"""Create all database tables"""
print("Creating database tables...")
with app.app_context():
# Drop all tables first (if they exist)
db.drop_all()
print("Dropped existing tables")
# Create all tables with new schema
db.create_all()
print("Created new tables with updated schema")
# Verify tables were created
inspector = db.inspect(db.engine)
tables = inspector.get_table_names()
print(f"Created tables: {tables}")
# Check columns for paste table
if 'paste' in tables:
columns = [col['name'] for col in inspector.get_columns('paste')]
print(f"Paste table columns: {columns}")
# Verify required columns exist
required_columns = ['id', 'title', 'content', 'language', 'created_at',
'expires_at', 'is_public', 'user_id', 'views']
missing_columns = [col for col in required_columns if col not in columns]
if missing_columns:
print(f"❌ Missing columns: {missing_columns}")
return False
else:
print("✅ All required columns present")
print("✅ Database created successfully!")
return True
if __name__ == "__main__":
success = create_database()
if success:
print("\n🎉 Database is ready!")
print("You can now run: python app.py")
else:
print("\n❌ Database creation failed!")
exit(1)