-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_wallet_last_refresh.py
More file actions
33 lines (28 loc) · 1.16 KB
/
add_wallet_last_refresh.py
File metadata and controls
33 lines (28 loc) · 1.16 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
import datetime
from app import app, db
from models import AIAgent
import sqlalchemy as sa
def run():
"""
Adds wallet_last_refresh column to AIAgent table
"""
with app.app_context():
print("Adding wallet_last_refresh column to AIAgent table...")
# Check if column exists
inspector = sa.inspect(db.engine)
columns = [col['name'] for col in inspector.get_columns('ai_agent')]
if 'wallet_last_refresh' not in columns:
# Add the column
with db.engine.begin() as conn:
conn.execute(sa.text('ALTER TABLE ai_agent ADD COLUMN wallet_last_refresh TIMESTAMP'))
print("Column added successfully!")
# Update existing records with current time
now = datetime.datetime.utcnow()
AIAgent.query.update({AIAgent.wallet_last_refresh: now})
db.session.commit()
print(f"Updated {AIAgent.query.count()} existing records with current timestamp")
else:
print("Column wallet_last_refresh already exists, skipping...")
print("Migration complete!")
if __name__ == "__main__":
run()