forked from SIMPLE-AstroDB/SIMPLE-db
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename spectrum to access_url; closes SIMPLE-AstroDB#477
- Loading branch information
1 parent
1e6e954
commit 57c6001
Showing
2 changed files
with
23 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters