Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: drizzle-kit generate:pg generates faulty default arrays #634

Closed
lucaspiresfernandes opened this issue May 26, 2023 · 2 comments
Closed
Assignees
Labels
bug Something isn't working drizzle/kit

Comments

@lucaspiresfernandes
Copy link

What version of drizzle-orm are you using?

0.26.1

What version of drizzle-kit are you using?

0.18.1

Describe the Bug

import {
	pgEnum,
	pgTable,
	serial
} from 'drizzle-orm/pg-core';

export const CharacterType = ['player', 'npc', 'enemy'] as const;
export const CharacterTypeEnum = pgEnum('charactertype', CharacterType);

export const CampaignAttribute = pgTable(
	'campaignattribute',
	{
		id: serial('id').notNull(),
		characterType: CharacterTypeEnum('characterType')
			.array(3)
			.default(['player', 'npc', 'enemy'])
			.notNull()
			.$type<CharacterType[]>(),
	}
);

using drizzle-kit generate:pg generates this:

DO $$ BEGIN
 CREATE TYPE "charactertype" AS ENUM('player', 'npc', 'enemy');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;

CREATE TABLE IF NOT EXISTS "campaignattribute" (
	"id" serial NOT NULL,
	"characterType" charactertype[3] DEFAULT player,npc,enemy NOT NULL
);

This SQL is invalid inside PostgreSQL context as the characterType default constrait is not generated inside '{}'.

Expected behavior

Field characterType from campaignattribute should generate "characterType" charactertype[3] DEFAULT '{player,npc,enemy}' NOT NULL.

Environment & setup

No response

@lucaspiresfernandes lucaspiresfernandes added the bug Something isn't working label May 26, 2023
@AndriiSherman
Copy link
Member

Thanks! Taking that

@AndriiSherman AndriiSherman self-assigned this May 26, 2023
@Angelelz
Copy link
Collaborator

This issue here is the same as the #1003
I'll close this in favor of that one and I'll assign Andrew.
Please refer to #1344 for a discussion on how to work around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working drizzle/kit
Projects
None yet
Development

No branches or pull requests

3 participants