Zephury
Zephury
DTDrizzle Team
Created by Zephury on 11/20/2023 in #help
I swear this infer was working... am I crazy?
everything seems to work. just no types. I haven't tested extensively, but I haven't had any actual problems. If I understood correctly, drizzle-kit studio needs to have the relations, as you see in userRelations, from my example in order to work though? I was not able to use drizzle-kit studio unless I provided the userRelations. I believe that is the expected behavior though?
14 replies
DTDrizzle Team
Created by Zephury on 11/20/2023 in #help
I swear this infer was working... am I crazy?
https://github.com/drizzle-team/drizzle-orm/issues/1502 this is exactly the issue I have, for reference
14 replies
DTDrizzle Team
Created by zeekrey on 11/24/2023 in #help
Is there a --force flag for drizzle-kit push?
yeah... getting really sick of having to wipe my entire database every time I want a new migration during development. Makes me very apprehensive to use in prod. In my case, I had an id field that was a bigint, which used to be a generated id; it's for languages, so I decided to switch the id field to varchar and use iso language abbreviations instead, but I can't push, nor complete a migration with it:
error: foreign key constraint "profile_language_language_id_language_id_fk" cannot be implemented
at D:\dev\{{project_name}}\api\node_modules\drizzle-kit\bin.cjs:24378:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgPostgres.query (D:\dev\{{project_name}}\api\node_modules\drizzle-kit\bin.cjs:25339:21)
at async Command.<anonymous> (D:\dev\{{project_name}}\api\node_modules\drizzle-kit\bin.cjs:61152:9) {
length: 257,
severity: 'ERROR',
code: '42804',
detail: 'Key columns "language_id" and "id" are of incompatible types: character varying and bigint.',
error: foreign key constraint "profile_language_language_id_language_id_fk" cannot be implemented
at D:\dev\{{project_name}}\api\node_modules\drizzle-kit\bin.cjs:24378:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgPostgres.query (D:\dev\{{project_name}}\api\node_modules\drizzle-kit\bin.cjs:25339:21)
at async Command.<anonymous> (D:\dev\{{project_name}}\api\node_modules\drizzle-kit\bin.cjs:61152:9) {
length: 257,
severity: 'ERROR',
code: '42804',
detail: 'Key columns "language_id" and "id" are of incompatible types: character varying and bigint.',
checked every file and did a file search to see if anything still tried implementing it as a foreign key, but no, all foreign key references are switched to varchar as well. There is no more bigint related to language in my application.
2 replies
DTDrizzle Team
Created by Zephury on 11/20/2023 in #help
I swear this infer was working... am I crazy?
thank you. I will create one as soon as I'm able to find the time
14 replies
DTDrizzle Team
Created by Zephury on 11/20/2023 in #help
I swear this infer was working... am I crazy?
export enum UserRole {
MANAGER = 'manager',
MAINTAINER = 'maintainer',
AUTHOR = 'author',
TRANSLATOR = 'translator',
MEMBER = 'member',
USER = 'user',
}

export type User = typeof user.$inferSelect;

export const user = pgTable('user', {
id: bigint('id', { mode: 'bigint' }).primaryKey(),
profileId: bigint('profile_id', { mode: 'bigint' })
.unique()
.references(() => profile.id),
discordId: varchar('discord_id', { length: 256 }),
discordUsername: varchar('discord_username', { length: 256 }),
discordDiscriminator: varchar('discord_discriminator', { length: 256 }),
discordGlobalName: varchar('discord_global_name', { length: 256 }),
discordAccessToken: varchar('discord_access_token', { length: 256 }),
discordRefreshToken: varchar('discord_refresh_token', { length: 256 }),
discordAvatar: varchar('discord_avatar', { length: 256 }),
roles: json('role').default(['user']).notNull().$type<UserRole[]>(),
isAdmin: boolean('is_admin').default(false),
isBanned: boolean('is_banned').default(false),
editLanguages: json('edit_languages'),
createdAt: timestamp('created_at').defaultNow(),
updatedAt: timestamp('updated_at').defaultNow(),
});

export const userRelations = relations(user, ({ one }) => ({
profile: one(profile, {
fields: [user.profileId],
references: [profile.id],
}),
}));
export enum UserRole {
MANAGER = 'manager',
MAINTAINER = 'maintainer',
AUTHOR = 'author',
TRANSLATOR = 'translator',
MEMBER = 'member',
USER = 'user',
}

export type User = typeof user.$inferSelect;

export const user = pgTable('user', {
id: bigint('id', { mode: 'bigint' }).primaryKey(),
profileId: bigint('profile_id', { mode: 'bigint' })
.unique()
.references(() => profile.id),
discordId: varchar('discord_id', { length: 256 }),
discordUsername: varchar('discord_username', { length: 256 }),
discordDiscriminator: varchar('discord_discriminator', { length: 256 }),
discordGlobalName: varchar('discord_global_name', { length: 256 }),
discordAccessToken: varchar('discord_access_token', { length: 256 }),
discordRefreshToken: varchar('discord_refresh_token', { length: 256 }),
discordAvatar: varchar('discord_avatar', { length: 256 }),
roles: json('role').default(['user']).notNull().$type<UserRole[]>(),
isAdmin: boolean('is_admin').default(false),
isBanned: boolean('is_banned').default(false),
editLanguages: json('edit_languages'),
createdAt: timestamp('created_at').defaultNow(),
updatedAt: timestamp('updated_at').defaultNow(),
});

export const userRelations = relations(user, ({ one }) => ({
profile: one(profile, {
fields: [user.profileId],
references: [profile.id],
}),
}));
14 replies
DTDrizzle Team
Created by Zephury on 11/20/2023 in #help
I swear this infer was working... am I crazy?
So it seems its just something I’ll have to wait and hope for an eventual fix with? I’m not sure exactly what you mean by the 3rd parameter. Could you give me a rough example? I suppose it did happen around the time I was messing with relations and inferred relations
14 replies
DTDrizzle Team
Created by Zephury on 11/20/2023 in #help
I swear this infer was working... am I crazy?
I tried deleting all caches, restarting vs code, restarting ts server and still, no luck 🥲
14 replies