Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local files based sync #249

Merged
merged 2 commits into from
Sep 23, 2024
Merged

Local files based sync #249

merged 2 commits into from
Sep 23, 2024

Conversation

cloverich
Copy link
Owner

@cloverich cloverich commented Sep 23, 2024

Re-works the database back to a cache over files - the app now layers over a directory of markdown files where the files are the source of truth. This is how the app was originally envisioned / previously implemented (see #61).

This requires the directory to adhere to the following structure:

/_attachments # <-- all images, file links, etc, go here
/my_journal_1
  016e4a96-ff00-763d-83c3-2e6c9a7a287b.md
  016e4a97-4d20-7e0d-b2dd-8bdaa65ed981.md
/my_journal_2
  # ...

Screenshot of my notes directory:
Screenshot 2024-09-23 at 8 27 31 AM

Note title, tags, and create / updated timestamps are stored in front matter:

---
title: Re-importing exported Chronicles directory
tags: thesixthprototype
createdAt: 2024-09-17T01:45:39.880Z
updatedAt: 2024-09-17T20:41:46.532Z
---

The filename serves as the unique identifier for the document; id format will be revisted in #248 , support for additional front matter (at least, preserving its existence) will be reviewed in #127

I have a lot of mixed feelings about the work in this PR. It makes everything about the application more complicated. It hopefully sets up better for default sync (via iCloud, whatever), but there remains a few more tasks to make it a bit more robust. It will likely have some issues, but should be safer than syncing the database (What I was doing previously -- I wasn't using the app daily until recently). At this point going to roll with it a while and make some more incremental changes, as documented in #247

- basically a temporary bit of code so I can conver the Chronicles database to an index over files, where files are the source of truth; this is how older versions of chronicles worked.
@cloverich cloverich changed the title (WIP) Import export Local files based sync Sep 23, 2024

export interface GetDocumentResponse {
id: string;
createdAt: string;
updatedAt: string;
title?: string;
content: string;
journalId: string;
journal: string;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-worked the journal references from id to name, to support reconciling synced journal names with what's in the cache. Probably this was a mistake, but I tied up the change too tightly to all the other work; may re-visit this in the near future.

updatedAt: new Date().toISOString(),
});

// todo: dumb; revert to having documents reference id instead of name
this.db
.prepare("update documents set journal = :newName where journal = :name")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of where changing the reference to be by name results in extra work; obviously dumb design here. But works for now....

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This importer is a legacy of the prior file-based format, which IIRC was something like:

/my_journal
  2024/
    /04
      /01
# etc

Because I did not use front-matter, and because the ctime / mtime could be changed by bulk file moves / zip / cloud sync, I relied on the filename for the date of the note. I think it makes sense to leave this until I'm satisfied with the final format of Chronicles data, and especially until I introduce markdown importers.

This large set of changes converts the database from source of truth to a cache over the file system,
where the source of truth is a directory of markdown files + attachments. This returns Chronicles
persistence to an earlier design and should improve its ability to work via file-system cloud-sync,
like iCloud, out of the box.

It introduces a "Sync" operation and numerous supporting changes, along with a few semi-related
improvements or fixes uncovered while hacking away. There remain a few related changes to ensure
the sync experience is smooth; as is the user would need to manually sync when switching devices.
@cloverich cloverich merged commit 82c3b71 into master Sep 23, 2024
2 checks passed
@cloverich cloverich deleted the import_export branch September 23, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve "Document loading error" screen
1 participant