summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-12-11 20:10:58 +0100
committerDaniel Friesel <derf@finalrewind.org>2022-12-11 20:10:58 +0100
commit5de6dfb4e1712c1afea94a3f1ff813e96f0d40e2 (patch)
treeb6745f5eff0a9559666a0c9914d50c9dfda05359
parenta325c23ff9b5d1dc84482dfb199a70699da2f9a8 (diff)
database: refactor schema/iris version check
-rw-r--r--lib/Travelynx/Command/database.pm24
1 files changed, 5 insertions, 19 deletions
diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm
index 256820b..55b79e9 100644
--- a/lib/Travelynx/Command/database.pm
+++ b/lib/Travelynx/Command/database.pm
@@ -14,27 +14,13 @@ has description => 'Initialize or upgrade database layout';
has usage => sub { shift->extract_usage };
-sub get_iris_version {
- my ($db) = @_;
- my $version;
-
- eval { $version = $db->select( 'schema_version', ['iris'] )->hash->{iris}; };
- if ($@) {
-
- # If it failed, the version table does not exist -> run setup first.
- return undef;
- }
- return $version;
-}
-
sub get_schema_version {
- my ($db) = @_;
+ my ( $db, $key ) = @_;
my $version;
- eval {
- $version
- = $db->select( 'schema_version', ['version'] )->hash->{version};
- };
+ $key //= 'version';
+
+ eval { $version = $db->select( 'schema_version', [$key] )->hash->{$key}; };
if ($@) {
# If it failed, the version table does not exist -> run setup first.
@@ -1430,7 +1416,7 @@ sub migrate_db {
exit(1);
}
- my $iris_version = get_iris_version($db);
+ my $iris_version = get_schema_version( $db, 'iris' );
say "Found IRIS station database v${iris_version}";
if ( $iris_version eq $Travel::Status::DE::IRIS::Stations::VERSION ) {
say 'Station database is up-to-date';