Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
Switch database to postgres (#58)
Browse files Browse the repository at this point in the history
* Switch database to postgres

* Fix port

* Run prettier

* up

* Make username not null
  • Loading branch information
maxidragon authored Nov 22, 2023
1 parent 863bdeb commit fe48574
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 15 deletions.
10 changes: 0 additions & 10 deletions prisma/migrations/20231014174534_init/migration.sql

This file was deleted.

12 changes: 12 additions & 0 deletions prisma/migrations/20231122113755_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"email" TEXT NOT NULL,
"username" TEXT,
"password" TEXT NOT NULL,

CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- Made the column `username` on table `User` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterTable
ALTER TABLE "User" ALTER COLUMN "username" SET NOT NULL;
2 changes: 1 addition & 1 deletion prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "mysql"
provider = "postgresql"
4 changes: 2 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ generator client {
}

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

model User {
id Int @id @default(autoincrement())
email String @unique
username String?
username String
password String
}

2 changes: 1 addition & 1 deletion src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class AuthService {
const isTaken = await this.isTaken(dto.username, dto.email);
if (isTaken) throw new ForbiddenException('Username or email is taken!');

const user = await this.prisma.user.create({
await this.prisma.user.create({
data: {
username: dto.username,
password: sha512(dto.password),
Expand Down
29 changes: 28 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as dotenv from 'dotenv';
import { ValidationPipe } from '@nestjs/common';

dotenv.config();

const { PORT = 5000 } = process.env;
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
transform: true,
transformOptions: { enableImplicitConversion: true },
}),
);
app.enableCors({
origin: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
allowedHeaders: [
'Authorization',
'X-Requested-With',
'Content-Type',
'Access-Control-Allow-Origin',
'Access-Control-Allow-Credentials',
'Origin',
],
});
await app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}...`);
});
}

bootstrap();

0 comments on commit fe48574

Please sign in to comment.