Files
rogaining_srv/check_old_entries.py
2025-08-29 09:11:20 +09:00

94 lines
3.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
"""
old_rogdb から新しいデータベースへのエントリーデータ移行スクリプト
rog_entry テーブルのデータを NewEvent2 システムに移行
"""
import os
import sys
import django
from datetime import datetime
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()
from django.db import connection
from rog.models import NewEvent2, Entry, Team, NewCategory, CustomUser
print("=== old_rogdb エントリーデータ移行 ===")
try:
# old_rogdb の rog_entry データを確認
print("old_rogdb の rog_entry データを確認中...")
with connection.cursor() as cursor:
# rog_entry テーブルの構造とデータを確認
cursor.execute("""
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'rog_entry'
ORDER BY ordinal_position;
""")
columns = cursor.fetchall()
print("✅ rog_entry テーブル構造:")
for col_name, data_type in columns:
print(f" - {col_name}: {data_type}")
# データ件数確認
cursor.execute("SELECT COUNT(*) FROM rog_entry;")
entry_count = cursor.fetchone()[0]
print(f"✅ rog_entry データ件数: {entry_count}")
# サンプルデータ確認
cursor.execute("""
SELECT id, team_id, event_id, category_id, date,
zekken_number, zekken_label, is_active
FROM rog_entry
LIMIT 5;
""")
sample_data = cursor.fetchall()
print("\\n✅ サンプルデータ:")
for row in sample_data:
print(f" ID:{row[0]}, Team:{row[1]}, Event:{row[2]}, Category:{row[3]}, Zekken:{row[5]}")
# イベント情報の確認
cursor.execute("""
SELECT e.id, e.event_name, COUNT(re.id) as entry_count
FROM rog_newevent2 e
LEFT JOIN rog_entry re ON e.id = re.event_id
GROUP BY e.id, e.event_name
HAVING COUNT(re.id) > 0
ORDER BY entry_count DESC;
""")
event_data = cursor.fetchall()
print("\\n✅ エントリーがあるイベント:")
for event_id, event_name, count in event_data:
print(f" Event ID:{event_id} '{event_name}': {count}")
# FC岐阜イベントのエントリー確認
cursor.execute("""
SELECT re.id, re.zekken_number, re.zekken_label,
t.team_name, c.category_name
FROM rog_entry re
JOIN rog_newevent2 e ON re.event_id = e.id
JOIN rog_team t ON re.team_id = t.id
JOIN rog_newcategory c ON re.category_id = c.id
WHERE e.event_name LIKE '%FC岐阜%'
ORDER BY re.zekken_number
LIMIT 10;
""")
fc_entries = cursor.fetchall()
print("\\n✅ FC岐阜イベントのエントリー最初の10件:")
for entry_id, zekken, label, team_name, category in fc_entries:
print(f" ゼッケン{zekken}: {team_name} ({category})")
except Exception as e:
print(f"❌ エラーが発生しました: {e}")
import traceback
traceback.print_exc()