Skip to content

Commit

Permalink
Allow force option when schema version matches
Browse files Browse the repository at this point in the history
Since the alert types are determined dynamically from the protocol definition, the status schema may need to be updated even if nothing changed in the scripts, when the dish software adds a new alert type (which just happened, say hello to the "mast_not_near_vertical" alert). This allows the manual override for that case, not just schema version downgrade.
  • Loading branch information
sparky8512 committed Feb 16, 2021
1 parent a4bf2d1 commit 18829bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 12 additions & 4 deletions dish_grpc_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
case and how you would rather see it. This only affects a few fields, since
most of the useful data is not in arrays.
Note that using this script to record the alert_detail group mode will tend to
trip schema-related errors when new alert types are added to the dish
software. The error message will include something like "table status has no
column named alert_foo", where "foo" is the newly added alert type. To work
around this rare occurrence, you can pass the -f option to force a schema
update. Alternatively, instead of using the alert_detail mode, you can use the
alerts bitmask in the status group.
NOTE: The Starlink user terminal does not include time values with its
history or status data, so this script uses current system time to compute
the timestamps it writes into the database. It is recommended to run this
Expand Down Expand Up @@ -52,8 +60,8 @@ def parse_args():
group.add_argument("-f",
"--force",
action="store_true",
help="Override database schema downgrade protection; may result in "
"discarded data")
help="Force schema conversion, even if it results in downgrade; may "
"result in discarded data")
group.add_argument("-k",
"--skip-query",
action="store_true",
Expand Down Expand Up @@ -139,7 +147,7 @@ def cb_add_bulk(bulk, count, timestamp, counter):
gstate.sql_conn.commit()
except sqlite3.OperationalError as e:
# these are not necessarily fatal, but also not much can do about
logging.error("Unexpected error from database, discarding %s rows: %s", rows_written, e)
logging.error("Unexpected error from database, discarding data: %s", e)
rc = 1
else:
if opts.verbose:
Expand All @@ -152,7 +160,7 @@ def ensure_schema(opts, conn, context):
cur = conn.cursor()
cur.execute("PRAGMA user_version")
version = cur.fetchone()
if version and version[0] == SCHEMA_VERSION:
if version and version[0] == SCHEMA_VERSION and not opts.force:
cur.close()
return 0

Expand Down
2 changes: 2 additions & 0 deletions starlink_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
*alerts*.
: **alert_unexpected_location** : Alert corresponding with bit 3 (bit mask 8)
in *alerts*.
: **alert_mast_not_near_vertical** : Alert corresponding with bit 4 (bit mask
16) in *alerts*.
General history data
--------------------
Expand Down

0 comments on commit 18829bd

Please sign in to comment.