refactor(db): consolidate ~20+ databases into 2 (mana_platform + mana_sync)

Mirrors the frontend unification (single IndexedDB) on the backend.
All services now use pgSchema() for isolation within one shared database,
enabling cross-schema JOINs, simplified ops, and zero DB setup for new apps.

- Migrate 7 services from pgTable() to pgSchema(): mana-user (usr),
  mana-media (media), todo, traces, presi, uload, cards
- Update all DATABASE_URLs in .env.development, docker-compose, configs
- Rewrite init-db scripts for 2 databases + 12 schemas
- Rewrite setup-databases.sh for consolidated architecture
- Update shared-drizzle-config default to mana_platform
- Update CLAUDE.md with new database architecture docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-02 14:31:28 +02:00
parent b1a5c95f1d
commit 3ea28b9065
44 changed files with 311 additions and 346 deletions

View file

@ -17,7 +17,7 @@ import { GuideService } from './services/guide';
const PORT = parseInt(process.env.PORT || '3026', 10);
const DB_URL =
process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/traces';
process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/mana_platform';
const LLM_URL = process.env.MANA_LLM_URL || 'http://localhost:3025';
const SEARCH_URL = process.env.MANA_SEARCH_URL || 'http://localhost:3021';
const CORS_ORIGINS = (process.env.CORS_ORIGINS || 'http://localhost:5173').split(',');

View file

@ -1,5 +1,5 @@
import {
pgTable,
pgSchema,
uuid,
text,
doublePrecision,
@ -10,6 +10,8 @@ import {
uniqueIndex,
} from 'drizzle-orm/pg-core';
export const tracesSchema = pgSchema('traces');
// ============================================
// Enums
// ============================================
@ -49,7 +51,7 @@ export const guideStatusEnum = pgEnum('guide_status', ['generating', 'ready', 'e
// Tables
// ============================================
export const locations = pgTable(
export const locations = tracesSchema.table(
'locations',
{
id: uuid('id').defaultRandom().primaryKey(),
@ -80,7 +82,7 @@ export const locations = pgTable(
]
);
export const cities = pgTable(
export const cities = tracesSchema.table(
'cities',
{
id: uuid('id').defaultRandom().primaryKey(),
@ -94,7 +96,7 @@ export const cities = pgTable(
(table) => [uniqueIndex('cities_name_country_code_idx').on(table.name, table.countryCode)]
);
export const cityVisits = pgTable(
export const cityVisits = tracesSchema.table(
'city_visits',
{
id: uuid('id').defaultRandom().primaryKey(),
@ -115,7 +117,7 @@ export const cityVisits = pgTable(
]
);
export const places = pgTable(
export const places = tracesSchema.table(
'places',
{
id: uuid('id').defaultRandom().primaryKey(),
@ -139,7 +141,7 @@ export const places = pgTable(
]
);
export const pois = pgTable(
export const pois = tracesSchema.table(
'pois',
{
id: uuid('id').defaultRandom().primaryKey(),
@ -165,7 +167,7 @@ export const pois = pgTable(
]
);
export const guides = pgTable(
export const guides = tracesSchema.table(
'guides',
{
id: uuid('id').defaultRandom().primaryKey(),
@ -190,7 +192,7 @@ export const guides = pgTable(
]
);
export const guidePois = pgTable(
export const guidePois = tracesSchema.table(
'guide_pois',
{
id: uuid('id').defaultRandom().primaryKey(),