Skip to content

Commit

Permalink
feat: add new connection with mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
PiluVitu committed Sep 5, 2024
1 parent b2e5720 commit 36650d6
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 141 deletions.
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
HOSTNAME='localhost'
PORT=3000
SECRET_KEY='321'
DATABASE_URL="postgresql://postgres:password@localhost:5432/octopost"


MONGO_ROOT_USERNAME="octopost"
MONGO_ROOT_PASSWORD="1234"
MONGODB_ADMINUSERNAME="octopost"
MONGODB_ADMINPASSWORD="1234"
MONGO_CONTAINER_NAME="db-dev"
MONGO_CONTAINER_PORT="27017"
DATABASE_URL="mongodb://${MONGO_ROOT_USERNAME}:${MONGO_ROOT_PASSWORD}@${MONGO_CONTAINER_NAME}:${MONGO_CONTAINER_PORT}"
38 changes: 17 additions & 21 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
services:
db-dev: &db
db-dev:
profiles:
- dev
image: mongo:7.0.14-rc0-jammy
image: mongo
ports:
- '27017:27017'
- "27017:27017"
command: ["--replSet", "rs0", "--bind_ip_all", "--port", "27017"]
environment:
MONGO_INITDB_ROOT_USERNAME: $MONGO_ROOT_USERNAME
MONGO_INITDB_ROOT_PASSWORD: $MONGO_ROOT_PASSWORD
MONGO_INITDB_DATABASE: "octopost"
volumes:
- db:/var/lib/mongodb/mydata
- db-config:/data/config
healthcheck:
test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'rs0',members:[{_id:0,host:'host.docker.internal:27017'}]}) }" | mongosh --port 27017 --quiet
interval: 5s
timeout: 30s
start_period: 0s
start_interval: 1s
retries: 30
networks:
- octopost

mongo-express-dev: &mg-express
mongo-express-dev:
profiles:
- dev
image: mongo-express
Expand All @@ -22,7 +32,7 @@ services:
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: $MONGODB_ADMINUSERNAME
ME_CONFIG_MONGODB_ADMINPASSWORD: $MONGODB_ADMINPASSWORD
ME_CONFIG_MONGODB_URL: 'mongodb://octopost:1234@db-dev:27017'
ME_CONFIG_MONGODB_URL: "mongodb://octopost:1234@db-dev:27017"
ME_CONFIG_BASICAUTH: false
networks:
- octopost
Expand All @@ -35,28 +45,14 @@ services:
profiles:
- prod
ports:
- '${PORT}:${PORT}'
depends_on:
- db-prod
- "${PORT}:${PORT}"
networks:
- octopost

mongo-express-prod:
<<: *mg-express
profiles:
- prod
environment:
ME_CONFIG_BASICAUTH: false
ME_CONFIG_MONGODB_URL: 'mongodb://octopost:1234@db-prod:27017'

db-prod:
<<: *db
profiles:
- prod

networks:
octopost:
driver: bridge

volumes:
db:
db-config:
64 changes: 0 additions & 64 deletions prisma/migrations/20240502234532_init_db/migration.sql

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions prisma/migrations/20240624191001_add_in_my_pc/migration.sql

This file was deleted.

This file was deleted.

23 changes: 0 additions & 23 deletions prisma/migrations/20240722010704_rename_columns/migration.sql

This file was deleted.

3 changes: 0 additions & 3 deletions prisma/migrations/migration_lock.toml

This file was deleted.

16 changes: 8 additions & 8 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ generator client {
}

datasource db {
provider = "postgresql"
provider = "mongodb"
url = env("DATABASE_URL")
}

model User {
id String @id @default(uuid())
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
name String?
username String @unique
Expand All @@ -30,14 +30,14 @@ model User {
}

model Account {
id String @id @default(uuid())
id String @id @default(auto()) @map("_id") @db.ObjectId
name String?
username String?
socialMediaUserId String? @map("social_media_user_id") //Referes to the social media user id -> Twitter ID
avatarUrl String? @map("avatar_url")
userId String? @map("user_id")
userId String? @map("user_id") @db.ObjectId
favorite Boolean
socialMediaId Int @map("social_media_id")
socialMediaId String @map("social_media_id") @db.ObjectId
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
Expand All @@ -49,20 +49,20 @@ model Account {
}

model Token {
id Int @id @default(autoincrement())
id String @id @default(auto()) @map("_id") @db.ObjectId
authToken String? @map("auth_token")
token String?
issuedAt DateTime? @map("issued_at")
expiresIn Int? @map("expire_in")
accountId String @unique @map("account_id")
accountId String @unique @map("account_id") @db.ObjectId
account Account? @relation(fields: [accountId], references: [id])
@@map("tokens")
}

model SocialMedia {
id Int @id @default(autoincrement())
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
description String?
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* istanbul ignore file -- @preserve */

import { app } from '@/config/app';
import { env } from '@/config/env';

Expand Down
21 changes: 21 additions & 0 deletions src/teste.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { PrismaClient } from '@prisma/client';

const client = new PrismaClient({
log: ['info', 'warn', 'query', 'error'],
});

async function main() {
console.log('FOI');
const post = await client.user.create({
data: {
email: 'johndoe@example.com',
name: 'John Doe',
password: '001@Mypassword',
username: 'johndoe123',
},
});

console.log(post);
}

main();

0 comments on commit 36650d6

Please sign in to comment.