Use a different schema on postgres

Hello, I am currently trying to define a table with drizzle like this:
const rollupAccountResponsesDaily = pgTable('rollup_account_responses_daily', {
rollupDate: timestamp('rollup_date', { withTimezone: true }),
accountId: uuid('account_id'),
questionId: text('question_id'),
source: text('source'),
msa: text('msa'),
response: text('response'),
metrics: jsonb('metrics'),
createdAt: timestamp('created_at', { withTimezone: true }),
updatedAt: timestamp('updated_at', { withTimezone: true }),
});
const rollupAccountResponsesDaily = pgTable('rollup_account_responses_daily', {
rollupDate: timestamp('rollup_date', { withTimezone: true }),
accountId: uuid('account_id'),
questionId: text('question_id'),
source: text('source'),
msa: text('msa'),
response: text('response'),
metrics: jsonb('metrics'),
createdAt: timestamp('created_at', { withTimezone: true }),
updatedAt: timestamp('updated_at', { withTimezone: true }),
});
But this table is not on the public schema on postgres, is there a way to change the schema so that the generated code will be "sandbox.rollup_account_responses_daily" ? Thanks
1 Reply
Pipriles
PiprilesOP2y ago
Update: You can define a custom schema like this
import { timestamp, text, jsonb, uuid, pgSchema } from 'drizzle-orm/pg-core';

export const sandbox = pgSchema("sandbox")

export const rollupAccountResponsesDaily = sandbox.table('rollup_account_responses_daily', {
rollupDate: timestamp('rollup_date', { withTimezone: true }),
accountId: uuid('account_id'),
questionId: text('question_id'),
source: text('source'),
msa: text('msa'),
response: text('response'),
metrics: jsonb('metrics'),
createdAt: timestamp('created_at', { withTimezone: true }),
updatedAt: timestamp('updated_at', { withTimezone: true }),
});
import { timestamp, text, jsonb, uuid, pgSchema } from 'drizzle-orm/pg-core';

export const sandbox = pgSchema("sandbox")

export const rollupAccountResponsesDaily = sandbox.table('rollup_account_responses_daily', {
rollupDate: timestamp('rollup_date', { withTimezone: true }),
accountId: uuid('account_id'),
questionId: text('question_id'),
source: text('source'),
msa: text('msa'),
response: text('response'),
metrics: jsonb('metrics'),
createdAt: timestamp('created_at', { withTimezone: true }),
updatedAt: timestamp('updated_at', { withTimezone: true }),
});
Want results from more Discord servers?
Add your server