drizzle-kit push not working with pgSchema
Hello, this is my first time using Drizzle and am running into some problems pushing my schema out. I have the following
I am using a codebase first approach with Drizzle and have the following schema defined under the following path
And this is my
I was able to successfully do
Thanks in advance!
docker-compose.yamldocker-compose.yaml that is spinning up a Postgres instance alongside Adminer.services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
ports:
- 5432:5432
adminer:
image: adminer
restart: always
ports:
- 8080:8080services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
ports:
- 5432:5432
adminer:
image: adminer
restart: always
ports:
- 8080:8080I am using a codebase first approach with Drizzle and have the following schema defined under the following path
<project root>/drizzle/schema/auth.ts<project root>/drizzle/schema/auth.tsimport { sql } from "drizzle-orm";
import { boolean, check, pgRole, pgSchema, text, timestamp, uuid } from "drizzle-orm/pg-core";
export const admin = pgRole("admin", { createRole: true, createDb: true, inherit: true });
export const authSchema = pgSchema("auth");
export const user = authSchema.table("user", {
id: uuid("id").defaultRandom().primaryKey(),
name: text("name").notNull(),
username: text("username").notNull().unique(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").notNull(),
image: text("image"),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
});
export const userAccount = authSchema.table(
"useraccount",
{
id: uuid("id").defaultRandom().primaryKey(),
accountId: text("account_id"),
providerId: text("provider_id"),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
accessToken: text("access_token"),
refreshToken: text("refresh_token"),
idToken: text("id_token"),
scope: text("scope"),
password: text("password").notNull(),
accessTokenExpiresAt: timestamp("access_token_expires_at", { withTimezone: true }),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at", { withTimezone: true }),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
},
(table) => [
{
checkConstraint: check("password_check", sql`char_length(${table.password}) >= 8`),
},
],
);
export const session = authSchema.table("session", {
id: uuid("id").defaultRandom().primaryKey(),
token: text("token").notNull().unique(),
ipAddress: text("ip_address"),
userAgent: text("user_agent"),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
expiresAt: timestamp("expires_at", { withTimezone: true }).default(
sql`(now() + interval '7 days')`,
),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
});
export const verification = authSchema.table("verification", {
id: uuid("id").defaultRandom().primaryKey(),
identifier: text("identifier").notNull(),
value: text("value").notNull(),
expiresAt: timestamp("expires_at", { withTimezone: true }).default(
sql`(now() + interval '7 days')`,
),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
});import { sql } from "drizzle-orm";
import { boolean, check, pgRole, pgSchema, text, timestamp, uuid } from "drizzle-orm/pg-core";
export const admin = pgRole("admin", { createRole: true, createDb: true, inherit: true });
export const authSchema = pgSchema("auth");
export const user = authSchema.table("user", {
id: uuid("id").defaultRandom().primaryKey(),
name: text("name").notNull(),
username: text("username").notNull().unique(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").notNull(),
image: text("image"),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
});
export const userAccount = authSchema.table(
"useraccount",
{
id: uuid("id").defaultRandom().primaryKey(),
accountId: text("account_id"),
providerId: text("provider_id"),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
accessToken: text("access_token"),
refreshToken: text("refresh_token"),
idToken: text("id_token"),
scope: text("scope"),
password: text("password").notNull(),
accessTokenExpiresAt: timestamp("access_token_expires_at", { withTimezone: true }),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at", { withTimezone: true }),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
},
(table) => [
{
checkConstraint: check("password_check", sql`char_length(${table.password}) >= 8`),
},
],
);
export const session = authSchema.table("session", {
id: uuid("id").defaultRandom().primaryKey(),
token: text("token").notNull().unique(),
ipAddress: text("ip_address"),
userAgent: text("user_agent"),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
expiresAt: timestamp("expires_at", { withTimezone: true }).default(
sql`(now() + interval '7 days')`,
),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
});
export const verification = authSchema.table("verification", {
id: uuid("id").defaultRandom().primaryKey(),
identifier: text("identifier").notNull(),
value: text("value").notNull(),
expiresAt: timestamp("expires_at", { withTimezone: true }).default(
sql`(now() + interval '7 days')`,
),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
});And this is my
drizzle.config.tsdrizzle.config.ts:import { defineConfig } from "drizzle-kit";
export default defineConfig({
dialect: "postgresql",
schema: "./drizzle/schema/*",
out: "./drizzle/migrations/",
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});import { defineConfig } from "drizzle-kit";
export default defineConfig({
dialect: "postgresql",
schema: "./drizzle/schema/*",
out: "./drizzle/migrations/",
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});I was able to successfully do
drizzle-kit pushdrizzle-kit push and I did this while my databse was running in a container. However, when I open up Adminer to inspect the database, I do not see my authauth schema shown in the UI nor any of the tables I have defined. Hoping someone can assist me here.Thanks in advance!