LaCocoRoco
LaCocoRoco
DTDrizzle Team
Created by LaCocoRoco on 8/30/2024 in #help
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;
1 replies