1ST
This commit is contained in:
141
backend/create_sample_data.py
Normal file
141
backend/create_sample_data.py
Normal file
@@ -0,0 +1,141 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Create sample todo data for testing"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from dotenv import load_dotenv
|
||||
import pymysql
|
||||
from datetime import datetime, timedelta
|
||||
import uuid
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
def create_sample_todos():
|
||||
"""Create sample todo items for testing"""
|
||||
print("=" * 60)
|
||||
print("Creating Sample Todo Data")
|
||||
print("=" * 60)
|
||||
|
||||
db_config = {
|
||||
'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'),
|
||||
'charset': 'utf8mb4'
|
||||
}
|
||||
|
||||
try:
|
||||
connection = pymysql.connect(**db_config)
|
||||
cursor = connection.cursor()
|
||||
|
||||
# Sample todos data
|
||||
sample_todos = [
|
||||
{
|
||||
'title': '完成網站改版設計稿',
|
||||
'description': '設計新版網站的主要頁面布局,包含首頁、產品頁面和聯絡頁面',
|
||||
'status': 'DOING',
|
||||
'priority': 'HIGH',
|
||||
'due_date': (datetime.now() + timedelta(days=7)).date(),
|
||||
'creator_ad': '92367',
|
||||
'creator_display_name': 'ymirliu 陸一銘',
|
||||
'creator_email': 'ymirliu@panjit.com.tw',
|
||||
'starred': True
|
||||
},
|
||||
{
|
||||
'title': '資料庫效能優化',
|
||||
'description': '優化主要查詢語句,提升系統響應速度',
|
||||
'status': 'NEW',
|
||||
'priority': 'URGENT',
|
||||
'due_date': (datetime.now() + timedelta(days=3)).date(),
|
||||
'creator_ad': '92367',
|
||||
'creator_display_name': 'ymirliu 陸一銘',
|
||||
'creator_email': 'ymirliu@panjit.com.tw',
|
||||
'starred': False
|
||||
},
|
||||
{
|
||||
'title': 'API 文檔更新',
|
||||
'description': '更新所有 API 介面文檔,補充新增的端點說明',
|
||||
'status': 'DOING',
|
||||
'priority': 'MEDIUM',
|
||||
'due_date': (datetime.now() + timedelta(days=10)).date(),
|
||||
'creator_ad': 'test',
|
||||
'creator_display_name': '測試使用者',
|
||||
'creator_email': 'test@panjit.com.tw',
|
||||
'starred': False
|
||||
},
|
||||
{
|
||||
'title': '使用者測試回饋整理',
|
||||
'description': '整理上週使用者測試的所有回饋意見,並分類處理',
|
||||
'status': 'BLOCKED',
|
||||
'priority': 'LOW',
|
||||
'due_date': (datetime.now() + timedelta(days=15)).date(),
|
||||
'creator_ad': 'test',
|
||||
'creator_display_name': '測試使用者',
|
||||
'creator_email': 'test@panjit.com.tw',
|
||||
'starred': True
|
||||
},
|
||||
{
|
||||
'title': '系統安全性檢查',
|
||||
'description': '對系統進行全面的安全性檢查,確保沒有漏洞',
|
||||
'status': 'NEW',
|
||||
'priority': 'URGENT',
|
||||
'due_date': (datetime.now() + timedelta(days=2)).date(),
|
||||
'creator_ad': '92367',
|
||||
'creator_display_name': 'ymirliu 陸一銘',
|
||||
'creator_email': 'ymirliu@panjit.com.tw',
|
||||
'starred': False
|
||||
}
|
||||
]
|
||||
|
||||
created_count = 0
|
||||
|
||||
for todo in sample_todos:
|
||||
todo_id = str(uuid.uuid4())
|
||||
|
||||
sql = """
|
||||
INSERT INTO todo_item
|
||||
(id, title, description, status, priority, due_date, created_at, creator_ad, creator_display_name, creator_email, starred)
|
||||
VALUES
|
||||
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
|
||||
values = (
|
||||
todo_id,
|
||||
todo['title'],
|
||||
todo['description'],
|
||||
todo['status'],
|
||||
todo['priority'],
|
||||
todo['due_date'],
|
||||
datetime.now(),
|
||||
todo['creator_ad'],
|
||||
todo['creator_display_name'],
|
||||
todo['creator_email'],
|
||||
todo['starred']
|
||||
)
|
||||
|
||||
cursor.execute(sql, values)
|
||||
created_count += 1
|
||||
print(f"[OK] Created todo: {todo['title']} (ID: {todo_id[:8]}...)")
|
||||
|
||||
connection.commit()
|
||||
|
||||
print(f"\n[SUCCESS] Created {created_count} sample todos successfully!")
|
||||
|
||||
# Show summary
|
||||
cursor.execute("SELECT COUNT(*) FROM todo_item")
|
||||
total_count = cursor.fetchone()[0]
|
||||
print(f"[INFO] Total todos in database: {total_count}")
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Failed to create sample data: {str(e)}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_sample_todos()
|
Reference in New Issue
Block a user