zipperer / migrate_database_with_michael

0 stars 0 forks source link

Draft tables that will allow us to query a presentation id and get all the timestamped entries for that presentation #43

Closed zipperer closed 5 months ago

zipperer commented 5 months ago

Want to ask for presentation id 3192 and get

presentation_id | entry_timestamp     | book        | chapter | verse
3192            | 2014-01-05 00:01:49 | Romans      | 8       | 29
...
3192            | 2014-01-05 01:31:00 | 2Corinthians| 10      | 16
zipperer commented 5 months ago

Copy as of 20240124_12_54 20240124 Table Structure Proposal.pdf

Google Drive source 20240124 Table Structure Proposal

note: will soon change privileges on file to share

zipperer commented 5 months ago
-- Table from "Title Text File" – the list of presentation numbers and titles
-- tablename: presentation'
id   | date_encoded | day    | morning_or_night | presentation_date | title
3192 | SM010514     | Sunday | morning          | 2014-01-05        | Predestination: Increase …
3913 | SN010514     | Sunday | night            | 2014-01-05        | Doctrine of the Devil: ...

-- Table from directory of files ‘Bible Display App CSV txt files’ after split days with two sessions into two files.
-- tablename: file_for_timestamp_entries_book_chapter_verse
id  | filename                  | file_date  | morning_or_night
330 | BDA 2014 1 05_morning.txt | 2014-01-05 | morning
331 | BDA 2014 1 05_night.txt   | 2014-01-05 | night

-- Table from content of files in directory of files ‘Bible Display App CSV txt files’ after 
--  (a) split days with two sessions into two files and 
--  (b) convert to csv.
-- tablename: timestamped_entry_book_chapter_verse

filename                  | filename_date | morning_or_night | entry_timestamp     | book     | chapter | verse
BDA 2014 1 05_morning.txt | 2014-01-05    | morning          | 2014-01-05 00:01:49 | Romans   | 8       | 29
BDA 2014 1 05_night.txt   | 2014-01-05    | night            | 2014-01-05 00:04:45 | 1Timothy | 4       | 1

-- This query gives way to get all timestamped entries for a given presentation id

SELECT presentation.id, entry.entry_timestamp, entry.book, entry.chapter, entry.verse,
FROM timestamped_entry_book_chapter_verse as entry 
JOIN presentation ON entry.filename_date = presentation.presentation_date
WHERE entry.morning_or_night = presentation.morning_or_night AND
      presentation.id = 3192
ORDER BY entry.entry_timestamp

This version duplicates information across two tables:

Could either:

If we use id from file_for_timestamp_entries_book_chapter_verse in timestamped_entry_book_chapter_verse, then we will need to populate the table with a script that:

i.e. script will need to connect to db, e.g. by python and psycopg2

zipperer commented 5 months ago

Could either:

  • get rid of table file_for_timestamp_entries_book_chapter_verse
  • use id from file_for_timestamp_entries_book_chapter_verse in timestamped_entry_book_chapter_verse

First option is simpler. Second option saves space since it reduces how often db stores filenames.

I plan to do first option first in the spirit of 'make it more complex only when you need to'/'delay optimization'.

zipperer commented 5 months ago
-- Table from "Title Text File" – the list of presentation numbers and titles
-- tablename: presentation'
id   | date_encoded | day    | morning_or_night | presentation_date | title
3192 | SM010514     | Sunday | morning          | 2014-01-05        | Predestination: Increase …
3913 | SN010514     | Sunday | night            | 2014-01-05        | Doctrine of the Devil: ...

39 provides a table like this

zipperer commented 5 months ago
-- Table from content of files in directory of files ‘Bible Display App CSV txt files’ after 
--  (a) split days with two sessions into two files and 
--  (b) convert to csv.
-- tablename: timestamped_entry_book_chapter_verse

filename                  | filename_date | morning_or_night | entry_timestamp     | book     | chapter | verse
BDA 2014 1 05_morning.txt | 2014-01-05    | morning          | 2014-01-05 00:01:49 | Romans   | 8       | 29
BDA 2014 1 05_night.txt   | 2014-01-05    | night            | 2014-01-05 00:04:45 | 1Timothy | 4       | 1

To get a table like this I propose:

zipperer commented 5 months ago

A future issue will implement this table and the process to populate it.