Skip to content

Commit 8d35c77

Browse files
committed
refactor: update Dockerfile and Prisma schema for improved structure and consistency
- Updated Prisma schema to replace uuid fields with id fields of type BigInt. - Refactored repository interfaces to use ICrudWithId for better clarity in CRUD operations. - Removed deprecated methods for UUID handling in repositories, enhancing code maintainability.
1 parent 004d4cd commit 8d35c77

File tree

23 files changed

+160
-164
lines changed

23 files changed

+160
-164
lines changed

Dockerfile

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
FROM node:22 AS build
2-
WORKDIR /opt/app
1+
FROM alpine:3.19 AS frontend
2+
WORKDIR /opt/frontend
33

4-
RUN apt-get update \
5-
&& apt-get install -y curl unzip \
4+
RUN apk add --no-cache curl unzip ca-certificates \
65
&& curl -L https://github.com/remnawave/frontend/releases/latest/download/remnawave-frontend.zip -o frontend.zip \
7-
&& unzip frontend.zip -d frontend_temp \
8-
&& mkdir frontend \
9-
&& cp -r frontend_temp/dist/* frontend/ \
10-
&& rm -rf frontend_temp frontend.zip \
11-
&& apt-get purge -y curl unzip \
12-
&& apt-get autoremove -y \
13-
&& apt-get clean \
14-
&& rm -rf /var/lib/apt/lists/*
6+
&& unzip frontend.zip -d frontend_temp
7+
8+
FROM node:22 AS backend-build
9+
WORKDIR /opt/app
1510

1611
COPY package*.json ./
1712
COPY prisma ./prisma
1813

19-
RUN npm ci --legacy-peer-deps
14+
RUN npm ci
2015

2116
COPY . .
2217

23-
RUN npm run migrate:generate
2418
RUN npm run build
25-
RUN npm run build:seed
19+
20+
RUN npm run migrate:generate
21+
22+
RUN npm cache clean --force
23+
24+
RUN npm prune --omit=dev
2625

2726
FROM node:22
2827
WORKDIR /opt/app
2928

30-
COPY --from=build /opt/app/dist ./dist
31-
COPY --from=build /opt/app/frontend ./frontend
32-
COPY --from=build /opt/app/prisma/schema.prisma ./prisma/
33-
COPY --from=build /opt/app/prisma/migrations ./prisma/migrations
29+
COPY --from=backend-build /opt/app/dist ./dist
30+
COPY --from=frontend /opt/frontend/frontend_temp/dist ./frontend
31+
COPY --from=backend-build /opt/app/prisma ./prisma
32+
COPY --from=backend-build /opt/app/node_modules ./node_modules
3433

3534
COPY configs /var/lib/remnawave/configs
3635
COPY package*.json ./
@@ -39,12 +38,7 @@ COPY libs ./libs
3938
COPY ecosystem.config.js ./
4039
COPY docker-entrypoint.sh ./
4140

42-
RUN npm ci --omit=dev --legacy-peer-deps \
43-
&& npm run migrate:generate \
44-
&& npm cache clean --force \
45-
&& npm install pm2 -g \
41+
RUN npm install pm2 -g \
4642
&& npm link
4743

48-
# CMD [ "npm", "run", "migrate:deploy", "&&", "pm2-runtime", "start", "ecosystem.config.js", "--env", "production" ]
49-
5044
CMD [ "/bin/sh", "docker-entrypoint.sh" ]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Warnings:
3+
4+
- The primary key for the `active_user_inbounds` table will be changed. If it partially fails, the table could be left without primary key constraint.
5+
- You are about to drop the column `uuid` on the `active_user_inbounds` table. All the data in the column will be lost.
6+
- The primary key for the `nodes_traffic_usage_history` table will be changed. If it partially fails, the table could be left without primary key constraint.
7+
- You are about to drop the column `uuid` on the `nodes_traffic_usage_history` table. All the data in the column will be lost.
8+
- The primary key for the `nodes_usage_history` table will be changed. If it partially fails, the table could be left without primary key constraint.
9+
- You are about to drop the column `uuid` on the `nodes_usage_history` table. All the data in the column will be lost.
10+
- The primary key for the `nodes_user_usage_history` table will be changed. If it partially fails, the table could be left without primary key constraint.
11+
- You are about to drop the column `uuid` on the `nodes_user_usage_history` table. All the data in the column will be lost.
12+
- The primary key for the `user_traffic_history` table will be changed. If it partially fails, the table could be left without primary key constraint.
13+
- You are about to drop the column `uuid` on the `user_traffic_history` table. All the data in the column will be lost.
14+
15+
*/
16+
-- DropIndex
17+
DROP INDEX "active_user_inbounds_user_uuid_inbound_uuid_key";
18+
19+
-- DropIndex
20+
DROP INDEX "nodes_usage_history_node_uuid_created_at_key";
21+
22+
-- DropIndex
23+
DROP INDEX "nodes_user_usage_history_node_uuid_user_uuid_created_at_key";
24+
25+
-- AlterTable
26+
ALTER TABLE "active_user_inbounds" DROP CONSTRAINT "active_user_inbounds_pkey",
27+
DROP COLUMN "uuid",
28+
ADD CONSTRAINT "active_user_inbounds_pkey" PRIMARY KEY ("user_uuid", "inbound_uuid");
29+
30+
-- AlterTable
31+
ALTER TABLE "admin" ALTER COLUMN "created_at" SET DEFAULT now(),
32+
ALTER COLUMN "updated_at" SET DEFAULT now();
33+
34+
-- AlterTable
35+
ALTER TABLE "api_tokens" ALTER COLUMN "created_at" SET DEFAULT now(),
36+
ALTER COLUMN "updated_at" SET DEFAULT now();
37+
38+
-- AlterTable
39+
ALTER TABLE "keygen" ALTER COLUMN "created_at" SET DEFAULT now(),
40+
ALTER COLUMN "updated_at" SET DEFAULT now();
41+
42+
-- AlterTable
43+
ALTER TABLE "nodes" ALTER COLUMN "created_at" SET DEFAULT now(),
44+
ALTER COLUMN "updated_at" SET DEFAULT now();
45+
46+
-- AlterTable
47+
ALTER TABLE "nodes_traffic_usage_history" DROP CONSTRAINT "nodes_traffic_usage_history_pkey",
48+
DROP COLUMN "uuid",
49+
ADD COLUMN "id" BIGSERIAL NOT NULL,
50+
ALTER COLUMN "reset_at" SET DEFAULT now(),
51+
ADD CONSTRAINT "nodes_traffic_usage_history_pkey" PRIMARY KEY ("id");
52+
53+
-- AlterTable
54+
ALTER TABLE "nodes_usage_history" DROP CONSTRAINT "nodes_usage_history_pkey",
55+
DROP COLUMN "uuid",
56+
ALTER COLUMN "created_at" SET DEFAULT date_trunc('hour', now()),
57+
ADD CONSTRAINT "nodes_usage_history_pkey" PRIMARY KEY ("node_uuid", "created_at");
58+
59+
-- AlterTable
60+
ALTER TABLE "nodes_user_usage_history" DROP CONSTRAINT "nodes_user_usage_history_pkey",
61+
DROP COLUMN "uuid",
62+
ALTER COLUMN "created_at" SET DEFAULT date_trunc('hour', now()),
63+
ALTER COLUMN "updated_at" SET DEFAULT now(),
64+
ADD CONSTRAINT "nodes_user_usage_history_pkey" PRIMARY KEY ("node_uuid", "user_uuid", "created_at");
65+
66+
-- AlterTable
67+
ALTER TABLE "subscription_settings" ALTER COLUMN "created_at" SET DEFAULT now(),
68+
ALTER COLUMN "updated_at" SET DEFAULT now();
69+
70+
-- AlterTable
71+
ALTER TABLE "subscription_templates" ALTER COLUMN "created_at" SET DEFAULT now(),
72+
ALTER COLUMN "updated_at" SET DEFAULT now();
73+
74+
-- AlterTable
75+
ALTER TABLE "user_traffic_history" DROP CONSTRAINT "user_traffic_history_pkey",
76+
DROP COLUMN "uuid",
77+
ADD COLUMN "id" BIGSERIAL NOT NULL,
78+
ALTER COLUMN "reset_at" SET DEFAULT now(),
79+
ADD CONSTRAINT "user_traffic_history_pkey" PRIMARY KEY ("id");
80+
81+
-- AlterTable
82+
ALTER TABLE "users" ALTER COLUMN "created_at" SET DEFAULT now(),
83+
ALTER COLUMN "updated_at" SET DEFAULT now();
84+
85+
-- AlterTable
86+
ALTER TABLE "xray_config" ALTER COLUMN "updated_at" SET DEFAULT now();

prisma/schema.prisma

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ model NodeInboundExclusions {
146146
}
147147

148148
model NodesTrafficUsageHistory {
149-
uuid String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
149+
id BigInt @id @default(autoincrement())
150150
nodeUuid String @map("node_uuid") @db.Uuid
151151
trafficBytes BigInt @map("traffic_bytes")
152152
resetAt DateTime @default(dbgenerated("now()")) @map("reset_at")
@@ -157,7 +157,6 @@ model NodesTrafficUsageHistory {
157157
}
158158

159159
model NodesUserUsageHistory {
160-
uuid String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
161160
nodeUuid String @map("node_uuid") @db.Uuid
162161
userUuid String @map("user_uuid") @db.Uuid
163162
downloadBytes BigInt @map("download_bytes")
@@ -170,12 +169,11 @@ model NodesUserUsageHistory {
170169
node Nodes @relation(fields: [nodeUuid], references: [uuid], onDelete: Cascade)
171170
user Users @relation(fields: [userUuid], references: [uuid], onDelete: Cascade)
172171
173-
@@unique([nodeUuid, userUuid, createdAt])
172+
@@id([nodeUuid, userUuid, createdAt])
174173
@@map("nodes_user_usage_history")
175174
}
176175

177176
model NodesUsageHistory {
178-
uuid String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
179177
nodeUuid String @map("node_uuid") @db.Uuid
180178
downloadBytes BigInt @map("download_bytes")
181179
uploadBytes BigInt @map("upload_bytes")
@@ -185,12 +183,12 @@ model NodesUsageHistory {
185183
186184
node Nodes @relation(fields: [nodeUuid], references: [uuid], onDelete: Cascade)
187185
188-
@@unique([nodeUuid, createdAt])
186+
@@id([nodeUuid, createdAt])
189187
@@map("nodes_usage_history")
190188
}
191189

192190
model UserTrafficHistory {
193-
uuid String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
191+
id BigInt @id @default(autoincrement())
194192
userUuid String @map("user_uuid") @db.Uuid
195193
usedBytes BigInt @map("used_bytes")
196194
resetAt DateTime @default(dbgenerated("now()")) @map("reset_at")
@@ -245,14 +243,13 @@ model Hosts {
245243
}
246244

247245
model ActiveUserInbounds {
248-
uuid String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
249246
userUuid String @map("user_uuid") @db.Uuid
250247
inboundUuid String @map("inbound_uuid") @db.Uuid
251248
252249
user Users @relation(fields: [userUuid], references: [uuid], onDelete: Cascade)
253250
inbound Inbounds @relation(fields: [inboundUuid], references: [uuid], onDelete: Cascade)
254251
255-
@@unique([userUuid, inboundUuid])
252+
@@id([userUuid, inboundUuid])
256253
@@map("active_user_inbounds")
257254
}
258255

src/common/types/crud-port.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@ export interface ICrud<ENTITY> {
55
findByUUID: (uuid: string) => Promise<ENTITY | null>;
66
update: (entity: ENTITY) => Promise<ENTITY | null>;
77
}
8+
9+
export interface ICrudWithId<ENTITY> {
10+
create: (entity: ENTITY) => Promise<ENTITY>;
11+
deleteById: (id: bigint | number) => Promise<boolean>;
12+
findByCriteria: (entity: Partial<ENTITY>) => Promise<ENTITY[]>;
13+
findById: (id: bigint | number) => Promise<ENTITY | null>;
14+
update: (entity: ENTITY) => Promise<ENTITY | null>;
15+
}
16+
17+
export interface ICrudHistoricalRecords<ENTITY> {
18+
create: (entity: ENTITY) => Promise<ENTITY>;
19+
findByCriteria: (entity: Partial<ENTITY>) => Promise<ENTITY[]>;
20+
}

src/modules/inbounds/builders/remove-inbound-from-nodes/remove-inbound-from-nodes.builder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export class RemoveInboundFromNodesBuilder {
55

66
constructor(inboundUuid: string) {
77
this.query = this.getQuery(inboundUuid);
8-
return this;
98
}
109

1110
public getQuery(inboundUuid: string): Prisma.Sql {

src/modules/inbounds/builders/remove-inbound-from-users/remove-inbound-from-users.builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export class RemoveInboundFromUsersBuilder {
99
}
1010

1111
public getQuery(inboundUuid: string): Prisma.Sql {
12-
const query = `
12+
const query = Prisma.sql`
1313
DELETE FROM "public"."active_user_inbounds"
14-
WHERE "inbound_uuid" = '${inboundUuid}';
14+
WHERE "inbound_uuid" = ${inboundUuid};
1515
`;
16-
return Prisma.raw(query);
16+
return query;
1717
}
1818
}

src/modules/inbounds/converters/active-user-inbounds.converter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const modelToEntity = (model: ActiveUserInbounds): ActiveUserInboundEntity => {
1212

1313
const entityToModel = (entity: ActiveUserInboundEntity): ActiveUserInbounds => {
1414
return {
15-
uuid: entity.uuid,
1615
userUuid: entity.userUuid,
1716
inboundUuid: entity.inboundUuid,
1817
};

src/modules/inbounds/entities/active-user-inbound.entity.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ActiveUserInbounds } from '@prisma/client';
22

33
export class ActiveUserInboundEntity implements ActiveUserInbounds {
4-
uuid: string;
54
userUuid: string;
65
inboundUuid: string;
76

src/modules/inbounds/entities/base-inbound.entity.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ export class BaseInboundEntity extends InboundsEntity {
66
constructor(entity: InboundsEntity, port: number) {
77
super(entity);
88
this.port = port;
9-
10-
return this;
119
}
1210
}

src/modules/inbounds/entities/inbound-with-stats.entity.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,5 @@ export class InboundWithStatsEntity {
4343
enabled: Number(data.enabledNodes),
4444
disabled: Number(data.disabledNodes),
4545
};
46-
47-
return this;
4846
}
4947
}

0 commit comments

Comments
 (0)