mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-19 14:57:42 +02:00
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:
parent
b1a5c95f1d
commit
3ea28b9065
44 changed files with 311 additions and 346 deletions
|
|
@ -6,7 +6,7 @@ export default defineConfig({
|
|||
dialect: 'postgresql',
|
||||
dbCredentials: {
|
||||
url:
|
||||
process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/mana_analytics',
|
||||
process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/mana_platform',
|
||||
},
|
||||
schemaFilter: ['feedback'],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export function loadConfig(): Config {
|
|||
port: parseInt(env('PORT', '3064'), 10),
|
||||
databaseUrl: env(
|
||||
'DATABASE_URL',
|
||||
'postgresql://manacore:devpassword@localhost:5432/mana_analytics'
|
||||
'postgresql://manacore:devpassword@localhost:5432/mana_platform'
|
||||
),
|
||||
manaAuthUrl: env('MANA_CORE_AUTH_URL', 'http://localhost:3001'),
|
||||
manaLlmUrl: env('MANA_LLM_URL', 'http://localhost:3025'),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ export default defineConfig({
|
|||
out: './drizzle',
|
||||
dialect: 'postgresql',
|
||||
dbCredentials: {
|
||||
url: process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/mana_auth',
|
||||
url:
|
||||
process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/mana_platform',
|
||||
},
|
||||
schemaFilter: ['auth'],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -22,7 +22,10 @@ export function loadConfig(): Config {
|
|||
const env = (key: string, fallback?: string) => process.env[key] || fallback || '';
|
||||
return {
|
||||
port: parseInt(env('PORT', '3001'), 10),
|
||||
databaseUrl: env('DATABASE_URL', 'postgresql://manacore:devpassword@localhost:5432/mana_auth'),
|
||||
databaseUrl: env(
|
||||
'DATABASE_URL',
|
||||
'postgresql://manacore:devpassword@localhost:5432/mana_platform'
|
||||
),
|
||||
syncDatabaseUrl: env(
|
||||
'SYNC_DATABASE_URL',
|
||||
'postgresql://manacore:devpassword@localhost:5432/mana_sync'
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export default defineConfig({
|
|||
dialect: 'postgresql',
|
||||
dbCredentials: {
|
||||
url:
|
||||
process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/mana_credits',
|
||||
process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/mana_platform',
|
||||
},
|
||||
schemaFilter: ['credits', 'gifts'],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ export function loadConfig(): Config {
|
|||
port: parseInt(process.env.PORT || '3061', 10),
|
||||
databaseUrl: requiredEnv(
|
||||
'DATABASE_URL',
|
||||
'postgresql://manacore:devpassword@localhost:5432/mana_credits'
|
||||
'postgresql://manacore:devpassword@localhost:5432/mana_platform'
|
||||
),
|
||||
manaAuthUrl: requiredEnv('MANA_CORE_AUTH_URL', 'http://localhost:3001'),
|
||||
serviceKey: requiredEnv('MANA_CORE_SERVICE_KEY', 'dev-service-key'),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { createDrizzleConfig } from '@manacore/shared-drizzle-config';
|
||||
|
||||
export default createDrizzleConfig({
|
||||
dbName: 'mana_media',
|
||||
dbName: 'mana_platform',
|
||||
schemaPath: './src/db/schema/index.ts',
|
||||
schemaFilter: ['media'],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {
|
||||
pgTable,
|
||||
pgSchema,
|
||||
uuid,
|
||||
text,
|
||||
timestamp,
|
||||
|
|
@ -11,11 +11,13 @@ import {
|
|||
} from 'drizzle-orm/pg-core';
|
||||
import { relations } from 'drizzle-orm';
|
||||
|
||||
export const mediaSchema = pgSchema('media');
|
||||
|
||||
/**
|
||||
* Core media table - stores unique files by content hash (SHA-256)
|
||||
* This is the Content-Addressable Storage (CAS) approach
|
||||
*/
|
||||
export const media = pgTable(
|
||||
export const media = mediaSchema.table(
|
||||
'media',
|
||||
{
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
|
|
@ -70,7 +72,7 @@ export const media = pgTable(
|
|||
* Media references - tracks which user/app owns a reference to a media item
|
||||
* Multiple users can reference the same media (deduplication)
|
||||
*/
|
||||
export const mediaReferences = pgTable(
|
||||
export const mediaReferences = mediaSchema.table(
|
||||
'media_references',
|
||||
{
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
|
|
@ -101,7 +103,7 @@ export const mediaReferences = pgTable(
|
|||
* Lazy-generated thumbnails cache
|
||||
* Stores on-the-fly generated thumbnails with specific parameters
|
||||
*/
|
||||
export const mediaThumbnails = pgTable(
|
||||
export const mediaThumbnails = mediaSchema.table(
|
||||
'media_thumbnails',
|
||||
{
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ export default defineConfig({
|
|||
dialect: 'postgresql',
|
||||
dbCredentials: {
|
||||
url:
|
||||
process.env.DATABASE_URL ||
|
||||
'postgresql://manacore:devpassword@localhost:5432/mana_subscriptions',
|
||||
process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/mana_platform',
|
||||
},
|
||||
schemaFilter: ['subscriptions'],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export function loadConfig(): Config {
|
|||
port: parseInt(env('PORT', '3063'), 10),
|
||||
databaseUrl: env(
|
||||
'DATABASE_URL',
|
||||
'postgresql://manacore:devpassword@localhost:5432/mana_subscriptions'
|
||||
'postgresql://manacore:devpassword@localhost:5432/mana_platform'
|
||||
),
|
||||
manaAuthUrl: env('MANA_CORE_AUTH_URL', 'http://localhost:3001'),
|
||||
serviceKey: env('MANA_CORE_SERVICE_KEY', 'dev-service-key'),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ export default defineConfig({
|
|||
out: './drizzle',
|
||||
dialect: 'postgresql',
|
||||
dbCredentials: {
|
||||
url: process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/mana_user',
|
||||
url:
|
||||
process.env.DATABASE_URL || 'postgresql://manacore:devpassword@localhost:5432/mana_platform',
|
||||
},
|
||||
schemaFilter: ['usr'],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ export function loadConfig(): Config {
|
|||
const env = (key: string, fallback?: string) => process.env[key] || fallback || '';
|
||||
return {
|
||||
port: parseInt(env('PORT', '3062'), 10),
|
||||
databaseUrl: env('DATABASE_URL', 'postgresql://manacore:devpassword@localhost:5432/mana_user'),
|
||||
databaseUrl: env(
|
||||
'DATABASE_URL',
|
||||
'postgresql://manacore:devpassword@localhost:5432/mana_platform'
|
||||
),
|
||||
manaAuthUrl: env('MANA_CORE_AUTH_URL', 'http://localhost:3001'),
|
||||
serviceKey: env('MANA_CORE_SERVICE_KEY', 'dev-service-key'),
|
||||
cors: { origins: env('CORS_ORIGINS', 'http://localhost:5173').split(',') },
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
export * from './schema';
|
||||
export * from './tag-groups';
|
||||
export * from './tags';
|
||||
export * from './tag-links';
|
||||
|
|
|
|||
3
services/mana-user/src/db/schema/schema.ts
Normal file
3
services/mana-user/src/db/schema/schema.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { pgSchema } from 'drizzle-orm/pg-core';
|
||||
|
||||
export const usrSchema = pgSchema('usr');
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { pgTable, text, jsonb, timestamp } from 'drizzle-orm/pg-core';
|
||||
import { text, jsonb, timestamp } from 'drizzle-orm/pg-core';
|
||||
import { usrSchema } from './schema';
|
||||
|
||||
export const userSettings = pgTable('user_settings', {
|
||||
export const userSettings = usrSchema.table('user_settings', {
|
||||
userId: text('user_id').primaryKey(),
|
||||
globalSettings: jsonb('global_settings')
|
||||
.default({
|
||||
|
|
|
|||
|
|
@ -1,15 +1,7 @@
|
|||
import {
|
||||
pgTable,
|
||||
varchar,
|
||||
text,
|
||||
uuid,
|
||||
timestamp,
|
||||
index,
|
||||
unique,
|
||||
integer,
|
||||
} from 'drizzle-orm/pg-core';
|
||||
import { varchar, text, uuid, timestamp, index, unique, integer } from 'drizzle-orm/pg-core';
|
||||
import { usrSchema } from './schema';
|
||||
|
||||
export const tagGroups = pgTable(
|
||||
export const tagGroups = usrSchema.table(
|
||||
'tag_groups',
|
||||
{
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { pgTable, varchar, text, uuid, timestamp, index, unique } from 'drizzle-orm/pg-core';
|
||||
import { varchar, text, uuid, timestamp, index, unique } from 'drizzle-orm/pg-core';
|
||||
import { usrSchema } from './schema';
|
||||
import { tags } from './tags';
|
||||
|
||||
export const tagLinks = pgTable(
|
||||
export const tagLinks = usrSchema.table(
|
||||
'tag_links',
|
||||
{
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
|
|
|
|||
|
|
@ -1,16 +1,8 @@
|
|||
import {
|
||||
pgTable,
|
||||
varchar,
|
||||
text,
|
||||
uuid,
|
||||
timestamp,
|
||||
index,
|
||||
unique,
|
||||
integer,
|
||||
} from 'drizzle-orm/pg-core';
|
||||
import { varchar, text, uuid, timestamp, index, unique, integer } from 'drizzle-orm/pg-core';
|
||||
import { usrSchema } from './schema';
|
||||
import { tagGroups } from './tag-groups';
|
||||
|
||||
export const tags = pgTable(
|
||||
export const tags = usrSchema.table(
|
||||
'tags',
|
||||
{
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue