Skip to content

Commit bfbfc80

Browse files
committed
Merge branch 'main' into change-seed
2 parents 2cd7555 + 78c0290 commit bfbfc80

File tree

48 files changed

+1317
-426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1317
-426
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ jobs:
2222
~/.rustup/
2323
scraper/target
2424
key: cargo-cache-${{ github.job }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
25-
- uses: actions-rust-lang/setup-rust-toolchain@v1
25+
- uses: dtolnay/rust-toolchain@v1
2626
with:
27+
toolchain: 1.82.0
2728
components: clippy,rustfmt
2829
- run: cargo build
2930
- run: cargo build --release

Makefile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ setup-ci:
1616
make generate-sql
1717

1818
sync: sync-server sync-web sync-root sync-common
19-
bunx lefthook install || true
2019
@echo '----------------------------------------------------------------------------------------------------------'
2120
@echo '| Most work is done. now running prisma-generate-sql (which might fail if .env.dev is not set configured)|'
2221
@echo '----------------------------------------------------------------------------------------------------------'
2322
make generate-sql || true
2423

2524
generate-sql:
26-
@cd server; bun run prisma-generate-sql
25+
@cd server; \
26+
if command -v dotenv && command -v prisma; \
27+
then dotenv -e .env.dev -- prisma generate --sql; \
28+
else bunx dotenv -e .env.dev -- bunx prisma generate --sql; \
29+
fi
2730

2831
start: start-all # build -> serve
2932
build: build-server build-web
@@ -44,6 +47,9 @@ test: dev-db
4447

4548
prepare-deploy-web: sync-common
4649
cd web; bun install; bun run build
50+
deploy-web:
51+
@if [ "${PORT}" == "" ]; then echo 'env PORT not found!'; exit 1; fi
52+
cd web; bun next start --port ${PORT}
4753
prepare-deploy-server: sync-common sync-server generate-sql
4854
deploy-server:
4955
cd server; bun src/main.ts
@@ -56,7 +62,7 @@ docker-watch:
5662
docker compose up --build --watch
5763

5864
seed:
59-
cd server; bunx prisma db seed
65+
cd server; if command -v prisma; then prisma db seed; else bunx prisma db seed; fi
6066

6167
## server/.envをDATABASE_URL=postgres://user:password@localhost:5432/databaseにしてから行う
6268
dev-db: export DATABASE_URL=$(LOCAL_DB)
@@ -70,14 +76,16 @@ dev-db:
7076
-e POSTGRES_DB=database \
7177
postgres:alpine
7278
@echo "Waiting for PostgreSQL to be ready..."
73-
@sleep 5 # PostgreSQLが起動するまでの待機(必要に応じて調整)
79+
@sleep 2 # PostgreSQLが起動するまでの待機(必要に応じて調整)
7480
@until docker exec postgres pg_isready -U user -d database; do \
7581
echo "Waiting for PostgreSQL to be ready..."; \
7682
sleep 1; \
7783
done
7884
@echo "PostgreSQL is ready. Running seed..."
79-
@cd server; bunx prisma generate; bunx prisma db push; cd ..
80-
@make seed;
85+
@cd server; if command -v prisma; then \
86+
prisma generate; prisma db push; else \
87+
bunx prisma generate; bunx prisma db push; fi
88+
@make seed
8189
@echo "Seeding completed."
8290

8391
# Sync (install/update packages, generate prisma, etc)
@@ -88,7 +96,7 @@ sync-web:
8896

8997
sync-server:
9098
cd server; bun install --frozen-lockfile
91-
cd server; bunx prisma generate
99+
cd server; if command -v prisma; then prisma generate; else bunx prisma generate; fi
92100
# copy .env.sample -> .env only if .env is not there
93101

94102
sync-root:

bun.lockb

16 Bytes
Binary file not shown.

common/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type {
77
Gender,
88
RelationshipStatus,
99
InterestSubject,
10+
Interest,
1011
User,
1112
InitUser,
1213
UpdateUser,
@@ -17,6 +18,7 @@ export type {
1718
Course,
1819
Enrollment,
1920
Day,
21+
UserWithCoursesAndSubjects,
2022
MessageID,
2123
ShareRoomID,
2224
Message,

common/zod/schemas.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export const InterestSubjectSchema = z.object({
3838
group: z.string(),
3939
});
4040

41+
export const InterestSchema = z.object({
42+
userId: UserIDSchema,
43+
subjectId: z.number(),
44+
});
45+
4146
export const UserSchema = z.object({
4247
id: UserIDSchema,
4348
guid: GUIDSchema,
@@ -103,6 +108,11 @@ export const EnrollmentSchema = z.object({
103108
courseId: CourseIDSchema,
104109
});
105110

111+
export const UserWithCoursesAndSubjectsSchema = UserSchema.extend({
112+
courses: CourseSchema.array(),
113+
interestSubjects: InterestSubjectSchema.array(),
114+
});
115+
106116
export const MessageIDSchema = z.number(); // TODO! Add __internal_prevent_cast_MessageID: PhantomData
107117
export const ShareRoomIDSchema = z.number();
108118

@@ -116,6 +126,7 @@ export const MessageSchema = z.object({
116126
creator: UserIDSchema,
117127
createdAt: z.date(),
118128
content: ContentSchema,
129+
isPicture: z.boolean(),
119130
edited: z.boolean(),
120131
});
121132

@@ -136,6 +147,7 @@ export const DMOverviewSchema = z.object({
136147
name: NameSchema,
137148
thumbnail: z.string(),
138149
lastMsg: MessageSchema.optional(),
150+
unreadMessages: z.number(),
139151
});
140152

141153
export const SharedRoomOverviewSchema = z.object({
@@ -161,6 +173,8 @@ export const PersonalizedDMRoomSchema = z.object({
161173
name: NameSchema,
162174
thumbnail: z.string(),
163175
matchingStatus: MatchingStatusSchema,
176+
unreadMessages: z.number(),
177+
friendId: z.number(),
164178
});
165179

166180
export const SharedRoomSchema = z.object({

common/zod/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
InitRoomSchema,
1515
InitSharedRoomSchema,
1616
InitUserSchema,
17+
InterestSchema,
1718
InterestSubjectSchema,
1819
IntroLongSchema,
1920
IntroShortSchema,
@@ -37,6 +38,7 @@ import type {
3738
UpdateUserSchema,
3839
UserIDSchema,
3940
UserSchema,
41+
UserWithCoursesAndSubjectsSchema,
4042
} from "./schemas";
4143

4244
export type UserID = z.infer<typeof UserIDSchema>;
@@ -47,6 +49,7 @@ export type PictureUrl = z.infer<typeof PictureUrlSchema>;
4749
export type Gender = z.infer<typeof GenderSchema>;
4850
export type RelationshipStatus = z.infer<typeof RelationshipStatusSchema>;
4951
export type InterestSubject = z.infer<typeof InterestSubjectSchema>;
52+
export type Interest = z.infer<typeof InterestSchema>;
5053
export type User = z.infer<typeof UserSchema>;
5154
export type InitUser = z.infer<typeof InitUserSchema>;
5255
export type UpdateUser = z.infer<typeof UpdateUserSchema>;
@@ -59,6 +62,9 @@ export type Course = z.infer<typeof CourseSchema>;
5962
export type Enrollment = z.infer<typeof EnrollmentSchema>;
6063
export type Day = z.infer<typeof DaySchema>;
6164
export type Period = z.infer<typeof PeriodSchema>;
65+
export type UserWithCoursesAndSubjects = z.infer<
66+
typeof UserWithCoursesAndSubjectsSchema
67+
>;
6268
export type MessageID = z.infer<typeof MessageIDSchema>;
6369
export type ShareRoomID = z.infer<typeof ShareRoomIDSchema>;
6470
export type Message = z.infer<typeof MessageSchema>;

flake.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
biome
2828
pkg-config
2929
openssl
30+
lefthook
31+
pkgs.prisma
32+
dotenv-cli
3033
] ++ [
3134
rust-pkgs
3235
];

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"prepare": "lefthook install"
89
},
910
"keywords": [],
1011
"author": "",

server/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"dev": "bun --watch src/main.ts",
99
"build": "tsc",
10-
"serve": "bun target/main.js",
11-
"prisma-generate-sql": "bunx dotenv -e .env.dev -- prisma generate --sql"
10+
"serve": "bun target/main.js"
1211
},
1312
"prisma": {
1413
"seed": "bun src/seeds/seed-test.ts"
@@ -36,5 +35,6 @@
3635
"globals": "^15.8.0",
3736
"prisma": "^5.11.0",
3837
"typescript": "^5.4.5"
39-
}
38+
},
39+
"trustedPackages": ["prisma"]
4040
}

server/prisma/schema.prisma

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,24 @@ model User {
4242
interests Interest[]
4343
}
4444

45-
// プロフィールの画像。
4645
model Avatar {
4746
guid String @id
4847
data Bytes
4948
}
5049

50+
model Picture {
51+
hash String @id
52+
data Bytes
53+
key String // password
54+
}
55+
5156
model InterestSubject {
5257
id Int @id @default(autoincrement())
5358
name String
5459
group String // such as Computer Science | name = ML
60+
Interest Interest[] // ignore this
5561
5662
@@unique([name, group])
57-
Interest Interest[] // ignore this
5863
}
5964

6065
// User->Interest->InterestSubject
@@ -122,8 +127,6 @@ enum MatchingStatus {
122127
REJECTED
123128
}
124129

125-
// TODO: lazy load MessageLog s.t. it doesn't need to be loaded on Overview query.
126-
// https://www.prisma.io/docs/orm/prisma-client/queries/select-fields
127130
model SharedRoom {
128131
id Int @id @default(autoincrement())
129132
thumbnail String // URL to thumbnail picture
@@ -134,10 +137,12 @@ model SharedRoom {
134137

135138
model Message {
136139
id Int @id @default(autoincrement())
137-
creator Int // refers to UserId
140+
creator Int // refers to UserId
138141
createdAt DateTime @default(now()) // @readonly
139142
edited Boolean @default(false)
140143
content String
144+
isPicture Boolean // iff the message is a picture. if true, then content is a url of picture.
145+
read Boolean @default(false)
141146
relation Relationship? @relation(fields: [relationId], references: [id], onDelete: Cascade)
142147
relationId Int?
143148
sharedRoom SharedRoom? @relation(fields: [sharedRoomId], references: [id], onDelete: Cascade)

0 commit comments

Comments
 (0)