Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
50a6753
Add SQLite post mappings for wp_mobile_cache
oguzkocer Oct 16, 2025
61fc706
Add unit tests for SQLite post mappings
oguzkocer Oct 16, 2025
fe99eb0
Add Repository pattern for database operations in wp_mobile_cache
oguzkocer Oct 17, 2025
3b73a66
Add upsert method to PostRepository for atomic insert/update operations
oguzkocer Oct 18, 2025
c9c28ff
Add site_id to post database structure
oguzkocer Oct 18, 2025
5efdb26
Add sites table migration and foreign key constraint
oguzkocer Oct 18, 2025
825481f
Add Repository pattern design documentation
oguzkocer Oct 18, 2025
e67b521
Introduce RowId type and replace SiteId with DbSite
oguzkocer Oct 18, 2025
9e4e16b
Split QueryExecutor and TransactionManager traits for type-level tran…
oguzkocer Oct 18, 2025
e4737f3
Rename site_id to db_site_id for consistency
oguzkocer Oct 18, 2025
d637f2c
Document term_relationships design and add reorganization prompt
oguzkocer Oct 18, 2025
73b416e
Implement term relationships normalization
oguzkocer Oct 19, 2025
e7e8415
Add cache freshness tracking with last_fetched_at
oguzkocer Oct 21, 2025
1bd73c6
Reorganize documentation into focused topic-specific files
oguzkocer Oct 22, 2025
2ec502a
Add comprehensive test suite for PostRepository
oguzkocer Oct 22, 2025
5a93204
Consolidate test helpers by migrating to rstest fixtures
oguzkocer Oct 22, 2025
932b10f
Increase the migration count in WordPressApiCacheTest
oguzkocer Oct 22, 2025
56df719
Consolidate post insertion logic into single upsert method
oguzkocer Oct 22, 2025
306b34b
Remove InsertIntoDb trait
oguzkocer Oct 22, 2025
0074ac1
Remove Repository trait
oguzkocer Oct 22, 2025
0e95f58
Update documentation to reflect consolidated post insertion logic
oguzkocer Oct 22, 2025
f757fd7
Temporarily remove wp_mobile_cache documentation
oguzkocer Oct 22, 2025
f394d19
Remove unnecessary comment from DbSite
oguzkocer Oct 22, 2025
2b467cd
Add From<String> and From<&str> implementations for TaxonomyType
oguzkocer Oct 22, 2025
4126780
Remove unused test helpers and redundant test
oguzkocer Oct 23, 2025
84ca651
Refactor test infrastructure to use centralized TestContext
oguzkocer Oct 23, 2025
5b94704
Complete TestContext migration and simplify fixture structure
oguzkocer Oct 23, 2025
063d5ff
Rename test_helpers to test_fixtures for consistency
oguzkocer Oct 23, 2025
b07d467
Remove unused query methods from PostRepository
oguzkocer Oct 23, 2025
c185b06
Remove redundant tests from posts mapping
oguzkocer Oct 23, 2025
fe6c03e
Remove DbEntity trait and centralize table names in repositories
oguzkocer Oct 23, 2025
1c1699c
Enforce transaction requirement for sync_terms_for_object
oguzkocer Oct 23, 2025
130f2ac
Enforce term loading via type-safe PostTerms parameter
oguzkocer Oct 23, 2025
5ef887c
Refactor term loading to use generic repository pattern
oguzkocer Oct 23, 2025
eeecf14
Fix term relationships to use WordPress object IDs instead of SQLite …
oguzkocer Oct 23, 2025
ed75851
Enforce PostBuilder pattern and improve test ergonomics
oguzkocer Oct 23, 2025
0b45606
Add with_post_id() builder method for PostId convenience
oguzkocer Oct 23, 2025
df41e51
Replace for loops with functional programming patterns
oguzkocer Oct 23, 2025
af55ccf
Refactor tests to use repository instances from test context
oguzkocer Oct 23, 2025
1cb3bf5
Combine duplicate round-trip tests into parameterized test
oguzkocer Oct 23, 2025
5c857b3
Improve timestamp assertion with proper date parsing
oguzkocer Oct 23, 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