Fix migration

This commit is contained in:
2025-08-25 18:49:33 +09:00
parent 6886ba15c8
commit 8e3f7024a2
12 changed files with 2254 additions and 20 deletions

View File

@ -107,19 +107,19 @@ def check_database_connectivity():
# rogdb DB接続確認
target_conn = psycopg2.connect(**ROGDB_DB)
target_cursor = target_conn.cursor()
target_cursor.execute("SELECT COUNT(*) FROM rog_gpscheckin")
target_cursor.execute("SELECT COUNT(*) FROM gps_checkins")
target_count = target_cursor.fetchone()[0]
print(f"✅ rogdb DB接続成功: rog_gpscheckin {target_count}")
print(f"✅ rogdb DB接続成功: gps_checkins {target_count}")
# 移行先テーブル構造確認
target_cursor.execute("""
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'rog_gpscheckin'
WHERE table_name = 'gps_checkins'
ORDER BY ordinal_position
""")
target_columns = target_cursor.fetchall()
print("📋 rog_gpscheckinテーブル構造:")
print("📋 gps_checkinsテーブル構造:")
for col_name, col_type in target_columns:
print(f" {col_name}: {col_type}")
@ -212,7 +212,7 @@ def backup_existing_data(target_cursor):
target_cursor.execute("SELECT COUNT(*) FROM rog_member")
member_count = target_cursor.fetchone()[0]
target_cursor.execute("SELECT COUNT(*) FROM rog_gpscheckin")
target_cursor.execute("SELECT COUNT(*) FROM gps_checkins")
checkin_count = target_cursor.fetchone()[0]
# Location2025データ数も確認
@ -228,7 +228,7 @@ def backup_existing_data(target_cursor):
print(f" rog_entry: {entry_count} 件 (保護対象)")
print(f" rog_team: {team_count} 件 (保護対象)")
print(f" rog_member: {member_count} 件 (保護対象)")
print(f" rog_gpscheckin: {checkin_count} 件 (移行対象)")
print(f" gps_checkins: {checkin_count} 件 (移行対象)")
if entry_count > 0 or team_count > 0 or member_count > 0:
print("✅ 既存のcore application dataが検出されました。これらは保護されます。")
@ -265,7 +265,7 @@ def migrate_gps_data(source_cursor, target_cursor):
target_cursor.execute("""
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'rog_gpscheckin'
WHERE table_name = 'gps_checkins'
ORDER BY ordinal_position
""")
target_columns = [row[0] for row in target_cursor.fetchall()]
@ -370,7 +370,7 @@ def migrate_gps_data(source_cursor, target_cursor):
columns_str = ', '.join(final_columns)
target_cursor.execute(f"""
INSERT INTO rog_gpscheckin ({columns_str})
INSERT INTO gps_checkins ({columns_str})
VALUES ({placeholders})
""", final_values)
@ -406,7 +406,7 @@ def main():
print("=" * 60)
print("GPS記録データ移行スクリプト (既存データ保護版)")
print("=" * 60)
print("移行対象: gifuroge.gps_information → rogdb.rog_gpscheckin")
print("移行対象: gifuroge.gps_information → rogdb.gps_checkins")
print("既存データ保護: rog_entry, rog_team, rog_member, rog_location2025")
print("=" * 60)