Skip to content

Commit

Permalink
fix: separate pg schema into it's own file
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniciusCestarii committed Dec 16, 2024
1 parent 1b959ff commit 0993621
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export * from "@/modules/shared/schema";

export * from "@/modules/pet/drizzle";
export * from "@/modules/pet/pets/pet";
export * from "@/modules/pet/species/specie";
export * from "@/modules/pet/breeds/breed";

export * from "@/modules/health/drizzle";
export * from "@/modules/health/patients/patient";
3 changes: 3 additions & 0 deletions src/modules/health/drizzle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { pgSchema } from "drizzle-orm/pg-core";

export const healthPgSchema = pgSchema("health");
7 changes: 3 additions & 4 deletions src/modules/health/patients/patient.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { sexEnum } from "@/db/schema";
import { date, pgSchema, uuid, varchar } from "drizzle-orm/pg-core";
import { date, uuid, varchar } from "drizzle-orm/pg-core";
import { v7 } from "uuid";
import { healthPgSchema } from "../drizzle";

export const healthSchema = pgSchema("health");

export const patientsTable = healthSchema.table("patients", {
export const patientsTable = healthPgSchema.table("patients", {
id: uuid().primaryKey().$defaultFn(v7),
name: varchar({ length: 255 }).notNull(),
birthdate: date().notNull(),
Expand Down
7 changes: 3 additions & 4 deletions src/modules/pet/breeds/breed.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { pgSchema, uuid, varchar } from "drizzle-orm/pg-core";
import { uuid, varchar } from "drizzle-orm/pg-core";
import { v7 } from "uuid";
import { speciesTable } from "../species/specie";
import { petPgSchema } from "../drizzle";

export const petSchema = pgSchema("pet");

export const breedsTable = petSchema.table("breeds", {
export const breedsTable = petPgSchema.table("breeds", {
id: uuid().primaryKey().$defaultFn(v7),
name: varchar({ length: 255 }).notNull(),
speciesId: uuid()
Expand Down
3 changes: 3 additions & 0 deletions src/modules/pet/drizzle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { pgSchema } from "drizzle-orm/pg-core";

export const petPgSchema = pgSchema("pet");
7 changes: 3 additions & 4 deletions src/modules/pet/pets/pet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { date, pgSchema, uuid, varchar } from "drizzle-orm/pg-core";
import { date, uuid, varchar } from "drizzle-orm/pg-core";
import { v7 } from "uuid";
import { breedsTable } from "../breeds/breed";
import { speciesTable } from "../species/specie";
import { sexEnum } from "@/db/schema";
import { petPgSchema } from "../drizzle";

export const petSchema = pgSchema("pet");

export const petsTable = petSchema.table("pets", {
export const petsTable = petPgSchema.table("pets", {
id: uuid().primaryKey().$defaultFn(v7),
name: varchar({ length: 255 }).notNull(),
birthdate: date().notNull(),
Expand Down
7 changes: 3 additions & 4 deletions src/modules/pet/species/specie.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { pgSchema, uuid, varchar } from "drizzle-orm/pg-core";
import { uuid, varchar } from "drizzle-orm/pg-core";
import { v7 } from "uuid";
import { petPgSchema } from "../drizzle";

export const petSchema = pgSchema("pet");

export const speciesTable = petSchema.table("species", {
export const speciesTable = petPgSchema.table("species", {
id: uuid().primaryKey().$defaultFn(v7),
name: varchar({ length: 255 }).notNull().unique(),
});

0 comments on commit 0993621

Please sign in to comment.