CREATE TABLE logs (
	id           TEXT PRIMARY KEY,
	level        TEXT NOT NULL DEFAULT 'info' CHECK(level IN ('debug','info','warn','error')),
	source       TEXT NOT NULL DEFAULT '',
	entity_id    TEXT NOT NULL DEFAULT '',
	execution_id TEXT NOT NULL DEFAULT '',
	message      TEXT NOT NULL,
	metadata     TEXT NOT NULL DEFAULT '{}',
	created_at   TEXT NOT NULL
);

CREATE INDEX idx_logs_level ON logs(level);
CREATE INDEX idx_logs_source ON logs(source);
CREATE INDEX idx_logs_created_at ON logs(created_at);
