From d9f91bc0e7ed551aaa882db58c0b6e9777dc4f64 Mon Sep 17 00:00:00 2001 From: Graham Date: Mon, 9 Oct 2023 21:39:01 +0100 Subject: [PATCH] Add file name and timestamp to artifact_sources table Signed-off-by: Graham --- .../openrs2/archive/client/ClientImporter.kt | 25 ++++++++++++++++--- .../V25__client_source_file_metadata.sql | 5 ++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 archive/src/main/resources/org/openrs2/archive/migrations/V25__client_source_file_metadata.sql diff --git a/archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt b/archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt index 688aad803f..021cba43dc 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt @@ -52,6 +52,7 @@ import java.time.ZoneOffset import java.util.jar.JarInputStream import java.util.jar.JarOutputStream import java.util.jar.Pack200 +import kotlin.io.path.getLastModifiedTime @Singleton public class ClientImporter @Inject constructor( @@ -72,12 +73,26 @@ public class ClientImporter @Inject constructor( } logger.info { "Importing $path" } - import(parse(buf), name, description, url) + import( + parse(buf), + name, + description, + url, + path.fileName.toString(), + path.getLastModifiedTime().toInstant() + ) } } } - public suspend fun import(artifact: Artifact, name: String?, description: String?, url: String?) { + public suspend fun import( + artifact: Artifact, + name: String?, + description: String?, + url: String?, + fileName: String, + timestamp: Instant + ) { database.execute { connection -> importer.prepare(connection) @@ -85,14 +100,16 @@ public class ClientImporter @Inject constructor( connection.prepareStatement( """ - INSERT INTO artifact_sources (blob_id, name, description, url) - VALUES (?, ?, ?, ?) + INSERT INTO artifact_sources (blob_id, name, description, url, file_name, timestamp) + VALUES (?, ?, ?, ?, ?, ?) """.trimIndent() ).use { stmt -> stmt.setLong(1, id) stmt.setString(2, name) stmt.setString(3, description) stmt.setString(4, url) + stmt.setString(5, fileName) + stmt.setObject(6, timestamp.atOffset(ZoneOffset.UTC), Types.TIMESTAMP_WITH_TIMEZONE) stmt.execute() } diff --git a/archive/src/main/resources/org/openrs2/archive/migrations/V25__client_source_file_metadata.sql b/archive/src/main/resources/org/openrs2/archive/migrations/V25__client_source_file_metadata.sql new file mode 100644 index 0000000000..55b2bb4153 --- /dev/null +++ b/archive/src/main/resources/org/openrs2/archive/migrations/V25__client_source_file_metadata.sql @@ -0,0 +1,5 @@ +-- @formatter:off + +ALTER TABLE artifact_sources + ADD COLUMN file_name TEXT NULL, + ADD COLUMN timestamp TIMESTAMPTZ NULL;