mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
refactor: content-addressed assets, cross-channel multimodal, infra simplification (#63)
* refactor(attachment): multimodal attachment refactor with snapshot schema and storage layer - Add snapshot schema migration (0008) and update init/versions/snapshots - Add internal/attachment and internal/channel normalize for unified attachment handling - Move containerfs provider from internal/media to internal/storage - Update agent types, channel adapters (Telegram/Feishu), inbound and handlers - Add containerd snapshot lineage and local_channel tests - Regenerate sqlc, swagger and SDK * refactor(media): content-addressed asset system with unified naming - Replace asset_id foreign key with content_hash as sole identifier for bot_history_message_assets (pure soft-link model) - Remove mime, size_bytes, storage_key from DB; derive at read time via media.Resolve from actual storage - Merge migrations 0008/0009 into single 0008; keep 0001 as canonical schema - Add Docker initdb script for deterministic migration execution order - Fix cross-channel real-time image display (Telegram → WebUI SSE) - Fix message disappearing on refresh (null assets fallback) - Fix file icon instead of image preview (mime derivation from storage) - Unify AssetID → ContentHash naming across Go, Agent, and Frontend - Change storage key prefix from 4-char to 2-char for directory sharding - Add server-entrypoint.sh for Docker deployment migration handling * refactor(infra): embedded migrations, Docker simplification, and config consolidation - Embed SQL migrations into Go binary, removing shell-based migration scripts - Consolidate config files into conf/ directory (app.example.toml, app.docker.toml, app.dev.toml) - Simplify Docker setup: remove initdb.d scripts, streamline nginx config and entrypoint - Remove legacy CLI, feishu-echo commands, and obsolete incremental migration files - Update install script and docs to require sudo for one-click install - Add mise tasks for dev environment orchestration * chore: recover migrations --------- Co-authored-by: Acbox <acbox0328@gmail.com>
This commit is contained in:
@@ -277,27 +277,33 @@ CREATE TABLE IF NOT EXISTS containers (
|
||||
CREATE INDEX IF NOT EXISTS idx_containers_bot_id ON containers(bot_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS snapshots (
|
||||
id TEXT PRIMARY KEY,
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
container_id TEXT NOT NULL REFERENCES containers(container_id) ON DELETE CASCADE,
|
||||
parent_snapshot_id TEXT REFERENCES snapshots(id) ON DELETE SET NULL,
|
||||
runtime_snapshot_name TEXT NOT NULL,
|
||||
parent_runtime_snapshot_name TEXT,
|
||||
snapshotter TEXT NOT NULL,
|
||||
digest TEXT,
|
||||
source TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_snapshots_container_id ON snapshots(container_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_snapshots_parent_id ON snapshots(parent_snapshot_id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_snapshots_container_runtime_name
|
||||
ON snapshots(container_id, runtime_snapshot_name);
|
||||
CREATE INDEX IF NOT EXISTS idx_snapshots_container_created_at
|
||||
ON snapshots(container_id, created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_snapshots_runtime_name
|
||||
ON snapshots(runtime_snapshot_name);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS container_versions (
|
||||
id TEXT PRIMARY KEY,
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
container_id TEXT NOT NULL REFERENCES containers(container_id) ON DELETE CASCADE,
|
||||
snapshot_id TEXT NOT NULL REFERENCES snapshots(id) ON DELETE RESTRICT,
|
||||
snapshot_id UUID NOT NULL REFERENCES snapshots(id) ON DELETE RESTRICT,
|
||||
version INTEGER NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
UNIQUE (container_id, version)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_container_versions_container_id ON container_versions(container_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_container_versions_snapshot_id ON container_versions(snapshot_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS lifecycle_events (
|
||||
id TEXT PRIMARY KEY,
|
||||
@@ -370,39 +376,17 @@ CREATE TABLE IF NOT EXISTS bot_storage_bindings (
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bot_storage_bindings_bot_id ON bot_storage_bindings(bot_id);
|
||||
|
||||
-- media_assets: immutable media objects with dedup by content hash
|
||||
CREATE TABLE IF NOT EXISTS media_assets (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
bot_id UUID NOT NULL REFERENCES bots(id) ON DELETE CASCADE,
|
||||
storage_provider_id UUID REFERENCES storage_providers(id) ON DELETE SET NULL,
|
||||
content_hash TEXT NOT NULL,
|
||||
media_type TEXT NOT NULL,
|
||||
mime TEXT NOT NULL DEFAULT 'application/octet-stream',
|
||||
size_bytes BIGINT NOT NULL DEFAULT 0,
|
||||
storage_key TEXT NOT NULL,
|
||||
original_name TEXT,
|
||||
width INTEGER,
|
||||
height INTEGER,
|
||||
duration_ms BIGINT,
|
||||
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
CONSTRAINT media_assets_bot_hash_unique UNIQUE (bot_id, content_hash)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_media_assets_bot_id ON media_assets(bot_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_media_assets_content_hash ON media_assets(content_hash);
|
||||
|
||||
-- bot_history_message_assets: join table linking messages to media assets
|
||||
-- bot_history_message_assets: soft link (message -> content_hash only).
|
||||
-- MIME, size, storage_key are derived from storage at read time.
|
||||
CREATE TABLE IF NOT EXISTS bot_history_message_assets (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
message_id UUID NOT NULL REFERENCES bot_history_messages(id) ON DELETE CASCADE,
|
||||
asset_id UUID NOT NULL REFERENCES media_assets(id) ON DELETE CASCADE,
|
||||
role TEXT NOT NULL DEFAULT 'attachment',
|
||||
ordinal INTEGER NOT NULL DEFAULT 0,
|
||||
content_hash TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
CONSTRAINT message_asset_unique UNIQUE (message_id, asset_id)
|
||||
CONSTRAINT message_asset_content_unique UNIQUE (message_id, content_hash)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_message_assets_message_id ON bot_history_message_assets(message_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_assets_asset_id ON bot_history_message_assets(asset_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user