|
| 1 | +""" |
| 2 | +Seed guid_sis_map Table |
| 3 | +======================== |
| 4 | +Creates the guid_sis_map table and populates it with ~20 demo mappings |
| 5 | +for POC/demo purposes. Maps real Student_GUIDs to fake SIS IDs. |
| 6 | +""" |
| 7 | + |
| 8 | +import psycopg2 |
| 9 | +from psycopg2.extras import RealDictCursor |
| 10 | +from .db_config import DB_CONFIG |
| 11 | + |
| 12 | + |
| 13 | +def seed_guid_sis_map(): |
| 14 | + """Create guid_sis_map table and seed with demo data.""" |
| 15 | + connection = psycopg2.connect( |
| 16 | + host=DB_CONFIG['host'], |
| 17 | + user=DB_CONFIG['user'], |
| 18 | + password=DB_CONFIG['password'], |
| 19 | + dbname=DB_CONFIG['database'], |
| 20 | + port=DB_CONFIG['port'], |
| 21 | + cursor_factory=RealDictCursor |
| 22 | + ) |
| 23 | + cursor = connection.cursor() |
| 24 | + |
| 25 | + # Create table |
| 26 | + cursor.execute(""" |
| 27 | + CREATE TABLE IF NOT EXISTS guid_sis_map ( |
| 28 | + student_guid TEXT PRIMARY KEY, |
| 29 | + sis_id TEXT NOT NULL |
| 30 | + ); |
| 31 | + """) |
| 32 | + print("✓ guid_sis_map table created/verified") |
| 33 | + |
| 34 | + # Pick ~20 random GUIDs from student_level_with_predictions |
| 35 | + cursor.execute(""" |
| 36 | + SELECT "Student_GUID" |
| 37 | + FROM student_level_with_predictions |
| 38 | + ORDER BY RANDOM() |
| 39 | + LIMIT 20 |
| 40 | + """) |
| 41 | + guids = [row['Student_GUID'] for row in cursor.fetchall()] |
| 42 | + |
| 43 | + if not guids: |
| 44 | + print("✗ No students found in student_level_with_predictions") |
| 45 | + cursor.close() |
| 46 | + connection.close() |
| 47 | + return False |
| 48 | + |
| 49 | + # Clear existing demo data and insert fresh mappings |
| 50 | + cursor.execute("DELETE FROM guid_sis_map") |
| 51 | + |
| 52 | + for i, guid in enumerate(guids, start=100001): |
| 53 | + sis_id = f"BSC-{i}" |
| 54 | + cursor.execute( |
| 55 | + "INSERT INTO guid_sis_map (student_guid, sis_id) VALUES (%s, %s)", |
| 56 | + (guid, sis_id) |
| 57 | + ) |
| 58 | + |
| 59 | + connection.commit() |
| 60 | + print(f"✓ Seeded {len(guids)} GUID → SIS ID mappings (BSC-100001 .. BSC-{100000 + len(guids)})") |
| 61 | + |
| 62 | + # Verify |
| 63 | + cursor.execute("SELECT COUNT(*) AS count FROM guid_sis_map") |
| 64 | + count = cursor.fetchone()['count'] |
| 65 | + print(f"✓ Verified: {count} records in guid_sis_map") |
| 66 | + |
| 67 | + cursor.close() |
| 68 | + connection.close() |
| 69 | + return True |
| 70 | + |
| 71 | + |
| 72 | +if __name__ == "__main__": |
| 73 | + print("=" * 60) |
| 74 | + print("SEEDING guid_sis_map TABLE") |
| 75 | + print("=" * 60) |
| 76 | + seed_guid_sis_map() |
0 commit comments