Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
096aa13
Add SQLite post mappings for wp_mobile_cache
oguzkocer Oct 16, 2025
a0a2750
Add unit tests for SQLite post mappings
oguzkocer Oct 16, 2025
007d1df
Add Repository pattern for database operations in wp_mobile_cache
oguzkocer Oct 17, 2025
de670e7
Add upsert method to PostRepository for atomic insert/update operations
oguzkocer Oct 18, 2025
3b406cb
Add site_id to post database structure
oguzkocer Oct 18, 2025
6081f4b
Add sites table migration and foreign key constraint
oguzkocer Oct 18, 2025
2bcc245
Add Repository pattern design documentation
oguzkocer Oct 18, 2025
d0641fc
Introduce RowId type and replace SiteId with DbSite
oguzkocer Oct 18, 2025
483b318
Split QueryExecutor and TransactionManager traits for type-level tran…
oguzkocer Oct 18, 2025
86b0212
Rename site_id to db_site_id for consistency
oguzkocer Oct 18, 2025
4b73e8a
Document term_relationships design and add reorganization prompt
oguzkocer Oct 18, 2025
e0efc56
Implement term relationships normalization
oguzkocer Oct 19, 2025
a7d7b19
Add cache freshness tracking with last_fetched_at
oguzkocer Oct 21, 2025
f59ecfe
Reorganize documentation into focused topic-specific files
oguzkocer Oct 22, 2025
2e3830f
Add comprehensive test suite for PostRepository
oguzkocer Oct 22, 2025
25dc745
Consolidate test helpers by migrating to rstest fixtures
oguzkocer Oct 22, 2025
5658bda
Increase the migration count in WordPressApiCacheTest
oguzkocer Oct 22, 2025
f564bb7
Consolidate post insertion logic into single upsert method
oguzkocer Oct 22, 2025
a6abe51
Remove InsertIntoDb trait
oguzkocer Oct 22, 2025
acc8285
Remove Repository trait
oguzkocer Oct 22, 2025
0b6894e
Update documentation to reflect consolidated post insertion logic
oguzkocer Oct 22, 2025
19dc688
Temporarily remove wp_mobile_cache documentation
oguzkocer Oct 22, 2025
41ef762
Remove unnecessary comment from DbSite
oguzkocer Oct 22, 2025
75ae8e9
Add From<String> and From<&str> implementations for TaxonomyType
oguzkocer Oct 22, 2025
3395d21
Remove unused test helpers and redundant test
oguzkocer Oct 23, 2025
88ffcfb
Refactor test infrastructure to use centralized TestContext
oguzkocer Oct 23, 2025
2da33f4
Complete TestContext migration and simplify fixture structure
oguzkocer Oct 23, 2025
168a309
Rename test_helpers to test_fixtures for consistency
oguzkocer Oct 23, 2025
661aab6
Remove unused query methods from PostRepository
oguzkocer Oct 23, 2025
8b6bcff
Remove redundant tests from posts mapping
oguzkocer Oct 23, 2025
695be1d
Remove DbEntity trait and centralize table names in repositories
oguzkocer Oct 23, 2025
ee9edcb
Enforce transaction requirement for sync_terms_for_object
oguzkocer Oct 23, 2025
8766216
Enforce term loading via type-safe PostTerms parameter
oguzkocer Oct 23, 2025
55ba1a1
Refactor term loading to use generic repository pattern
oguzkocer Oct 23, 2025
f95d045
Fix term relationships to use WordPress object IDs instead of SQLite …
oguzkocer Oct 23, 2025
8f33f0c
Enforce PostBuilder pattern and improve test ergonomics
oguzkocer Oct 23, 2025
9cf8b7f
Add with_post_id() builder method for PostId convenience
oguzkocer Oct 23, 2025
a281955
Replace for loops with functional programming patterns
oguzkocer Oct 23, 2025
351aecb
Refactor tests to use repository instances from test context
oguzkocer Oct 23, 2025
777a93e
Combine duplicate round-trip tests into parameterized test
oguzkocer Oct 23, 2025
5c54f9b
Improve timestamp assertion with proper date parsing
oguzkocer Oct 23, 2025
3a4e862
Move mapping tests to repository module
oguzkocer Oct 24, 2025
8b03f03
Add InTransaction marker trait for compile-time transaction enforcement
oguzkocer Oct 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class WordPressApiCacheTest {

@Test
fun testThatMigrationsWork() = runTest {
assertEquals(2, WordPressApiCache().performMigrations())
assertEquals(3, WordPressApiCache().performMigrations())
}

@Test
Expand Down
18 changes: 18 additions & 0 deletions wp_api/src/taxonomies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ impl Display for TaxonomyType {
}
}

impl From<&str> for TaxonomyType {
fn from(s: &str) -> Self {
match s {
"category" => Self::Category,
"post_tag" => Self::PostTag,
"nav_menu" => Self::NavMenu,
"wp_pattern_category" => Self::WpPatternCategory,
_ => Self::Custom(s.to_string()),
}
}
}

impl From<String> for TaxonomyType {
fn from(s: String) -> Self {
Self::from(s.as_str())
}
}

#[derive(
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, uniffi::Enum,
)]
Expand Down
6 changes: 6 additions & 0 deletions wp_mobile_cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ default = ["rusqlite/bundled"]

[dependencies]
rusqlite = { version = "0.37.0", features = ["hooks"] }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
uniffi = { workspace = true }
wp_api = { path = "../wp_api" }

[dev-dependencies]
chrono = { workspace = true }
rstest = "0.18"
22 changes: 0 additions & 22 deletions wp_mobile_cache/migrations/0001-create-posts-table.sql

This file was deleted.

4 changes: 4 additions & 0 deletions wp_mobile_cache/migrations/0001-create-sites-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE `sites` (
-- Internal DB field (auto-incrementing)
`id` INTEGER PRIMARY KEY AUTOINCREMENT
) STRICT;
64 changes: 64 additions & 0 deletions wp_mobile_cache/migrations/0002-create-posts-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
CREATE TABLE `posts_edit_context` (
-- Internal DB field (auto-incrementing)
`rowid` INTEGER PRIMARY KEY AUTOINCREMENT,

-- Site identifier (foreign key to sites table)
`db_site_id` INTEGER NOT NULL REFERENCES sites(id) ON DELETE CASCADE,

-- Top-level non-nullable fields
`id` INTEGER NOT NULL,
`date` TEXT NOT NULL,
`date_gmt` TEXT NOT NULL,
`link` TEXT NOT NULL,
`modified` TEXT NOT NULL,
`modified_gmt` TEXT NOT NULL,
`slug` TEXT NOT NULL,
`status` TEXT NOT NULL,
`post_type` TEXT NOT NULL,
`password` TEXT NOT NULL,
`template` TEXT NOT NULL,

-- Top-level optional fields
`permalink_template` TEXT,
`generated_slug` TEXT,
`author` INTEGER,
`featured_media` INTEGER,
`sticky` INTEGER,
`parent` INTEGER,
`menu_order` INTEGER,

-- Optional enums (stored as TEXT)
`comment_status` TEXT,
`ping_status` TEXT,
`format` TEXT,

-- Complex optional fields (JSON)
`meta` TEXT,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be handled in a relationship table in a subsequent PR.


-- Nested: guid (guid is non-optional, but guid.raw is optional)
`guid_raw` TEXT,
`guid_rendered` TEXT NOT NULL,

-- Nested: title (title is non-optional, but title.raw is optional)
`title_raw` TEXT,
`title_rendered` TEXT NOT NULL,

-- Nested: content (content is non-optional, but some fields are optional)
`content_raw` TEXT,
`content_rendered` TEXT NOT NULL,
`content_protected` INTEGER,
`content_block_version` INTEGER,

-- Nested: excerpt (entire struct is optional)
`excerpt_raw` TEXT,
`excerpt_rendered` TEXT,
`excerpt_protected` INTEGER,

-- Client-side cache metadata: when this post was last fetched from the WordPress API
`last_fetched_at` TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),

FOREIGN KEY (db_site_id) REFERENCES sites(id) ON DELETE CASCADE
) STRICT;

CREATE UNIQUE INDEX idx_posts_edit_context_unique_db_site_id_and_id ON posts_edit_context(db_site_id, id);
CREATE INDEX idx_posts_edit_context_db_site_id ON posts_edit_context(db_site_id);
14 changes: 0 additions & 14 deletions wp_mobile_cache/migrations/0002-create-users-table.sql

This file was deleted.

31 changes: 31 additions & 0 deletions wp_mobile_cache/migrations/0003-create-term-relationships.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE TABLE `term_relationships` (
-- Internal DB field (auto-incrementing)
`rowid` INTEGER PRIMARY KEY AUTOINCREMENT,

-- Site identifier (foreign key to sites table)
`db_site_id` INTEGER NOT NULL,

-- Object identifier (rowid of post/page/nav_menu_item/etc)
-- Note: No FK constraint since this can reference different tables
`object_id` INTEGER NOT NULL,

-- WordPress term ID
`term_id` INTEGER NOT NULL,

-- Taxonomy type ('category', 'post_tag', or custom taxonomy)
`taxonomy_type` TEXT NOT NULL,

FOREIGN KEY (db_site_id) REFERENCES sites(id) ON DELETE CASCADE
) STRICT;

-- Prevent duplicate associations (same object can't have same term twice in same taxonomy)
CREATE UNIQUE INDEX idx_term_relationships_unique
ON term_relationships(db_site_id, object_id, term_id, taxonomy_type);

-- Query: "Find all objects with taxonomy X and term Y"
CREATE INDEX idx_term_relationships_by_term
ON term_relationships(db_site_id, taxonomy_type, term_id);

-- Query: "Find all terms for object X" (used in joins when reading posts)
CREATE INDEX idx_term_relationships_by_object
ON term_relationships(db_site_id, object_id);
Loading