Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added half the tables to drizzle #13

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,53 @@ Una plataforma de retroalimentación y evaluación para empleados dentro de una

![Mockup](mockup.png)

# 📚 Usage

To spawn the postgres container and get into it

```bash
docker pull postgres
docker run --name feedbackflow-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres
docker exec -it feedbackflow-postgres psql -U postgres
```

Create the database before running

```sql
CREATE DATABASE feedbackflow_db;
\l
```

Push the schema directly to the database

```bash
npx drizzle-kit push:pg
```

Show the created tables

```
\c feedbackflow_db
\dt
```

Make sure you have the right `.env.local` file in your project

```env
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=<YOUR KEY>
CLERK_SECRET_KEY=<YOUR KEY>
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/
```

To run the app

```bash
npm run dev
```

## Problema

Muchas empresas no cuentan con un sistema para dar retroalimentación entre los empleados, o si lo tienen, está de una manera muy sesgada, esto hace que muchas veces no se reconozca el esfuerzo de ciertos empleados que van muy bien, y no se le de un plan de mejora a aquellos que no van tan bien.
Expand Down
14 changes: 14 additions & 0 deletions db/drizzle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { drizzle } from "drizzle-orm/node-postgres";
import { Client } from "pg";

const client = new Client({
host: "127.0.0.1",
port: 5432,
user: "postgres",
password: "mysecretpassword",
database: "feedbackflow_db",
});

const db = drizzle(client);

export default db;
109 changes: 109 additions & 0 deletions db/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import {
boolean,
date,
integer,
pgEnum,
pgTable,
primaryKey,
varchar,
} from "drizzle-orm/pg-core";

export const userRoleEnum = pgEnum("role", ["employee", "manager"]);

export const user = pgTable("user", {
id: integer("id").primaryKey(),
name: varchar("name", { length: 32 }),
email: varchar("email", { length: 32 }),
jobTitle: varchar("job_title", { length: 32 }),
department: varchar("department", { length: 32 }),
photoUrl: varchar("photo_url", { length: 32 }),
role: userRoleEnum("role"),
});

export const project = pgTable("project", {
id: integer("id").primaryKey(),
managerId: integer("manager_id").references(() => user.id),
name: varchar("name", { length: 32 }),
description: varchar("description", { length: 256 }),
startDate: date("start_date"),
endDate: date("end_date"),
sprintSurveyPeriodicity: integer("sprint_survey_periodicity"),
});

export const projectMember = pgTable(
"project_member",
{
userId: integer("user_id").references(() => user.id),
projectId: integer("project_id").references(() => project.id),
startDate: date("start_date"),
endDate: date("end_date"),
},
// composite primary key on (userId, projectId)
(table) => {
return {
pk: primaryKey({ columns: [table.userId, table.projectId] }),
};
},
);

export const traitKindEnum = pgEnum("kind", ["employee", "manager"]);

export const trait = pgTable("trait", {
id: integer("id").primaryKey(),
name: varchar("name", { length: 32 }),
description: varchar("description", { length: 256 }),
kind: traitKindEnum("kind"),
});

export const userTrait = pgTable(
"user_trait",
{
userId: integer("user_id").references(() => user.id),
traitId: integer("trait_id").references(() => trait.id),
},
// composite primary key on (userId, traitId)
(table) => {
return {
pk: primaryKey({ columns: [table.userId, table.traitId] }),
};
},
);

export const pipTask = pgTable("pip_task", {
id: integer("id").primaryKey(),
userId: integer("user_id").references(() => user.id),
title: varchar("title", { length: 32 }),
description: varchar("description", { length: 256 }),
isDone: boolean("is_done"),
});

export const pipResource = pgTable("pip_resource", {
id: integer("id").primaryKey(),
userId: integer("user_id").references(() => user.id),
title: varchar("title", { length: 32 }),
description: varchar("description", { length: 256 }),
});

export const rulerSurvey = pgTable("ruler_survey", {
id: integer("id").primaryKey(),
createdAt: date("created_at"),
});

export const quadrantEnum = pgEnum("quadrant", ["1", "2", "3", "4"]);

export const rulerSurveyAnswers = pgTable(
"ruler_survey_answers",
{
rulerSurveyId: integer("ruler_survey_id").references(() => rulerSurvey.id),
userId: integer("user_id").references(() => user.id),
quadrant: quadrantEnum("quadrant"),
emotion: varchar("emotion", { length: 16 }),
createdAt: date("created_at"),
},
// composite primary key on (userId, rulerSurveyId)
(table) => {
return {
pk: primaryKey({ columns: [table.userId, table.rulerSurveyId] }),
};
},
);
14 changes: 14 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Config } from "drizzle-kit";

export default {
schema: "./db/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
host: "127.0.0.1",
port: 5432,
user: "postgres",
password: "mysecretpassword",
database: "feedbackflow_db",
},
} satisfies Config;
Binary file modified mockup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading