ext/web W6: schema migrate and SQLite FTS5 search

Add db.migrate with _marqdo_migrations, db.fts/search (bm25), and gold
covering published filters plus a comments table convention.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-28 11:07:24 +08:00
1 parent a900fd550f
commit e3b0314382
8 files changed
+498 -5

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
---
title: web db W6 smoke — migrate / FTS5 / published filter
import web:ext/web/web.mq.md
---
# main
*store = > web.db url="sqlite:web-fixtures/data/w6-smoke.db"*
`steps` =
| 版本 | SQL |
|------|-----|
| 1 | CREATE TABLE IF NOT EXISTS posts (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, body TEXT, status TEXT NOT NULL DEFAULT 'draft') |
| 2 | CREATE TABLE IF NOT EXISTS comments (id INTEGER PRIMARY KEY AUTOINCREMENT, post_id INTEGER NOT NULL, body TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending') |
*m1 = > `store`.migrate steps=`steps`*
*a1 = m1[^applied]*
*n1 = > len value=`a1`*
1. `n1` == 2
> print text=migrate-ok
2. *
> print text=migrate-fail
*m2 = > `store`.migrate steps=`steps`*
*a2 = m2[^applied]*
*n2 = > len value=`a2`*
1. `n2` == 0
> print text=migrate-idempotent-ok
2. *
> print text=migrate-idempotent-fail
`rows` =
| title | body | status |
|-------|------|--------|
| Alpha note | hello world search | published |
| Beta draft | secret draft body | draft |
| Gamma published | another hello | published |
> `store`.insert table=posts rows=`rows`
`pub` =
| 字段 | 操作 | 值 |
|------|------|-----|
| status | = | published |
*pc = > `store`.count table="posts" where=`pub`*
1. `pc` == 2
> print text=published-filter-ok
2. *
> print text=published-filter-fail
`comments` =
| post_id | body | status |
|---------|------|--------|
| 1 | nice post | approved |
| 1 | spam | pending |
> `store`.insert table=comments rows=`comments`
*cc = > `store`.count table="comments"*
1. `cc` == 2
> print text=comments-ok
2. *
> print text=comments-fail
> `store`.fts table="posts" columns="title,body"
*hit = > `store`.search table="posts" q="hello" limit=10*
*hn = hit[^count]*
1. `hn` >= 1
> print text=fts-ok
2. *
> print text=fts-fail
*rows2 = hit[^rows]*
*first = rows2[^1]*
*ft = first[^title]*
1. `ft`
> print text=fts-row-ok
2. *
> print text=fts-row-fail
+26
View File
@@ -1937,6 +1937,32 @@ fn ext_web_upload_live() {
let _ = child.wait();
}
#[test]
fn ext_web_db_w6_smoke() {
// W6: versioned migrate, FTS5 search, published filter + comments table.
let status = Command::new("cargo")
.args(["build", "-p", "marqdo_plugin_web"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.status()
.expect("build web plugin");
assert!(status.success(), "failed to build marqdo_plugin_web");
let db = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/ext/web-fixtures/data/w6-smoke.db");
for suffix in ["", "-wal", "-shm"] {
let _ = std::fs::remove_file(format!("{}{}", db.display(), suffix));
}
assert_out(
"tests/ext/web-db-w6-smoke.mq.md",
"migrate-ok
migrate-idempotent-ok
published-filter-ok
comments-ok
fts-ok
fts-row-ok",
);
}
#[test]
fn ext_web_db_w2_smoke() {
// W2 data layer: transactions, connection pooling, pagination, query