rcamf
rcamf
DTDrizzle Team
Created by rcamf on 1/17/2025 in #help
Grant Privileges to Role
I created roles in my project using the pgRole() in order to enable RLS on my database. After running the migration my user has no privileges on my tables and cannot access them. How can I grant all privileges to my role?
1 replies
DTDrizzle Team
Created by rcamf on 1/10/2025 in #help
Enum in Unique Constraint throws error.
Environment: drizzle-orm "0.36.0" I have one file that has an enum:
export const myEnum = pgEnum('myEnum', ['A', 'B', 'C']);
export const myEnum = pgEnum('myEnum', ['A', 'B', 'C']);
In another file I am importing that enum and using it for a column in my table with a unique check over multiple columns:
export const myTable = pgTable('my_table', {
id: uuid('id').primaryKey().defaultRandom(),
a: uuid('a').notNull(),
b: uuid('b').notNull(),
c: myEnum('c').notNull(),
}, table => [
unique('my_unique_constraint').on(table.a, table.b, table.c)
]);
export const myTable = pgTable('my_table', {
id: uuid('id').primaryKey().defaultRandom(),
a: uuid('a').notNull(),
b: uuid('b').notNull(),
c: myEnum('c').notNull(),
}, table => [
unique('my_unique_constraint').on(table.a, table.b, table.c)
]);
I get the following error message when executing:
TypeError: (0 , _1.myEnum) is not a function
at Object.<anonymous> (/Users/swifty/Work/platform/apps/api/src/drizzle/notifications/job-subscriptions.schema.ts:16:41)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (/Users/swifty/Work/platform/apps/api/src/drizzle/notifications/index.ts:12:1)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)

Node.js v20.11.0
TypeError: (0 , _1.myEnum) is not a function
at Object.<anonymous> (/Users/swifty/Work/platform/apps/api/src/drizzle/notifications/job-subscriptions.schema.ts:16:41)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (/Users/swifty/Work/platform/apps/api/src/drizzle/notifications/index.ts:12:1)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)

Node.js v20.11.0
When removing the constraint or moving the enum to the same file (which is not possible since I need it in multiple places) the error disappears. Does anyone have any clue why this happens?
2 replies
DTDrizzle Team
Created by rcamf on 2/15/2024 in #help
Type of relations when using with is not correctly set
I have two schemas:
export const jobs = pgTable('job', {
...primaryId,
});

export const setups = pgTable('setup', {
...primaryId,
jobId: uuid('job_id')
.notNull()
.references(() => jobs.id, {
onDelete: 'cascade',
}),
});
export const jobs = pgTable('job', {
...primaryId,
});

export const setups = pgTable('setup', {
...primaryId,
jobId: uuid('job_id')
.notNull()
.references(() => jobs.id, {
onDelete: 'cascade',
}),
});
They are in a one-to-one relation with the relations defined:
export const jobRelations = relations(jobs, ({ one }) => ({
setup: one(setups),
}));

export const setupRelations = relations(setups, ({ one }) => ({
job: one(jobs, {
fields: [setups.jobId],
references: [jobs.id],
}),
}));
export const jobRelations = relations(jobs, ({ one }) => ({
setup: one(setups),
}));

export const setupRelations = relations(setups, ({ one }) => ({
job: one(jobs, {
fields: [setups.jobId],
references: [jobs.id],
}),
}));
However when I run following query the setup property on a job is not properly typed:
const data = await db.query.jobs.findFirst({
with: {
setup: true
}
});
const data = await db.query.jobs.findFirst({
with: {
setup: true
}
});
Instead it has following type:
(property) setup: {
[x: string]: any;
} | {
[x: string]: any;
}[] | null | undefined
(property) setup: {
[x: string]: any;
} | {
[x: string]: any;
}[] | null | undefined
I tried following the other posts to solve this in the discord and also created the IncludeRelations type that was suggested in other similar posts, but nothing seems to be working for me.
4 replies