Skip to content

Commit

Permalink
Feature 335 seeps column names (#340)
Browse files Browse the repository at this point in the history
* Added latest SEEPS data to the point_stat directory

* Updated extension from .txt to .stat to METdbLoad will recognize the files

* Issue #335 update column names for SEEPS data updates

* Issue #335 changed names of SEEPS columns to reflect changes in MET

* Issue #335 add test for the changed SEEPS columns

* script that generates DB commands used to create and drop the database
  • Loading branch information
bikegeek authored Oct 11, 2024
1 parent 64d6a0c commit 02f3a00
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 8 deletions.
12 changes: 6 additions & 6 deletions METdbLoad/sql/mv_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2290,12 +2290,12 @@ CREATE TABLE line_data_seeps
obs_valid_beg DATETIME,
obs_valid_end DATETIME,
total INT UNSIGNED,
s12 DOUBLE,
s13 DOUBLE,
s21 DOUBLE,
s23 DOUBLE,
s31 DOUBLE,
s32 DOUBLE,
odfl DOUBLE,
odfh DOUBLE,
olfd DOUBLE,
olfh DOUBLE,
ohfd DOUBLE,
ohfl DOUBLE,
pf1 DOUBLE,
pf2 DOUBLE,
pf3 DOUBLE,
Expand Down
51 changes: 51 additions & 0 deletions METdbLoad/sql/scripts/db_cmds.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/bash


echo ""
echo ""
echo ""
echo "*****************"
echo " USAGE"
echo "*****************"
echo ""
echo " ***Run under BASH shell***"
echo " SET the following ENV variables: "
echo " DB_PWD - the password for the mvadmin user"
echo " DBNAME - the name of the database you wish to create/drop/load schema"
echo " MVSCHEMA - the full path and name of the mv_mysql.sql script to load the schema"
echo " Then copy and paste the appropriate command for dropping, creating, or loading the schema after running the following on the command line:"
echo ""
echo " bash db_cmd.bash "
echo ""
echo "*****************"
echo ""
echo ""
echo ""

echo ""
echo "********"
echo "Command to drop database ${DBNAME} if it exists (or error message if it doesn't exist)..."
echo "********"
echo mysql -u mvadmin -p${DB_PWD} "'drop database" ${DBNAME}"';"


echo ""
echo "********"
echo "Command to create database ${DBNAME}..."
echo "********"
echo mysql -u mvadmin -p${DB_PWD} -e "'"create database ${DBNAME}"'";

echo ""
echo "********"
echo "Command to grant privileges to ${DBNAME}..."
echo "********"
echo mysql -u mvadmin -p${DB_PWD} -e "\""GRANT INSERT, DELETE, UPDATE, INDEX, DROP ON ${DBNAME}.* to "'"mvuser"'"@"'"%"'" "\""
echo ""


echo ""
echo "********"
echo "Command to load mv_mysql.sql schema ${DBNAME}..."
echo "********"
echo mysql -u mvadmin -p${DB_PWD} ${DBNAME} "<" ${MVSCHEMA}
echo ""
9 changes: 9 additions & 0 deletions METdbLoad/sql/updates/update_for_6_0_beta6.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ ALTER TABLE line_data_orank
RENAME COLUMN climo_stdev TO obs_climo_stdev |
ADD COLUMN fcst_climo_mean DOUBLE |
ADD COLUMN fcst_climo_stdev DOUBLE |

ALTER TABLE line_data_seeps
RENAME COLUMN s12 TO odfl |
RENAME COLUMN s13 TO odfh |
RENAME COLUMN s21 TO olfd |
RENAME COLUMN s23 TO olfh |
RENAME COLUMN s31 TO ohfd |
RENAME COLUMN s32 TO ohfl |

|

DELIMITER ;
Binary file modified METdbLoad/tests/update_schema_6.0_beta6/Data/total_data.tar
Binary file not shown.
41 changes: 39 additions & 2 deletions METdbLoad/tests/update_schema_6.0_beta6/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


# Make sure the database name matches with the one you created on the database host
CONST_LOAD_DB_CMD = "use mv_mpr_orank"
TEST_DB = "mv_mpr_orank"
CONST_LOAD_DB_CMD = "use mv_mpr_orank_seeps"
TEST_DB = "mv_mpr_orank_seeps"

@pytest.fixture
def setup_db():
Expand Down Expand Up @@ -76,6 +76,7 @@ def test_db_created(setup_db):
finally:
setup_db.close()


def test_tables_created(setup_db):

# connect to the database and verify the MPR and ORANK tables exist
Expand All @@ -98,6 +99,7 @@ def test_tables_created(setup_db):
finally:
setup_db.close()


def test_mpr_columns(setup_db):
# log into the database and verify the renamed columns are in the
# list_data_mpr database table, the previous/replaced columns do NOT
Expand All @@ -123,6 +125,7 @@ def test_mpr_columns(setup_db):
finally:
setup_db.close()


def test_orank_columns(setup_db):
# log into the database and verify the renamed and new columns are in the
# list_data_orank database table, and the previous/replaced columns no longer
Expand All @@ -145,3 +148,37 @@ def test_orank_columns(setup_db):
finally:
setup_db.close()

def test_seeps_columns(setup_db):
# log into the database and verify the renamed SEEPS columns are in the
# list_data_seeps database table, and the previous/replaced columns no longer
# exist.

try:
with setup_db.cursor() as cursor:
cursor.execute(CONST_LOAD_DB_CMD)
check_columns_exist = "desc line_data_seeps;"
cursor.execute(check_columns_exist)

# Get all rows
rows = cursor.fetchall()
list_of_rows = [r[0] for r in rows]

# Verify newly renamed columns exist in the updated data
assert 'odfl' in list_of_rows
assert 'odfh' in list_of_rows
assert 'olfd' in list_of_rows
assert 'olfh' in list_of_rows
assert 'ohfd' in list_of_rows
assert 'ohfl' in list_of_rows

# Verify that remaining columns are unchanged in the updated data
assert 'pf1' in list_of_rows
assert 'pf2' in list_of_rows
assert 'pf3' in list_of_rows
assert 'pv1' in list_of_rows
assert 'pv2' in list_of_rows
assert 'pv3' in list_of_rows

finally:
setup_db.close()

0 comments on commit 02f3a00

Please sign in to comment.