Skip to content

Commit

Permalink
Rename spectrum to access_url; closes SIMPLE-AstroDB#477
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-rodriguez committed Apr 19, 2024
1 parent 1e6e954 commit 57c6001
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions scripts/updates/update_spectra_colnames.py
Original file line number Diff line number Diff line change
@@ -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/')
2 changes: 1 addition & 1 deletion simple/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57c6001

Please sign in to comment.