diff --git a/docker-compose.yml b/docker-compose.yml index 53fe995..0e5d47c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,14 @@ services: mongodb: - image: mongo:latest + build: ./mongodb_rs hostname: mongodb restart: always - env_file: - - .env environment: - MONGO_INITDB_ROOT_USERNAME=temp-root-username - MONGO_INITDB_ROOT_PASSWORD=temp-password - MONGO_INITDB_DATABASE=chat_projetweb + - MONGO_REPLICA_HOST=localhost + - MONGO_REPLICA_PORT=27017 ports: - "27017:27017" volumes: diff --git a/mongodb_rs/Dockerfile b/mongodb_rs/Dockerfile new file mode 100644 index 0000000..9bbc3d1 --- /dev/null +++ b/mongodb_rs/Dockerfile @@ -0,0 +1,11 @@ +FROM mongo:5 + +# we take over the default & start mongo in replica set mode in a background task +ENTRYPOINT mongod --port $MONGO_REPLICA_PORT --replSet rs0 --bind_ip 0.0.0.0 & MONGOD_PID=$!; \ +# we prepare the replica set with a single node and prepare the root user config +INIT_REPL_CMD="rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: '$MONGO_REPLICA_HOST:$MONGO_REPLICA_PORT' }] })"; \ +INIT_USER_CMD="db.getUser('$MONGO_INITDB_ROOT_USERNAME') || db.createUser({ user: '$MONGO_INITDB_ROOT_USERNAME', pwd: '$MONGO_INITDB_ROOT_PASSWORD', roles: ['root'] })"; \ +# we wait for the replica set to be ready and then submit the command just above +until (mongo admin --port $MONGO_REPLICA_PORT --eval "$INIT_REPL_CMD && $INIT_USER_CMD"); do sleep 1; done; \ +# we are done but we keep the container by waiting on signals from the mongo task +echo "REPLICA SET ONLINE"; wait $MONGOD_PID; \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 71b0476..f8fda22 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -14,7 +14,7 @@ datasource db { } model User { - id String @id @default(cuid()) @map("_id") @db.ObjectId + id String @id @default(auto()) @map("_id") @db.ObjectId username String @unique surname String name String @@ -28,7 +28,7 @@ model User { } model Channel { - id String @id @default(cuid()) @map("_id") @db.ObjectId + id String @id @default(auto()) @map("_id") @db.ObjectId name String topic String users User[] @relation(fields: [userIDs], references: [id]) @@ -39,7 +39,7 @@ model Channel { } model Message { - id String @id @default(cuid()) @map("_id") @db.ObjectId + id String @id @default(auto()) @map("_id") @db.ObjectId user User @relation(fields: [userId], references: [id]) userId String @db.ObjectId channel Channel @relation(fields: [channelId], references: [id]) diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts new file mode 100644 index 0000000..d16c5d4 --- /dev/null +++ b/src/routes/+page.server.ts @@ -0,0 +1,21 @@ +import type { Actions } from '@sveltejs/kit'; +import prismaClient from '$lib/prismaClient'; + +export const actions: Actions = { + login: async ({request}) => { + const formData = await request.formData(); + + console.log(formData.get("username")); + + await prismaClient.user.create({ + data: { + email: "fdp", + username: "test", + surname: "azeza", + name: "aiudhza", + password: "feur" + } + }); + + } +} \ No newline at end of file diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 1645fab..cd1246a 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -3,6 +3,9 @@ import { Button } from "$lib/components/ui/button"; import { Input } from "$lib/components/ui/input"; import * as Card from "$lib/components/ui/card"; + import { enhance } from '$app/forms'; + +