© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago
LaCocoRoco

Is it possible to add custom SQL for migration

I read about the possibility to add custom SQL for queries with sql.raw().
Is it somehow possible to add some additional SQL for migration like this?

// schema.ts

export const privateSchema = pgSchema('private');

export const dataTable = privateSchema.table('data', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
});

export type InsertData = typeof dataTable.$inferInsert;
export type SelectData = typeof dataTable.$inferSelect;

migrate(`
  ALTER TABLE ${privateSchema}.${dataTable}
    OWNER TO postgres;
`);
// schema.ts

export const privateSchema = pgSchema('private');

export const dataTable = privateSchema.table('data', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
});

export type InsertData = typeof dataTable.$inferInsert;
export type SelectData = typeof dataTable.$inferSelect;

migrate(`
  ALTER TABLE ${privateSchema}.${dataTable}
    OWNER TO postgres;
`);


SQL when generated:
CREATE SCHEMA IF NOT EXISTS "private"

CREATE TABLE IF NOT EXISTS "private"."data" (
  "id" serial PRIMARY KEY NOT NULL,
  "name" text NOT NULL
);

ALTER TABLE "private"."data"
  OWNER TO postgres;
CREATE SCHEMA IF NOT EXISTS "private"

CREATE TABLE IF NOT EXISTS "private"."data" (
  "id" serial PRIMARY KEY NOT NULL,
  "name" text NOT NULL
);

ALTER TABLE "private"."data"
  OWNER TO postgres;
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Define custom migration SQL for drizzle
Drizzle TeamDTDrizzle Team / help
2y ago
Custom SQL in migrations
Drizzle TeamDTDrizzle Team / help
3y ago
How to add custom SQL queries during or after migration in drizzle schema?
Drizzle TeamDTDrizzle Team / help
3y ago
Custom migration
Drizzle TeamDTDrizzle Team / help
15mo ago