Skip to content

Commit

Permalink
refactor: renomeando tabelas e colunas
Browse files Browse the repository at this point in the history
  • Loading branch information
kvnbg committed Apr 30, 2024
1 parent de4cd06 commit fac2935
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 27 deletions.
90 changes: 90 additions & 0 deletions prisma/migrations/20240430104124_change_tables_names/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
Warnings:
- You are about to drop the `Account` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `SocialMedia` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Token` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `User` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "Account" DROP CONSTRAINT "Account_socialMediaId_fkey";

-- DropForeignKey
ALTER TABLE "Account" DROP CONSTRAINT "Account_userId_fkey";

-- DropForeignKey
ALTER TABLE "Token" DROP CONSTRAINT "Token_accountId_fkey";

-- DropTable
DROP TABLE "Account";

-- DropTable
DROP TABLE "SocialMedia";

-- DropTable
DROP TABLE "Token";

-- DropTable
DROP TABLE "User";

-- CreateTable
CREATE TABLE "users" (
"id" TEXT NOT NULL,
"email" TEXT NOT NULL,
"name" TEXT,
"password" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"deleted_at" TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE "accounts" (
"id" TEXT NOT NULL,
"avatar_url" TEXT NOT NULL,
"user_id" TEXT,
"social_media_id" INTEGER,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "tokens" (
"id" SERIAL NOT NULL,
"auth_token" TEXT NOT NULL,
"token" TEXT NOT NULL,
"issued_at" TIMESTAMP(3) NOT NULL,
"expire_in" INTEGER NOT NULL,
"account_id" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "social_media" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");

-- CreateIndex
CREATE UNIQUE INDEX "tokens_account_id_key" ON "tokens"("account_id");

-- AddForeignKey
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_social_media_id_fkey" FOREIGN KEY ("social_media_id") REFERENCES "social_media"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tokens" ADD CONSTRAINT "tokens_account_id_fkey" FOREIGN KEY ("account_id") REFERENCES "accounts"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
46 changes: 23 additions & 23 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,45 @@ datasource db {
url = env("DATABASE_URL")
}

model User {
model users {
id String @id @default(uuid())
email String @unique
name String?
password String
account Account[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
deletedAt DateTime?
account accounts[]
created_at DateTime @default(now())
updated_at DateTime @default(now())
deleted_at DateTime?
}

model Account {
model accounts {
id String @id @default(uuid())
avatarUrl String
userId String?
socialMediaId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User? @relation(fields: [userId], references: [id])
socialMedia SocialMedia? @relation(fields: [socialMediaId], references: [id])
Token Token?
avatar_url String
user_id String?
social_media_id Int?
created_at DateTime @default(now())
updated_at DateTime @updatedAt
user users? @relation(fields: [user_id], references: [id])
social_media social_media? @relation(fields: [social_media_id], references: [id])
token tokens?
}

model Token {
model tokens {
id Int @id @default(autoincrement())
authToken String
auth_token String
token String
issuedAt DateTime
expireIn Int
accountId String @unique
issued_at DateTime
expire_in Int
account_id String @unique
account Account? @relation(fields: [accountId], references: [id])
account accounts? @relation(fields: [account_id], references: [id])
}

model SocialMedia {
model social_media {
id Int @id @default(autoincrement())
name String
description String
account Account[]
account accounts[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('[Repositories] UserRepository', () => {

await repository.create(user);

expect(prisma.user.create).toHaveBeenCalledWith({
expect(prisma.users.create).toHaveBeenCalledWith({
data: user,
});
});
Expand All @@ -27,7 +27,7 @@ describe('[Repositories] UserRepository', () => {

const user = UserMock.create();

prisma.user.create.mockImplementationOnce(() => {
prisma.users.create.mockImplementationOnce(() => {
throw new Error('error');
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Prisma } from '@prisma/client';
import { database } from '@/shared/infra/database/database.js';

type CreateUserParams = Prisma.Args<typeof database.user, 'create'>['data'];
type CreateUserParams = Prisma.Args<typeof database.users, 'create'>['data'];

export class UserRepository {
async create({ email, name, password }: CreateUserParams) {
const user = await database.user.create({
const user = await database.users.create({
data: {
email,
name,
Expand Down

0 comments on commit fac2935

Please sign in to comment.