Add `arrived` attribute (file creation timestamp) to books table. master
authorChris Jaekl <chris@localhost>
Mon, 24 Jan 2022 04:23:30 +0000 (23:23 -0500)
committerChris Jaekl <chris@localhost>
Mon, 24 Jan 2022 04:23:30 +0000 (23:23 -0500)
book.rb
store.rb

diff --git a/book.rb b/book.rb
index ea650249a9ac6c8c120e72824dce646276bc4c9f..2b93f4b574c9c45738a3a95a2c0b4f1697083d1c 100644 (file)
--- a/book.rb
+++ b/book.rb
@@ -12,6 +12,7 @@ class Book
   @@DC_NS_URL = 'http://purl.org/dc/elements/1.1/'
   @@SERIES_AND_VOLUME_REGEX = /^([A-Z]+)([0-9]+(\.[0-9]+)?)$/
 
+  attr_accessor :arrived
   attr_accessor :author
   attr_accessor :classification_id
   attr_accessor :cover
@@ -224,6 +225,8 @@ class Book
       scan_pdf!(file_name)
     end
 
+    @arrived = File.ctime(file_name)
+
     @classification_id = @store.find_classification(@author.grouping, File.basename(file_name, '.*'))
 
     # TODO:  Fix horrible hard-coded strings and paths
index f1b7fba68400465c102db20ba886e60c77d96207..1a33ca3868340e0cadf9f770d0e1517a3a57711d 100644 (file)
--- a/store.rb
+++ b/store.rb
@@ -71,6 +71,7 @@ EOS
 <<EOS
       CREATE TABLE Books (
         id             INTEGER PRIMARY KEY,
+        arrived        TIMESTAMP,
         author         INTEGER REFERENCES Authors(id),
         classification INTEGER REFERENCES Classifications(id),
         cover          INTEGER,
@@ -321,14 +322,14 @@ EOS
   end
 
   def store_book(book)
-    sql = "INSERT INTO Books (id, author, classification, cover, description, language, path, series, title, volume) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);"
+    sql = "INSERT INTO Books (id, arrived, author, classification, cover, description, language, path, series, title, volume) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);"
 
     book_id = next_id('book_id')
 
     author_id = store_author(book.author)
     (efs_id, mime_type) = store_cover(book)
 
-    args = [book_id, author_id, book.classification_id, efs_id, book.description, book.language, book.path, book.series_id, book.title, book.volume]
+    args = [book_id, book.arrived, author_id, book.classification_id, efs_id, book.description, book.language, book.path, book.series_id, book.title, book.volume]
 
     begin
       rs = @conn.exec_params(sql, args)