Skip to content

Commit 0b2188e

Browse files
committed
connected Supabase and upstash for database handling properly + fix: docker issue{removed pgadmin, and postgress locally and pushed data to cloud}
1 parent 8a643ad commit 0b2188e

9 files changed

Lines changed: 83 additions & 68 deletions

File tree

Client/package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@vitejs/plugin-react": "^5.0.4",
5050
"autoprefixer": "^10.4.22",
5151
"babel-plugin-react-compiler": "^19.1.0-rc.3",
52+
"baseline-browser-mapping": "^2.9.11",
5253
"eslint": "^9.36.0",
5354
"eslint-plugin-react-hooks": "^5.2.0",
5455
"eslint-plugin-react-refresh": "^0.4.22",

backend/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:18
1+
FROM node:20-alpine
22

33
# Set working directory
44
WORKDIR /app
@@ -18,4 +18,4 @@ EXPOSE 3000
1818

1919
# Run migrations and then start the application
2020
# `migrate deploy` is safe to run on every startup
21-
CMD ["sh", "-c", "npx prisma migrate deploy && npm run start:dev"]
21+
CMD ["sh", "-c", "npx prisma migrate deploy && npm run start"]

backend/package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@nestjs/websockets": "^11.1.6",
3333
"@prisma/client": "^6.15.0",
3434
"@types/passport-jwt": "^4.0.1",
35+
"@upstash/redis": "^1.36.0",
3536
"bcrypt": "^6.0.0",
3637
"cache-manager-redis-store": "^3.0.1",
3738
"class-transformer": "^0.5.1",

backend/prisma/schema.prisma

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
55
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
66

7+
78
generator client {
89
provider = "prisma-client-js"
910
}
1011

1112
datasource db {
12-
provider = "postgresql"
13-
url = env("DATABASE_URL")
13+
provider = "postgresql"
14+
url = env("DATABASE_URL")
15+
directUrl = env("DIRECT_URL")
1416
}
17+
1518

1619
enum Role{
1720
Admin

backend/src/app.module.ts

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,56 @@ import { PrismaModule } from './prisma/prisma.module';
33
import { UserModule } from './user/user.module';
44
import { AuthModule } from './auth/auth.module';
55
import { WorkspaceModule } from './workspaces/workspaces.module';
6-
import { ConfigModule, ConfigService } from '@nestjs/config';
76
import { CacheModule } from '@nestjs/cache-manager';
8-
import { redisStore } from 'cache-manager-redis-store';
97
import { DocumentModule } from './documents/document.module';
108
import { RealTimeModule } from './real-Time/real-Time.module';
9+
import { Redis } from '@upstash/redis';
10+
import { redisStore } from 'cache-manager-redis-store';
1111

1212
@Module({
1313
imports: [
14-
//load configuration from .env files golbally..
15-
ConfigModule.forRoot({
16-
isGlobal: true,
17-
envFilePath: '.env',
18-
}),
19-
20-
//2. stepup caching using Redis Store..
2114
CacheModule.registerAsync({
2215
isGlobal: true,
23-
imports: [ConfigModule],
24-
useFactory: (ConfigService: ConfigService) => ({
25-
store: redisStore,
26-
host: ConfigService.get<string>('redis_Host') || 'localhost',
27-
port: ConfigService.get<number>('redis_Port') || 6379,
28-
ttl: 1000 * 60 * 5,
29-
}),
30-
inject: [ConfigService],
16+
useFactory: async () => {
17+
if (process.env.NODE_ENV === 'production') {
18+
const redis = new Redis({
19+
url: process.env.UPSTASH_REDIS_REST_URL!,
20+
token: process.env.UPSTASH_REDIS_REST_TOKEN!,
21+
});
22+
23+
return {
24+
store: {
25+
get: (key: string) => redis.get(key),
26+
set: (key: string, value: any, options?: { ttl?: number }) =>
27+
redis.set(
28+
key,
29+
value,
30+
options?.ttl ? { ex: options.ttl } : undefined,
31+
),
32+
del: (key: string) => redis.del(key),
33+
},
34+
ttl: 60 * 5,
35+
};
36+
}
37+
38+
// ✅ Local Redis via Docker
39+
const host = process.env.REDIS_HOST || 'redis';
40+
const port = parseInt(process.env.REDIS_PORT || '6379', 10);
41+
42+
return {
43+
store: await redisStore({
44+
// Adding socket property for better compatibility
45+
socket: {
46+
host: host,
47+
port: port,
48+
},
49+
// If socket doesn't work for your version, keep these as fallback
50+
host: host,
51+
port: port,
52+
ttl: 60 * 5,
53+
}),
54+
};
55+
},
3156
}),
3257
PrismaModule,
3358
UserModule,
@@ -36,7 +61,5 @@ import { RealTimeModule } from './real-Time/real-Time.module';
3661
DocumentModule,
3762
RealTimeModule,
3863
],
39-
controllers: [],
40-
providers: [],
4164
})
4265
export class AppModule {}

backend/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function bootstrap() {
2222
}),
2323
);
2424
app.use(cookieParser());
25-
await app.listen(process.env.PORT ?? 3000);
25+
await app.listen(process.env.PORT ?? 3000, '0.0.0.0');
2626
}
2727
bootstrap().catch((err) => {
2828
console.error('Error during bootstrap:', err);

docker-compose.yml

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,19 @@
1+
version: "3.9"
2+
13
services:
24
redis:
3-
image: redis:6.2-alpine # Lightweight Redis image
5+
image: redis:7-alpine
46
container_name: brainvector-redis
57
restart: always
6-
# Expose the default Redis port
78
ports:
89
- "6379:6379"
9-
volumes:
10-
- redisdata:/data # Volume for Redis persistence
11-
deploy:
12-
resources:
13-
limits:
14-
cpus: "0.5"
15-
memory: 256m
16-
postgres:
17-
image: postgres:14
18-
restart: always
19-
environment:
20-
POSTGRES_USER: arun
21-
POSTGRES_PASSWORD: 12arun
22-
POSTGRES_DB: BrainVector
23-
ports:
24-
- "5432:5432"
25-
volumes:
26-
- pgdata:/var/lib/postgresql/data
27-
deploy:
28-
resources:
29-
limits:
30-
cpus: "1.0"
31-
memory: 1g
3210
healthcheck:
33-
test: ["CMD-SHELL", "pg_isready -U arun -d BrainVector"]
11+
test: ["CMD", "redis-cli", "ping"]
3412
interval: 5s
35-
timeout: 5s
13+
timeout: 3s
3614
retries: 5
37-
15+
volumes:
16+
- redisdata:/data
3817
backend:
3918
build: ./backend
4019
container_name: brainvector-backend
@@ -44,24 +23,18 @@ services:
4423
- ./backend:/app
4524
- /app/node_modules
4625
environment:
47-
DATABASE_URL: postgres://arun:12arun@postgres:5432/BrainVector
26+
DATABASE_URL: "postgresql://postgres.wuqxzlwctbdcissjfgvq:8988307565%40B@aws-1-ap-south-1.pooler.supabase.com:6543/postgres?pgbouncer=true"
4827
JWT_SECRET: EKTUHINIRANKAR
4928
NODE_ENV: development
29+
REDIS_HOST: redis
30+
REDIS_PORT: 6379
5031
PORT: 3000
32+
HOST: 0.0.0.0
5133
depends_on:
52-
postgres:
34+
redis:
5335
condition: service_healthy
54-
pgadmin:
55-
image: dpage/pgadmin4
56-
container_name: pgadmin
5736
restart: always
58-
environment:
59-
PGADMIN_DEFAULT_EMAIL: admin@brainvector.com
60-
PGADMIN_DEFAULT_PASSWORD: admin123
61-
ports:
62-
- "8080:80"
63-
depends_on:
64-
- postgres
37+
6538
frontend:
6639
build:
6740
context: ./client
@@ -79,5 +52,4 @@ services:
7952
restart: always
8053

8154
volumes:
82-
pgdata:
8355
redisdata:

0 commit comments

Comments
 (0)