refactor: large codebase cleanup - consolidate schemas, migrate to Drizzle ORM, extract frontend components, modernize Docker builds
Build & Deploy / build-and-push (discord-gateway) (push) Failing after 2m22s
Build & Deploy / build-and-push (backend) (push) Failing after 3m22s
Build & Deploy / build-and-push (proxy) (push) Successful in 1m36s
Build & Deploy / deploy (push) Skipped
Build & Deploy / build-and-push (discord-gateway) (push) Failing after 2m22s
Build & Deploy / build-and-push (backend) (push) Failing after 3m22s
Build & Deploy / build-and-push (proxy) (push) Successful in 1m36s
Build & Deploy / deploy (push) Skipped
- Consolidate all DB schema definitions into packages/shared as single source of truth - Migrate backend from raw SQL to Drizzle ORM across all modules - Extract frontend inline UI into separate component files - Refactor discord-gateway circuitBreaker into conversationState + moderationState - Convert messageStore to Proxy singleton pattern - Add validateBody/validateQuery middleware + Zod schemas for API endpoints - Modernize Docker builds with multi-stage + pnpm deploy - Migrate CI/CD from deployment to image-based pipeline - Remove 60+ unused/dead files (~15K lines) - Update color scheme from sky-blue to teal-cyan - Move DB connection management to @bete/shared/database Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
63f21513bd
commit
5802d02e29
223 files changed
+11499
-13350
No files matched your search
@@ -0,0 +1,76 @@
|
||||
import { createChildLogger, type Logger } from "@bete/shared/logger";
|
||||
import { and, desc, eq, isNull, or, type SQL, sql } from "drizzle-orm";
|
||||
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
|
||||
import type * as schema from "../../shared/database/schema.js";
|
||||
import { messagesTable } from "../../shared/database/schema.js";
|
||||
import type { MessageRecord } from "../message-capture/types.js";
|
||||
import { channelOrThreadCondition } from "./messagesCrud.js";
|
||||
|
||||
// ─── MessagesSearch Class ─────────────────────────────────────────────────────
|
||||
|
||||
export class MessagesSearch {
|
||||
private logger: Logger;
|
||||
|
||||
constructor(
|
||||
private db: NodePgDatabase<typeof schema>,
|
||||
_parentLogger?: Logger,
|
||||
) {
|
||||
this.logger = createChildLogger("messages-search");
|
||||
}
|
||||
|
||||
async searchMessages(input: {
|
||||
query: string;
|
||||
channelId?: string;
|
||||
guildId?: string;
|
||||
limit?: number;
|
||||
}): Promise<MessageRecord[]> {
|
||||
this.logger.debug({ query: input.query }, "searchMessages entry");
|
||||
try {
|
||||
const { query, channelId, guildId, limit = 20 } = input;
|
||||
|
||||
const searchPattern = `%${query}%`;
|
||||
const conditions: (SQL | undefined)[] = [
|
||||
isNull(messagesTable.deleted_at),
|
||||
];
|
||||
|
||||
if (guildId) {
|
||||
conditions.push(eq(messagesTable.guild_id, guildId));
|
||||
}
|
||||
|
||||
if (channelId) {
|
||||
conditions.push(channelOrThreadCondition(channelId));
|
||||
}
|
||||
|
||||
conditions.push(
|
||||
or(
|
||||
sql`lower(${messagesTable.content}) LIKE ${searchPattern}`,
|
||||
sql`lower(${messagesTable.edited_content}) LIKE ${searchPattern}`,
|
||||
),
|
||||
);
|
||||
|
||||
const validConditions = conditions.filter(
|
||||
(c): c is SQL => c !== undefined,
|
||||
);
|
||||
|
||||
const rows = await this.db
|
||||
.select()
|
||||
.from(messagesTable)
|
||||
.where(and(...validConditions))
|
||||
.orderBy(desc(messagesTable.created_at))
|
||||
.limit(limit);
|
||||
|
||||
return rows as MessageRecord[];
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
{
|
||||
query: input.query,
|
||||
channelId: input.channelId,
|
||||
guildId: input.guildId,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
},
|
||||
"Failed to search messages",
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user