File size: 2,135 Bytes
74bf532 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | """
Database migration: Add ROR support for multi-institution comparison
"""
from sqlalchemy import text
from uraas.database import Item, SessionLocal, engine
def migrate():
print("Adding ROR columns to items table...")
with engine.connect() as conn:
try:
# Add ror column
conn.execute(text("ALTER TABLE items ADD COLUMN ror VARCHAR(128)"))
conn.execute(text("CREATE INDEX ix_items_ror ON items(ror)"))
print("β Added ror column and index")
except Exception as e:
if (
"duplicate column" in str(e).lower()
or "already exists" in str(e).lower()
):
print("β ROR column already exists")
else:
print(f"Error: {e}")
try:
# Add institution column if not exists
conn.execute(text("ALTER TABLE items ADD COLUMN institution VARCHAR(255)"))
print("β Added institution column")
except Exception as e:
if (
"duplicate column" in str(e).lower()
or "already exists" in str(e).lower()
):
print("β Institution column already exists")
else:
print(f"Error: {e}")
conn.commit()
# Set default ROR for UNILAG papers
print("\nSetting default ROR for existing UNILAG papers...")
session = SessionLocal()
try:
unilag_ror = "https://ror.org/03qcnxw14"
count = (
session.query(Item)
.filter(Item.ror.is_(None))
.update(
{Item.ror: unilag_ror, Item.institution: "University of Lagos"},
synchronize_session=False,
)
)
session.commit()
print(f"β Updated {count} papers with UNILAG ROR")
finally:
session.close()
print("\nMigration complete!")
print("\nNext steps:")
print("1. Add Comparator tab to dashboard")
print("2. Test multi-institution comparison")
print("3. Add more institutions to database")
if __name__ == "__main__":
migrate()
|