Migration failure on fresh DB

SSilentSean5/7/2023
I'm currently experiencing a migration failure on a fresh Postgres DB with both postgres.js and node-postgres. It's complaining that an enum I have defined in my schema (which should have created already as it's in the generated migration) does not exist.
⌛ Running Migrations
❌ Migration Failed
error: type "grandcompany" does not exist
at Parser.parseErrorMessage (g:\code\htg-app\node_modules\.pnpm\pg-protocol@1.6.0\node_modules\pg-protocol\dist\parser.js:287:98)
at Parser.handlePacket (g:\code\htg-app\node_modules\.pnpm\pg-protocol@1.6.0\node_modules\pg-protocol\dist\parser.js at Socket.<anonymous> (g:\code\htg-app\node_modules\.pnpm\pg-protocol@1.6.0\node_modules\pg-protocol\dist\index.js:11:42)
at Socket.emit (node:events:512:28)
at Socket.emit (node:domain:489:12)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 101,
severity: 'ERROR',
code: '42704',
detail: undefined,
hint: undefined,
position: '1817',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_type.c',
line: '270',
routine: 'typenameType'
}
⌛ Running Migrations
❌ Migration Failed
error: type "grandcompany" does not exist
at Parser.parseErrorMessage (g:\code\htg-app\node_modules\.pnpm\pg-protocol@1.6.0\node_modules\pg-protocol\dist\parser.js:287:98)
at Parser.handlePacket (g:\code\htg-app\node_modules\.pnpm\pg-protocol@1.6.0\node_modules\pg-protocol\dist\parser.js at Socket.<anonymous> (g:\code\htg-app\node_modules\.pnpm\pg-protocol@1.6.0\node_modules\pg-protocol\dist\index.js:11:42)
at Socket.emit (node:events:512:28)
at Socket.emit (node:domain:489:12)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 101,
severity: 'ERROR',
code: '42704',
detail: undefined,
hint: undefined,
position: '1817',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_type.c',
line: '270',
routine: 'typenameType'
}
Vvolks5/7/2023
Best to post your generated migration and the relevant schema file
ASAndrii Sherman5/7/2023
Make sure you export all entities in schema file before running the migration Enums should also be exported
SSilentSean5/7/2023
Yep, everything is exported.
import { pgEnum, pgTable, uuid, varchar } from 'drizzle-orm/pg-core';

export const grandCompany = pgEnum('grandCompany', ['Unknown', 'Maelstrom', 'Adder', 'Flames']);

export const character = pgTable('character', {
id: uuid('id').defaultRandom().primaryKey(),
xivId: varchar('xivId').notNull(),

server: varchar('server').notNull(),
dc: varchar('dc').notNull(),
name: varchar('name').notNull(),

grandCompany: grandCompany('grandCompany'),
});
import { pgEnum, pgTable, uuid, varchar } from 'drizzle-orm/pg-core';

export const grandCompany = pgEnum('grandCompany', ['Unknown', 'Maelstrom', 'Adder', 'Flames']);

export const character = pgTable('character', {
id: uuid('id').defaultRandom().primaryKey(),
xivId: varchar('xivId').notNull(),

server: varchar('server').notNull(),
dc: varchar('dc').notNull(),
name: varchar('name').notNull(),

grandCompany: grandCompany('grandCompany'),
});
DO $$ BEGIN
CREATE TYPE "grandCompany" AS ENUM('Unknown', 'Maelstrom', 'Adder', 'Flames');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

CREATE TABLE IF NOT EXISTS "character" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"xivId" varchar NOT NULL,
"server" varchar NOT NULL,
"dc" varchar NOT NULL,
"name" varchar NOT NULL,
"grandCompany" grandCompany
);
DO $$ BEGIN
CREATE TYPE "grandCompany" AS ENUM('Unknown', 'Maelstrom', 'Adder', 'Flames');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

CREATE TABLE IF NOT EXISTS "character" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"xivId" varchar NOT NULL,
"server" varchar NOT NULL,
"dc" varchar NOT NULL,
"name" varchar NOT NULL,
"grandCompany" grandCompany
);
ASAndrii Sherman5/7/2023
Yeah, that’s a bug. Will fix it 2 workarounds for now 1. Change 1 param in pgEnum to “grand_company” 2. Add double quotes to grandCompany in sql file. Do it before applying to database First should be better if you fine with snake case naming on database side You using latest drizzle kit version?
SSilentSean5/7/2023
Awesome, thanks! Yeah, I have drizzle kit 0.17.6 at the moment.
ASAndrii Sherman5/7/2023
Thanks!

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Using Vercel Postgres and developing locallyTo confirm, if I want to use Vercel Postgres in production and a local Postgres DB for development, Custom Type interpreted as StringHello everyone, I am having some issues with getting Drizzle to work with PostGIS, I am trying to haCan I use queryBuilder for inserts?My scenario is that I want to read some rows from a database (prod), and generate a SQL file that weI ran introspect:pg to initialize my schema, then created a new migration. How should I deploy this?The remote database, right now, doesn't have the `drizzle.__drizzle_migrations` table. It'd be nice Transaction rollbackHello guys. Kind of dumb question but should I cover body of transaction in try/catch and call rollberror creating relationshipI'm having trouble creating a relationship in MySQL using drizzle-orm, I'm running `npx drizzle-kit define default value for arrayI work with a PostgreSQL database. Here is my Schema: export const user = pgTable( 'auth_user',TS query types dont match + no return typesI'm trying to query data from my db after importing the Item table from my schema. `const data = awaCan't generate migrations because of top level awaitThis only recently started happening.Here is my `drizzle.config.json` : ```{ "out": "./migratError types with custom schemaHi, I'm trying to do a general function to paginate my querys, but I'm having some problems with theTrying to write next-auth adapterblahblahblahrober AKA @Dan Kochetov helped me get most of the way to having a next-auth adapter doneBeen getting this error while using the libsql client. The code works though. Any ideas. Thanks! 🙂I get the error from the screenshot every time I access my db client, but the code works fine thoughSelect wildcardI'm sure someone's asked this before but I can't find it. Is there not a way to do a `.select()` wiRangeError: Maximum call stack size exceeded - When I try to INSERTHi, I am getting `RangeError: Maximum call stack size exceeded` when I try to INSERT something in tTables are not being generatedHey 👋 I'm probably missing something obvious but with the setup I have (shown in the image) drizzlInserting records into related tablesI have a few of tables that are related. I just need to know if there's a better approach when inserinArrayFor what i've seen pass an empty array to inArray is not supported, how to you handle this cases? usInvalid default value when using defaultNow()Receiving error: ```js Invalid default value for 'updated_at' (errno 1067) (sqlstate 42000) (Caller