98 lines
3.5 KiB
Python
98 lines
3.5 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""Create test todos directly in database for testing public/private functionality"""
|
|
|
|
import pymysql
|
|
import uuid
|
|
import json
|
|
from datetime import datetime
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables
|
|
load_dotenv()
|
|
|
|
def create_test_todos():
|
|
"""Create test todos directly in database"""
|
|
try:
|
|
# Connect to database
|
|
conn = pymysql.connect(
|
|
host=os.getenv('MYSQL_HOST', 'mysql.theaken.com'),
|
|
port=int(os.getenv('MYSQL_PORT', 33306)),
|
|
user=os.getenv('MYSQL_USER', 'A060'),
|
|
password=os.getenv('MYSQL_PASSWORD', 'WLeSCi0yhtc7'),
|
|
database=os.getenv('MYSQL_DATABASE', 'db_A060')
|
|
)
|
|
|
|
cursor = conn.cursor()
|
|
|
|
# Test data
|
|
todos = [
|
|
{
|
|
'id': str(uuid.uuid4()),
|
|
'title': '公開測試任務 - ymirliu 建立',
|
|
'description': '這是一個公開任務,其他人可以看到並追蹤',
|
|
'status': 'NEW',
|
|
'priority': 'MEDIUM',
|
|
'created_at': datetime.utcnow(),
|
|
'creator_ad': '92367',
|
|
'creator_display_name': 'ymirliu 劉念蒨',
|
|
'creator_email': 'ymirliu@panjit.com.tw',
|
|
'starred': False,
|
|
'is_public': True,
|
|
'tags': json.dumps(['測試', '公開功能'])
|
|
},
|
|
{
|
|
'id': str(uuid.uuid4()),
|
|
'title': '私人測試任務 - ymirliu 建立',
|
|
'description': '這是一個私人任務,只有建立者可見',
|
|
'status': 'NEW',
|
|
'priority': 'HIGH',
|
|
'created_at': datetime.utcnow(),
|
|
'creator_ad': '92367',
|
|
'creator_display_name': 'ymirliu 劉念蒨',
|
|
'creator_email': 'ymirliu@panjit.com.tw',
|
|
'starred': True,
|
|
'is_public': False,
|
|
'tags': json.dumps(['測試', '私人功能'])
|
|
}
|
|
]
|
|
|
|
# Insert todos
|
|
for todo in todos:
|
|
sql = """INSERT INTO todo_item
|
|
(id, title, description, status, priority, created_at, creator_ad,
|
|
creator_display_name, creator_email, starred, is_public, tags)
|
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
|
|
|
|
cursor.execute(sql, (
|
|
todo['id'], todo['title'], todo['description'], todo['status'],
|
|
todo['priority'], todo['created_at'], todo['creator_ad'],
|
|
todo['creator_display_name'], todo['creator_email'],
|
|
todo['starred'], todo['is_public'], todo['tags']
|
|
))
|
|
|
|
print(f"✓ 建立 {'公開' if todo['is_public'] else '私人'} Todo: {todo['title']}")
|
|
|
|
# Commit changes
|
|
conn.commit()
|
|
print(f"\n✅ 成功建立 {len(todos)} 個測試 Todo")
|
|
|
|
# Verify the insertion
|
|
cursor.execute("SELECT id, title, is_public FROM todo_item WHERE creator_ad = '92367'")
|
|
results = cursor.fetchall()
|
|
print(f"\n📊 資料庫中的測試數據:")
|
|
for result in results:
|
|
print(f" - {result[1]} ({'公開' if result[2] else '私人'})")
|
|
|
|
cursor.close()
|
|
conn.close()
|
|
|
|
except Exception as e:
|
|
print(f"❌ 建立測試數據失敗: {str(e)}")
|
|
return False
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
create_test_todos() |