fix: indexes and multiple instances

This commit is contained in:
Face 2025-06-23 22:37:39 +03:00
parent cd40ede713
commit 38942dab9a
5 changed files with 2129 additions and 32 deletions

View file

@ -1,54 +1,70 @@
version: '3.8'
services:
app:
# Multiple app instances
app-1:
build:
context: .
target: production-main
dockerfile: Dockerfile
ports:
- "3002:3000"
- "3003:3000" # Expose to host for nginx
env_file:
- website/.env
environment:
- INSTANCE_NAME=app-1
depends_on:
- websocket
- redis
- postgres
restart: unless-stopped
networks:
- shared_backend
app-2:
build:
context: .
target: production-main
dockerfile: Dockerfile
ports:
- "3004:3000" # Different port for second instance
env_file:
- website/.env
environment:
- INSTANCE_NAME=app-2
depends_on:
- websocket
restart: unless-stopped
networks:
- shared_backend
app-3:
build:
context: .
target: production-main
dockerfile: Dockerfile
ports:
- "3005:3000" # Different port for third instance
env_file:
- website/.env
environment:
- INSTANCE_NAME=app-3
depends_on:
- websocket
restart: unless-stopped
networks:
- shared_backend
# WebSocket service (single instance is usually sufficient)
websocket:
build:
context: .
target: production-websocket
dockerfile: Dockerfile
ports:
- "8081:8080"
- "8082:8080"
env_file:
- website/.env
depends_on:
- redis
restart: unless-stopped
networks:
- shared_backend
redis:
image: redis:8-alpine
volumes:
- rugplay_redisdata:/data
command: "redis-server --save 60 1"
restart: unless-stopped
postgres:
image: pgvector/pgvector:pg16
container_name: rugplay-postgres
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB:-rugplay}
ports:
- "5432:5432"
volumes:
- rugplay_pgdata:/var/lib/postgresql/data
restart: unless-stopped
volumes:
rugplay_pgdata:
rugplay_redisdata:
networks:
shared_backend:
external: true

View file

@ -0,0 +1,19 @@
CREATE INDEX IF NOT EXISTS "coin_symbol_idx" ON "coin" USING btree ("symbol");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "coin_creator_id_idx" ON "coin" USING btree ("creator_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "coin_is_listed_idx" ON "coin" USING btree ("is_listed");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "coin_market_cap_idx" ON "coin" USING btree ("market_cap");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "coin_current_price_idx" ON "coin" USING btree ("current_price");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "coin_change24h_idx" ON "coin" USING btree ("change_24h");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "coin_volume24h_idx" ON "coin" USING btree ("volume_24h");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "coin_created_at_idx" ON "coin" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "transaction_user_id_idx" ON "transaction" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "transaction_coin_id_idx" ON "transaction" USING btree ("coin_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "transaction_type_idx" ON "transaction" USING btree ("type");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "transaction_timestamp_idx" ON "transaction" USING btree ("timestamp");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "transaction_user_coin_idx" ON "transaction" USING btree ("user_id","coin_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "transaction_coin_type_idx" ON "transaction" USING btree ("coin_id","type");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "user_username_idx" ON "user" USING btree ("username");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "user_is_banned_idx" ON "user" USING btree ("is_banned");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "user_is_admin_idx" ON "user" USING btree ("is_admin");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "user_created_at_idx" ON "user" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "user_updated_at_idx" ON "user" USING btree ("updated_at");

File diff suppressed because it is too large Load diff

View file

@ -22,6 +22,13 @@
"when": 1749916220202,
"tag": "0002_small_micromacro",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1750707307426,
"tag": "0003_complete_runaways",
"breakpoints": true
}
]
}

View file

@ -33,6 +33,14 @@ export const user = pgTable("user", {
}).notNull().default("0.00000000"),
loginStreak: integer("login_streak").notNull().default(0),
prestigeLevel: integer("prestige_level").default(0),
}, (table) => {
return {
usernameIdx: index("user_username_idx").on(table.username),
isBannedIdx: index("user_is_banned_idx").on(table.isBanned),
isAdminIdx: index("user_is_admin_idx").on(table.isAdmin),
createdAtIdx: index("user_created_at_idx").on(table.createdAt),
updatedAtIdx: index("user_updated_at_idx").on(table.updatedAt),
};
});
export const session = pgTable("session", {
@ -88,6 +96,17 @@ export const coin = pgTable("coin", {
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
isListed: boolean("is_listed").default(true).notNull(),
}, (table) => {
return {
symbolIdx: index("coin_symbol_idx").on(table.symbol),
creatorIdIdx: index("coin_creator_id_idx").on(table.creatorId),
isListedIdx: index("coin_is_listed_idx").on(table.isListed),
marketCapIdx: index("coin_market_cap_idx").on(table.marketCap),
currentPriceIdx: index("coin_current_price_idx").on(table.currentPrice),
change24hIdx: index("coin_change24h_idx").on(table.change24h),
volume24hIdx: index("coin_volume24h_idx").on(table.volume24h),
createdAtIdx: index("coin_created_at_idx").on(table.createdAt),
};
});
export const userPortfolio = pgTable("user_portfolio", {
@ -114,6 +133,15 @@ export const transaction = pgTable("transaction", {
timestamp: timestamp("timestamp", { withTimezone: true }).notNull().defaultNow(),
recipientUserId: integer('recipient_user_id').references(() => user.id, { onDelete: 'set null' }),
senderUserId: integer('sender_user_id').references(() => user.id, { onDelete: 'set null' }),
}, (table) => {
return {
userIdIdx: index("transaction_user_id_idx").on(table.userId),
coinIdIdx: index("transaction_coin_id_idx").on(table.coinId),
typeIdx: index("transaction_type_idx").on(table.type),
timestampIdx: index("transaction_timestamp_idx").on(table.timestamp),
userCoinIdx: index("transaction_user_coin_idx").on(table.userId, table.coinId),
coinTypeIdx: index("transaction_coin_type_idx").on(table.coinId, table.type),
};
});
export const priceHistory = pgTable("price_history", {