DTDrizzle Team
Created by kinsyu on 12/1/2023 in #help
There's not enough information to infer relation
I am trying to use drizzle studio but I'm running into the following issue, There is not enough information to infer relation "__public__.collectionsTable.tokens". Here's a simplified version of the schema.
export const tokensTable = mysqlTable(
'tokens',
{
tokenId: varchar('token_id', { length: 255 }).notNull(),

metadataName: varchar('metadata_name', { length: 255 }),
metadataDescription: text('metadata_description'),
collectionId: varbinary('collection_id', {
length: 42,
}).notNull(),

createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)

export type Token = InferSelectModel<typeof tokensTable>
export type TokenInsert = InferInsertModel<typeof tokensTable>

export const tokensRelations = relations(tokensTable, ({ one }) => ({
collection: one(collectionsTable, {
fields: [tokensTable.collectionId],
references: [collectionsTable.id],
}),
}))

export const collectionsTable = mysqlTable(
'collections',
{
id: varbinary('id', {
length: 42,
}).primaryKey(),

name: varchar('name', {
length: 255,
}).notNull(),
description: text('description'),
createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)

export type Collection = InferSelectModel<typeof collectionsTable>
export type CollectionInsert = InferInsertModel<typeof collectionsTable>

export const collectionsRelations = relations(collectionsTable, ({ one, many }) => ({
tokens: many(tokensTable, {
relationName: 'collectionTokens',
}),
}))
export const tokensTable = mysqlTable(
'tokens',
{
tokenId: varchar('token_id', { length: 255 }).notNull(),

metadataName: varchar('metadata_name', { length: 255 }),
metadataDescription: text('metadata_description'),
collectionId: varbinary('collection_id', {
length: 42,
}).notNull(),

createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)

export type Token = InferSelectModel<typeof tokensTable>
export type TokenInsert = InferInsertModel<typeof tokensTable>

export const tokensRelations = relations(tokensTable, ({ one }) => ({
collection: one(collectionsTable, {
fields: [tokensTable.collectionId],
references: [collectionsTable.id],
}),
}))

export const collectionsTable = mysqlTable(
'collections',
{
id: varbinary('id', {
length: 42,
}).primaryKey(),

name: varchar('name', {
length: 255,
}).notNull(),
description: text('description'),
createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)

export type Collection = InferSelectModel<typeof collectionsTable>
export type CollectionInsert = InferInsertModel<typeof collectionsTable>

export const collectionsRelations = relations(collectionsTable, ({ one, many }) => ({
tokens: many(tokensTable, {
relationName: 'collectionTokens',
}),
}))
In short, each collection can have multiple tokens, but each token can belong to only one collection. I haven't had any issues with this schema for around the 6 months that we've been using it, but we wanted to try out drizzle studio and ran into that issue. The database is running on Planetscale, not sure if that's relevant.
3 replies
DTDrizzle Team
Created by iqrow on 5/24/2023 in #help
How to delete with cascade?
I'm using postgres with the following schema (reduced to the important parts):
export const worlds = pgTable('worlds', {
id: uuid('id').defaultRandom().primaryKey()
})
export const users_to_worlds = pgTable(
'users_to_worlds',
{
userId: varchar('user_id', { length: 32 })
.references(() => users.id)
.notNull(),
worldId: uuid('world_id')
.references(() => worlds.id)
.notNull(),
},
(table) => {
return {
pk: primaryKey(table.userId, table.worldId),
}
}
)
export const worlds = pgTable('worlds', {
id: uuid('id').defaultRandom().primaryKey()
})
export const users_to_worlds = pgTable(
'users_to_worlds',
{
userId: varchar('user_id', { length: 32 })
.references(() => users.id)
.notNull(),
worldId: uuid('world_id')
.references(() => worlds.id)
.notNull(),
},
(table) => {
return {
pk: primaryKey(table.userId, table.worldId),
}
}
)
And I'm trying to implement an api call to delete a world. Due to the reference to the world in the users_to_worlds I get the error: Error: update or delete on table "worlds" violates foreign key constraint "users_to_worlds_world_id_worlds_id_fk" on table "users_to_worlds" I believe what I want to use is a CASCADE delete where everything referencing a world is deleted when I delete a world. Is this possible through Drizzle? I can't seem to find anything on this.
7 replies
DTDrizzle Team
Created by McLean 25 on 4/5/2023 in #help
Can't find meta/_journal.json file when running migrate
3 replies
VVALORANT
Created by Mevix on 1/26/2024 in #community-help
secure boot verification failure
No description
219 replies
DTDrizzle Team
Created by Louistiti on 7/18/2023 in #help
Clear the whole database?
For my test environment I'd like to clear the whole db.. is there a way to achieve this using drizzle ?
59 replies
DTDrizzle Team
Created by eatmoose on 6/2/2023 in #help
Auto update timestamp fields
How to auto update fields like updated_at?
17 replies
VVALORANT
Created by ᲼᲼J on 2/24/2024 in #community-help
geforce nto detecting
No description
7 replies
DTDrizzle Team
Created by pablo on 9/21/2023 in #help
Does Drizzle support Microsoft SQL Server?
Does Drizzle support Microsoft SQL Server ?
3 replies
VVALORANT
Created by Derek on 12/16/2023 in #community-help
how do you check what you got banned for?
Help
15 replies
NNovu
Created by Sudhanshu on 10/15/2023 in #💬│support
How to install a specific version of 'pnpm'
As Novu using 7.33.4 version of pnpm but when I try to install pnpm then it install latest version but I don't want that, Ref : https://pnpm.io/installation#installing-a-specific-version from this link I got a command curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=<version> sh - but this command works only on mac as curl is not supported in windows.
9 replies
DTDrizzle Team
Created by fasm on 5/31/2023 in #help
update multiple rows
How can I update values in multiple rows at once?
28 replies
DTDrizzle Team
Created by paaradiso on 11/8/2023 in #help
Cannot read properties of undefined (reading 'referencedTable')
i'm just playing around with queries and i can't get this to work:
const liked = await db.query.collectionsTable.findMany({
with: {
likedCollectionsTable: true
}
});
const liked = await db.query.collectionsTable.findMany({
with: {
likedCollectionsTable: true
}
});
without the with it works. i'm passing the schemas to the db object:
export const db = drizzle(queryClient, { schema });
export const db = drizzle(queryClient, { schema });
and here are the two schemas:
export const likedCollectionsTable = pgTable('liked_collections', {
userId: text('user_id').references(() => usersTable.id),
collection_id: integer('collection_id').references(() => collectionsTable.id)
});

export const collectionsTable = pgTable('collections', {
id: integer('id').primaryKey(),
name: text('name'),
type: collectionTypeEnum('type'),
cover: text('cover'),
artist: text('artist'),
tags: text('tags')
.references(() => tagsTable.name)
.array(),
releaseDate: date('release_date'),
addedBy: text('added_by')
});
export const likedCollectionsTable = pgTable('liked_collections', {
userId: text('user_id').references(() => usersTable.id),
collection_id: integer('collection_id').references(() => collectionsTable.id)
});

export const collectionsTable = pgTable('collections', {
id: integer('id').primaryKey(),
name: text('name'),
type: collectionTypeEnum('type'),
cover: text('cover'),
artist: text('artist'),
tags: text('tags')
.references(() => tagsTable.name)
.array(),
releaseDate: date('release_date'),
addedBy: text('added_by')
});
12 replies
DTDrizzle Team
Created by Hocus on 12/5/2023 in #help
Updated drizzle-kit -> Error: Cannot find module 'drizzle-orm/pg-core'
I updated drizzle from:
"drizzle-orm": "^0.29.1",
"drizzle-kit": "^0.20.6",
"drizzle-orm": "^0.29.1",
"drizzle-kit": "^0.20.6",
to
"drizzle-orm": "^0.28.5",
"drizzle-kit": "^0.19.3",
"drizzle-orm": "^0.28.5",
"drizzle-kit": "^0.19.3",
I updated my config to use the new defineConfig method and changed the connectionString to uri
export default defineConfig({
schema: "./src/server/db/schema.ts",
driver: "mysql2",
dbCredentials: {
uri: env.DATABASE_URL,
},
tablesFilter: ["bun-loconta_*"],
});
export default defineConfig({
schema: "./src/server/db/schema.ts",
driver: "mysql2",
dbCredentials: {
uri: env.DATABASE_URL,
},
tablesFilter: ["bun-loconta_*"],
});
but now I am getting this error when I try to run drizzle-kit: Error: Cannot find module 'drizzle-orm/pg-core' I dont use postgres, my driver is mysql2 using PlanetScale as DB provider. my package.json - I am using bun run incase it matters:
"scripts": {
"db:push": "dotenv drizzle-kit push:mysql",
"db:studio": "dotenv drizzle-kit studio",
},
"scripts": {
"db:push": "dotenv drizzle-kit push:mysql",
"db:studio": "dotenv drizzle-kit studio",
},
7 replies
DTDrizzle Team
Created by ippo on 9/15/2023 in #help
TRIGGERS in Drizzle
Is there a way to define/implement TRIGGERs in Drizzle? An example would be great!
13 replies
DTDrizzle Team
Created by rushil1o1 on 8/17/2023 in #help
updatedAt timestamp update on DB row update
Whats the best way to update Postgres values for updatedAt --- I'm assuming there's a drizzle helper ? Can't find anything
2 replies
DTDrizzle Team
Created by Paul on 9/22/2023 in #help
TypeError: Seems like the schema generic is missing - did you forget to add it to your DB type?
How can I solve the following generic error relating to the db.query.users in my code below?
Property 'users' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> | { [x: string]:RelationalQueryBuilder<ExtractTablesWithRelations<any>, { ...; }>; }'.

Property 'users' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?">'.ts(2339)
Property 'users' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> | { [x: string]:RelationalQueryBuilder<ExtractTablesWithRelations<any>, { ...; }>; }'.

Property 'users' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?">'.ts(2339)
I'm trying to create an adapter that accepts a generic schema to instantiate a PostgresJsDatabase instance, or colloquially db. I've created the schema that is needed for this adapter, but how can I satisfy typescript when running db.query.user.findFirst()?
import { PostgresJsDatabase, drizzle } from "drizzle-orm/postgres-js";
import { Sql } from "postgres";
import * as schema from "./schema";
import { eq } from "drizzle-orm";

export function postgresAdapter<T extends typeof schema = any>(
sql: Sql,
schema: T
) {
const db = drizzle(sql, { schema });

const { users } = schema;

// This function works below
async function insertUser(
user: typeof users.$inferInsert
): Promise<void> {
await db
.insert(users)
.values(user)
.onConflictDoNothing({ target: users.id });
}

// I'm getting an error here at db.query
async function getUserById(
id: string
): Promise<typeof schema.users.$inferSelect | null> {
const user = await db.query.users.findFirst({
^ // Property 'users' does
// not exist on type
where: (users: any, { eq }) => eq(users.id, id),
});
return user || null;
}
}
import { PostgresJsDatabase, drizzle } from "drizzle-orm/postgres-js";
import { Sql } from "postgres";
import * as schema from "./schema";
import { eq } from "drizzle-orm";

export function postgresAdapter<T extends typeof schema = any>(
sql: Sql,
schema: T
) {
const db = drizzle(sql, { schema });

const { users } = schema;

// This function works below
async function insertUser(
user: typeof users.$inferInsert
): Promise<void> {
await db
.insert(users)
.values(user)
.onConflictDoNothing({ target: users.id });
}

// I'm getting an error here at db.query
async function getUserById(
id: string
): Promise<typeof schema.users.$inferSelect | null> {
const user = await db.query.users.findFirst({
^ // Property 'users' does
// not exist on type
where: (users: any, { eq }) => eq(users.id, id),
});
return user || null;
}
}
5 replies
FFilament
Created by GeRaged | Niklas on 8/29/2023 in #❓┊help
Filament\FilamentManager::getUserName(): Return value must be of type string, null returned
Is it possible to edit the user at Filament? I want instead of the name column, the columns firstname and lastname, but then comes the following error. How can I use my own columns without destroying the logic of filament Filament\FilamentManager::getUserName(): Return value must be of type string, null returned
2 replies
DTDrizzle Team
Created by mr_pablo on 5/24/2023 in #help
drop tables
Is there a way to do a migration to drop tables? Other ORMs like Sequelize and Prisma have a concept of up & down migrations, but Drizzle doesn't. Is there a Drizzle way to do a "down" migration?
23 replies
DTDrizzle Team
Created by Hussein on 10/26/2023 in #help
"Seems like the schema generic is missing - did you forget to add it to your DB type?"
how to fix this... i need to use db.query
19 replies
DTDrizzle Team
Created by johnnydt on 7/12/2023 in #help
testing best practices
Can anyone share how they're writing tests that involve drizzle? Looking for something similar to these docs for Prisma: https://www.prisma.io/docs/guides/testing/unit-testing
9 replies
DTDrizzle Team
Created by fermentfan on 7/30/2023 in #help
Mocking Drizzle instance
Hey there, I am currently trying to find a good way to mock our drizzle instance for our unit test suite, but the nature of the usage of it makes it kinda hard. Is there somebody who is running a code base with a mocked drizzle?
19 replies
PMPUBG MOBILE
Created by Deepblue on 2/2/2024 in #questions
Login failed. Please try again. (211, -541)j
Hello, i am getting this error while trying to login with phone number. Login failed. Please try again. (211, -541) I've tried to login on different devices getting same error. I've changed pw aswell but still same problem. Any idea? Thanks.
2 replies
DTDrizzle Team
Created by Guy on 8/27/2023 in #help
Reference to auth.users?
i was following ben davis video about sveltekit + supabase/drizzle. in his video he mention that he want to use sql file in supabase/migrations as a source of truth and then rewrote it in schema.ts,
create table profile (
id serial primary key,
first_name varchar(100),
last_name varchar(100),
email varchar(100),
user_id uuid references auth.users
);
create table profile (
id serial primary key,
first_name varchar(100),
last_name varchar(100),
email varchar(100),
user_id uuid references auth.users
);
but i prefer to use schema.ts as a source of truth then use the drizzle migrations.
export const profileTable = pgTable('profile', {
id: serial('id').primaryKey(),
last_name: varchar('last_name', { length: 100 }),
first_name: varchar('first_name', { length: 100 }),
email: varchar('email', { length: 100 }),
user_id: uuid('user_id').notNull().references(() => auth.users),
});
export const profileTable = pgTable('profile', {
id: serial('id').primaryKey(),
last_name: varchar('last_name', { length: 100 }),
first_name: varchar('first_name', { length: 100 }),
email: varchar('email', { length: 100 }),
user_id: uuid('user_id').notNull().references(() => auth.users),
});
the problem is that i can't reference the auth.users like in the .sql file
6 replies
HHomarr
Created by Bon on 2/24/2023 in #💬・get-help
Plex Integration Setup
Is there anything specific that needs to be done in order to connect Homarr to Plex? I'd assume an area to place the Plex instance URL, or some sort of API key field? I've enabled the Plex & Jellyfin widget but it doesn't seem to do anything. Thank you in advance!
67 replies