xync-db 0.2.1__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xync_db-0.2.1 → xync_db-0.3.0}/PKG-INFO +1 -1
- xync_db-0.3.0/src/xync_db/migrations/models/0005_credex_del.py +42 -0
- xync_db-0.3.0/src/xync_db/migrations/models/0006_credex_orphan.py +47 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/models/__init__.py +23 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/.gitignore +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/README.md +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/pyproject.toml +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/__init__.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/config.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/enums.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/exceptions.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/graph.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/i18n.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/logo.png +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/CLAUDE.md +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/__init__.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/models/0001_initial.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/models/0002_triggers.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/models/0003_files_seed.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/models/0004_all_seed.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/models/__init__.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/models/seed/__init__.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/models/seed/a_actor_seed.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/models/seed/a_tg_seed.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/models/seed/b_htx_seed.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/migrations/models/seed/xync_files.sql +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/models/CLAUDE.md +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/py.typed +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/shared.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/typs/__init__.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/typs/db/__init__.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/typs/db/actor.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/typs/db/ad.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/typs/db/common.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/typs/db/cred.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/typs/db/order.py +0 -0
- {xync_db-0.2.1 → xync_db-0.3.0}/src/xync_db/typs/db/pm.py +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Per-CredEx delete trigger → `credexs_del` channel.
|
|
2
|
+
|
|
3
|
+
Lets a user unregister ONE credential from ONE exchange (settings/creds edit form): deleting a
|
|
4
|
+
single `credex` row reactively removes it from that exchange (mirror of `credexs_new`, which posts
|
|
5
|
+
a freshly inserted `CredEx(exid=0)`). The handler is `api.handlers.creds.credex_del`.
|
|
6
|
+
|
|
7
|
+
The default `plsql("credex")` DEL trigger (from 0002) only carried `OLD.id`, useless post-cascade.
|
|
8
|
+
We override it: emit `[person_id, ex_id, exid]` (person via the still-living parent `cred`) — exactly
|
|
9
|
+
what the handler needs to find the agent and call `acl.cred_del(exid)`.
|
|
10
|
+
|
|
11
|
+
Crucially we SKIP the notify when the parent `cred` is already gone: that's a `Cred` cascade-delete,
|
|
12
|
+
where the BEFORE-DELETE `cred_del()` trigger already snapshotted every credex into `creds_del`. Firing
|
|
13
|
+
here too would double-delete on the exchange. A standalone credex delete leaves the cred alive → notify.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from typing import ClassVar
|
|
17
|
+
|
|
18
|
+
from tortoise.migrations.migration import Migration as BaseMigration
|
|
19
|
+
from tortoise.migrations.operations import RunSQL
|
|
20
|
+
|
|
21
|
+
CREDEX_DEL_SQL = """
|
|
22
|
+
CREATE OR REPLACE FUNCTION credex_del() returns trigger as $credex_del_trg$
|
|
23
|
+
DECLARE
|
|
24
|
+
pid INT;
|
|
25
|
+
BEGIN
|
|
26
|
+
-- person via the parent cred; NULL ⇒ cred already cascade-deleted ⇒ cred_del() handled it ⇒ skip
|
|
27
|
+
SELECT person_id INTO pid FROM cred WHERE id = OLD.cred_id;
|
|
28
|
+
IF pid IS NOT NULL THEN
|
|
29
|
+
PERFORM pg_notify('credexs_del', jsonb_build_array(pid, OLD.ex_id, OLD.exid)::varchar);
|
|
30
|
+
END IF;
|
|
31
|
+
RETURN NULL;
|
|
32
|
+
END
|
|
33
|
+
$credex_del_trg$ LANGUAGE plpgsql;
|
|
34
|
+
CREATE OR REPLACE TRIGGER credex_del AFTER DELETE ON "credex" FOR EACH ROW EXECUTE FUNCTION credex_del();
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Migration(BaseMigration):
|
|
41
|
+
dependencies: ClassVar = [("models", "0004_all_seed")]
|
|
42
|
+
operations: ClassVar = [RunSQL(CREDEX_DEL_SQL)]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Per-CredEx exid-overwrite trigger → `credexs_orphan` channel.
|
|
2
|
+
|
|
3
|
+
`CredEx.upsert` keys on (cred, ex) and overwrites `exid`. When it overwrites a REAL (non-zero) exid
|
|
4
|
+
with a different value, the previously-registered credential keeps living on the exchange as an
|
|
5
|
+
orphaned duplicate (the DB no longer tracks it). We don't silently leak it: a BEFORE-UPDATE trigger
|
|
6
|
+
catches the change and emits `[person_id, ex_id, OLD.exid, OLD.cred_id]` so service-api can ask the
|
|
7
|
+
owner whether to delete the stale one (handler `api.handlers.creds.credex_orphan`, mirror of the
|
|
8
|
+
`is_you` consent flow). On "yes" the answer routes back through `CredEx.orphan_del` →
|
|
9
|
+
`credexs_orphan_del` → `credex_orphan_del` handler → `acl.cred_del(OLD.exid)` + a success/error report.
|
|
10
|
+
|
|
11
|
+
`OLD.cred_id` is in the payload because the orphan-consent question shows the credential's `detail`,
|
|
12
|
+
which the handler can't recover from `[person_id, ex_id, OLD.exid]` alone: post-overwrite the (cred,
|
|
13
|
+
ex) row already holds the NEW exid, and a person may own several creds on one exchange.
|
|
14
|
+
|
|
15
|
+
Fires ONLY on a genuine real→different overwrite:
|
|
16
|
+
- `OLD.exid <> 0` skips the normal publish (stub 0 → real exid in `credex_new`);
|
|
17
|
+
- `NEW.exid <> OLD.exid` skips no-op re-writes (parse re-saving the same exid).
|
|
18
|
+
The user re-registers immediately (the overwrite proceeds — `RETURN NEW`); orphan cleanup is async
|
|
19
|
+
and consent-gated. person via the parent cred; NULL ⇒ no owner to ask ⇒ skip.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from typing import ClassVar
|
|
23
|
+
|
|
24
|
+
from tortoise.migrations.migration import Migration as BaseMigration
|
|
25
|
+
from tortoise.migrations.operations import RunSQL
|
|
26
|
+
|
|
27
|
+
CREDEX_ORPHAN_SQL = """
|
|
28
|
+
CREATE OR REPLACE FUNCTION credex_orphan() returns trigger as $credex_orphan_trg$
|
|
29
|
+
DECLARE
|
|
30
|
+
pid INT;
|
|
31
|
+
BEGIN
|
|
32
|
+
IF OLD.exid <> 0 AND NEW.exid <> OLD.exid THEN
|
|
33
|
+
SELECT person_id INTO pid FROM cred WHERE id = OLD.cred_id;
|
|
34
|
+
IF pid IS NOT NULL THEN
|
|
35
|
+
PERFORM pg_notify('credexs_orphan', jsonb_build_array(pid, OLD.ex_id, OLD.exid, OLD.cred_id)::varchar);
|
|
36
|
+
END IF;
|
|
37
|
+
END IF;
|
|
38
|
+
RETURN NEW;
|
|
39
|
+
END
|
|
40
|
+
$credex_orphan_trg$ LANGUAGE plpgsql;
|
|
41
|
+
CREATE OR REPLACE TRIGGER credex_orphan BEFORE UPDATE ON "credex" FOR EACH ROW EXECUTE FUNCTION credex_orphan();
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class Migration(BaseMigration):
|
|
46
|
+
dependencies: ClassVar = [("models", "0005_credex_del")]
|
|
47
|
+
operations: ClassVar = [RunSQL(CREDEX_ORPHAN_SQL)]
|
|
@@ -1588,6 +1588,29 @@ class CredEx(Model):
|
|
|
1588
1588
|
credex, _ = await cls.update_or_create({"exid": exid}, cred_id=cred_id, ex_id=ex_id)
|
|
1589
1589
|
return credex
|
|
1590
1590
|
|
|
1591
|
+
@classmethod
|
|
1592
|
+
async def remove(cls, *, cred_id: int, ex_id: int) -> bool:
|
|
1593
|
+
"""ЕДИНСТВЕННЫЙ standalone-делитор CredEx (single-writer-правило): сносит строку (cred, ex).
|
|
1594
|
+
Снятие креда с ОДНОЙ биржи из формы — удаление на бирже реактивно: BEFORE/AFTER-DELETE триггер
|
|
1595
|
+
`credex_del` (миграция 0005) положит `[person_id, ex_id, exid]` в `credexs_del` → handler вызовет
|
|
1596
|
+
`acl.cred_del(exid)`. Каскадное удаление при сносе самого Cred идёт другим путём (`creds_del`)."""
|
|
1597
|
+
return bool(await cls.filter(cred_id=cred_id, ex_id=ex_id).delete())
|
|
1598
|
+
|
|
1599
|
+
@classmethod
|
|
1600
|
+
async def orphan_del(cls, *, person_id: int, ex_id: int, exid: int) -> None:
|
|
1601
|
+
"""Удалить ОСИРОТЕВШИЙ exid на бирже — после согласия владельца (web-контроллер / бот-колбэк).
|
|
1602
|
+
Перезапись exid у строки (cred, ex) на другой оставляет старый реквизит висеть на бирже дубликатом;
|
|
1603
|
+
BEFORE-UPDATE триггер `credex_orphan` (миграция 0006) ловит это и шлёт `credexs_orphan` → handler
|
|
1604
|
+
спрашивает владельца. На «да» зовут СЮДА: свой канал `credexs_orphan_del` (НЕ переиспользуем
|
|
1605
|
+
`credexs_del`) — его handler `credex_orphan_del` делает `acl.cred_del(exid)` по (person, ex) И
|
|
1606
|
+
возвращает владельцу результат (успех/ошибка) тем же Notify; у обычного `credex_del` отчёта нет,
|
|
1607
|
+
поэтому каналы разделены. Строки CredEx для старого exid уже нет, и она не нужна. Единый эмиттер,
|
|
1608
|
+
чтобы канал/полезную нагрузку не дублировать в web- и bot-зонах."""
|
|
1609
|
+
await connections.get("default").execute_query(
|
|
1610
|
+
"SELECT pg_notify('credexs_orphan_del', jsonb_build_array($1::int, $2::int, $3::bigint)::varchar)",
|
|
1611
|
+
[person_id, ex_id, exid],
|
|
1612
|
+
)
|
|
1613
|
+
|
|
1591
1614
|
class Meta:
|
|
1592
1615
|
table_description = "Credential on Exchange"
|
|
1593
1616
|
unique_together = (("ex", "exid"),)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|