fix: split message type into normalized label + raw code
The scraper was writing a normalized type label ("text"/"unknown"/...) into
Message.type, but the column was Integer, so the storage layer coerced it to
NULL and the raw code was only recoverable from raw_json. Align with design
§4.3, which specifies two fields: `type` (normalized enum) and `type_raw`
(original code).
- Model (Message): type -> String(32) normalized label; add type_raw Integer
for the raw upstream type code.
- Scraper: _normalize_message sets both `type` (label) and `type_raw`
(coerced int from messageType/type); _is_divider now checks raw -2.
- Repos: type_raw joins _INT_FIELDS; Message.type stored as-is (string).
- Migration 96975050fa79: add type_raw + alter type Integer->String(32),
wrapped in batch_alter_table so it runs on SQLite and MySQL.
- env.py: enable render_as_batch on SQLite (dev/test) for portable batch
migrations; MySQL still uses direct ALTER.
- Tests updated end-to-end (scraper, repos, models).
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -179,7 +179,8 @@ async def test_message_natural_pk():
|
||||
owner_account_id="wxid_staff",
|
||||
talker_id="wxid_abc",
|
||||
is_send=False,
|
||||
type=1,
|
||||
type="text",
|
||||
type_raw=1,
|
||||
text="hello",
|
||||
timestamp=1700000000000,
|
||||
)
|
||||
@@ -195,6 +196,8 @@ async def test_message_natural_pk():
|
||||
assert fetched.text == "hello"
|
||||
assert fetched.timestamp == 1700000000000
|
||||
assert fetched.is_send is False
|
||||
assert fetched.type == "text"
|
||||
assert fetched.type_raw == 1
|
||||
finally:
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user