docs(captain-memory): document intentional omission of secondary FKs
This commit is contained in:
parent
cae1ae36d6
commit
ca662a528c
@ -1,6 +1,12 @@
|
|||||||
class CreateCaptainContactMemories < ActiveRecord::Migration[7.1]
|
class CreateCaptainContactMemories < ActiveRecord::Migration[7.1]
|
||||||
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
||||||
def change
|
def change
|
||||||
|
# NOTE: source_conversation_id, source_unit_id, source_inbox_id, and
|
||||||
|
# superseded_by_id are intentionally plain bigints WITHOUT foreign keys.
|
||||||
|
# Rationale: preserve memory history and audit trail even if the source
|
||||||
|
# conversation/unit/inbox is hard-deleted (LGPD compliance for customer
|
||||||
|
# data retention, see spec §10). Application code must tolerate
|
||||||
|
# dangling references gracefully.
|
||||||
create_table :captain_contact_memories do |t|
|
create_table :captain_contact_memories do |t|
|
||||||
t.references :account, null: false, foreign_key: true
|
t.references :account, null: false, foreign_key: true
|
||||||
t.references :contact, null: false, foreign_key: true
|
t.references :contact, null: false, foreign_key: true
|
||||||
|
|||||||
@ -107,13 +107,13 @@ CREATE TABLE captain_contact_memories (
|
|||||||
confidence FLOAT NOT NULL,
|
confidence FLOAT NOT NULL,
|
||||||
scope VARCHAR NOT NULL DEFAULT 'global',
|
scope VARCHAR NOT NULL DEFAULT 'global',
|
||||||
embedding vector(1536),
|
embedding vector(1536),
|
||||||
source_conversation_id BIGINT REFERENCES conversations(id),
|
source_conversation_id BIGINT,
|
||||||
source_unit_id BIGINT REFERENCES captain_units(id),
|
source_unit_id BIGINT,
|
||||||
source_inbox_id BIGINT REFERENCES inboxes(id),
|
source_inbox_id BIGINT,
|
||||||
expires_at TIMESTAMP,
|
expires_at TIMESTAMP,
|
||||||
last_verified_at TIMESTAMP NOT NULL,
|
last_verified_at TIMESTAMP NOT NULL,
|
||||||
superseded_at TIMESTAMP,
|
superseded_at TIMESTAMP,
|
||||||
superseded_by_id BIGINT REFERENCES captain_contact_memories(id),
|
superseded_by_id BIGINT,
|
||||||
deleted_at TIMESTAMP,
|
deleted_at TIMESTAMP,
|
||||||
metadata JSONB NOT NULL DEFAULT '{}',
|
metadata JSONB NOT NULL DEFAULT '{}',
|
||||||
created_at TIMESTAMP NOT NULL,
|
created_at TIMESTAMP NOT NULL,
|
||||||
@ -121,6 +121,8 @@ CREATE TABLE captain_contact_memories (
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Observação — FKs secundárias:** `source_conversation_id`, `source_unit_id`, `source_inbox_id` e `superseded_by_id` são `BIGINT` simples sem `FOREIGN KEY`. Manter a referência mesmo após o registro de origem ser hard-deletado é essencial pra auditoria LGPD (§10) e pra relatórios históricos por unidade (§3 decisão 3). App-layer precisa tratar referências órfãs graciosamente.
|
||||||
|
|
||||||
### 6.2 Índices
|
### 6.2 Índices
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user