From 57c600189931e3f368162b8ecf5002e0271ed650 Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Fri, 19 Apr 2024 13:58:21 -0400 Subject: [PATCH] Rename spectrum to access_url; closes #477 --- scripts/updates/update_spectra_colnames.py | 22 ++++++++++++++++++++++ simple/schema.py | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 scripts/updates/update_spectra_colnames.py diff --git a/scripts/updates/update_spectra_colnames.py b/scripts/updates/update_spectra_colnames.py new file mode 100644 index 000000000..a89df5320 --- /dev/null +++ b/scripts/updates/update_spectra_colnames.py @@ -0,0 +1,22 @@ +"""Script to update a column name in the database""" + +import sqlalchemy as sa +from astrodb_utils import load_astrodb +from simple.schema import REFERENCE_TABLES + +# Establish connection to database +db = load_astrodb("SIMPLE.sqlite", recreatedb=True, reference_tables=REFERENCE_TABLES) + +# Perform column rename +with db.engine.connect() as conn: + conn.execute(sa.text('ALTER TABLE Spectra RENAME COLUMN spectrum TO access_url;')) + conn.commit() + +# Reflect table changes, because of the ALTER commands +db = load_astrodb('SIMPLE.sqlite', recreatedb=False, reference_tables=REFERENCE_TABLES) + +# Inspect change +db.query(db.Spectra).limit(10).table() + +# Save changes +db.save_database('data/') \ No newline at end of file diff --git a/simple/schema.py b/simple/schema.py index eedc2c59c..f047cd949 100644 --- a/simple/schema.py +++ b/simple/schema.py @@ -326,7 +326,7 @@ class Spectra(Base): primary_key=True, ) # Data - spectrum = Column(String(1000), nullable=False) # URL of spectrum location + access_url = Column(String(1000), nullable=False) # URL of spectrum location original_spectrum = Column( String(1000) ) # URL of original spectrum location, if applicable