Pupok
Pupok
Explore posts from servers
DTDrizzle Team
Created by Pupok on 8/9/2024 in #help
Error migrating "type does not exist"
im adding more stuff to my db, so i created this type and once i wanted to migrate i got his
[⢿] applying migrations...PostgresError: type "filetype" does not exist
at ErrorResponse (/home/alejandro/.dev/toyota-ro/node_modules/drizzle-kit/bin.cjs:79677:27)
at handle (/home/alejandro/.dev/toyota-ro/node_modules/drizzle-kit/bin.cjs:79454:7)
at Socket.data (/home/alejandro/.dev/toyota-ro/node_modules/drizzle-kit/bin.cjs:79277:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:128:17) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42704',
file: 'parse_type.c',
line: '270',
routine: 'typenameType'
}
[⢿] applying migrations...PostgresError: type "filetype" does not exist
at ErrorResponse (/home/alejandro/.dev/toyota-ro/node_modules/drizzle-kit/bin.cjs:79677:27)
at handle (/home/alejandro/.dev/toyota-ro/node_modules/drizzle-kit/bin.cjs:79454:7)
at Socket.data (/home/alejandro/.dev/toyota-ro/node_modules/drizzle-kit/bin.cjs:79277:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:128:17) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42704',
file: 'parse_type.c',
line: '270',
routine: 'typenameType'
}
the error is pointing out the type i created as lowercase, but its camel cased
export const fileTypeEnum = pgEnum('fileType', ['image/jpeg', 'application/pdf'])

export const files = pgTable('files', {
id: text('id').primaryKey(),
roId: text('roId').notNull(),
name: text('name').notNull(),
key: text('key').notNull(),
url: text('url').notNull(),
type: fileTypeEnum('type').notNull(),
createdAt: timestamp('createdAt').defaultNow().notNull()
})
export const fileTypeEnum = pgEnum('fileType', ['image/jpeg', 'application/pdf'])

export const files = pgTable('files', {
id: text('id').primaryKey(),
roId: text('roId').notNull(),
name: text('name').notNull(),
key: text('key').notNull(),
url: text('url').notNull(),
type: fileTypeEnum('type').notNull(),
createdAt: timestamp('createdAt').defaultNow().notNull()
})
the type exist in supabase, so i cant apply my other change because this one keeps on failing
DO $$ BEGIN
CREATE TYPE "public"."fileType" AS ENUM('image/jpeg', 'application/pdf');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
ALTER TABLE "files" ALTER COLUMN "type" SET DATA TYPE fileType;
DO $$ BEGIN
CREATE TYPE "public"."fileType" AS ENUM('image/jpeg', 'application/pdf');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
ALTER TABLE "files" ALTER COLUMN "type" SET DATA TYPE fileType;
17 replies
DTDrizzle Team
Created by Pupok on 8/7/2024 in #help
Is this the right way of using relations ?
hi, this is my first project using drizzle, and I'm not that good at sql query as mostly i use ORMs, but now im using drizzle to learn more sql like syntax, This is the schema is question:
export const repairOrder = pgTable(
'repairOrder',
{
id: text('id').primaryKey(),
userId: text('userId').notNull(),
mechanicId: text('mechanicId'),
status: roStatusEnum('status').notNull().default('part sent'),
roNumber: text('roNumber').notNull(),
carMaker: text('carMaker').notNull(),
carModel: text('carModel').notNull(),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt')
.defaultNow()
.$onUpdate(() => new Date())
} to
}
)

export const repairOrderFilesRelation = relations(repairOrder, ({ many }) => ({
files: many(files)
}))

export const files = pgTable(
'files',
{
id: text('id').primaryKey(),
roId: text('roId').notNull(),
name: text('name').notNull(),
key: text('key').notNull(),
url: text('url').notNull(),
type: text('type').notNull(),
}jjk
)

export const fileToRepairOrder = relations(files, ({ one }) => ({
repairOrder: one(repairOrder, {
fields: [files.roId],
references: [repairOrder.id]
})
}))
export const repairOrder = pgTable(
'repairOrder',
{
id: text('id').primaryKey(),
userId: text('userId').notNull(),
mechanicId: text('mechanicId'),
status: roStatusEnum('status').notNull().default('part sent'),
roNumber: text('roNumber').notNull(),
carMaker: text('carMaker').notNull(),
carModel: text('carModel').notNull(),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt')
.defaultNow()
.$onUpdate(() => new Date())
} to
}
)

export const repairOrderFilesRelation = relations(repairOrder, ({ many }) => ({
files: many(files)
}))

export const files = pgTable(
'files',
{
id: text('id').primaryKey(),
roId: text('roId').notNull(),
name: text('name').notNull(),
key: text('key').notNull(),
url: text('url').notNull(),
type: text('type').notNull(),
}jjk
)

export const fileToRepairOrder = relations(files, ({ one }) => ({
repairOrder: one(repairOrder, {
fields: [files.roId],
references: [repairOrder.id]
})
}))
and this is the query
const [data] = await db
.select()
.from(repairOrder)
.innerJoin(estimator, eq(estimator.id, repairOrder.userId))
.leftJoin(mechanic, eq(mechanic.id, repairOrder.mechanicId))
.where(eq(repairOrder.id, id))

const filesData = await db.select().from(files).where(eq(files.roId, id))
const [data] = await db
.select()
.from(repairOrder)
.innerJoin(estimator, eq(estimator.id, repairOrder.userId))
.leftJoin(mechanic, eq(mechanic.id, repairOrder.mechanicId))
.where(eq(repairOrder.id, id))

const filesData = await db.select().from(files).where(eq(files.roId, id))
I did the relation between files and repair orders, if i try to join them directly into one query (
leftJoin(files, eq(files.roId, repairOrder.id))
leftJoin(files, eq(files.roId, repairOrder.id))
) then it will only return 1 file, this is why i splitted it into 2 so i can get all, is this the right way of doing it?
17 replies