Nick
Nick
Explore posts from servers
DTDrizzle Team
Created by Nick on 9/18/2024 in #help
Sharing a database - Keeps trying to drop other tables when pushing tables with the different prefix
So I've got tables with the prefix chris-woodward-gallery and cars-under-20k. I was learning, and still am, so want to make the use of vercel's free db. Problem is I've set up my schema to prefix the tables, and removed any reference to the chris-woodward-gallery variant, but when I push it still say it's trying to drop those tables. As a big-old-noob I'm struggling to debug this tbh:
PostgresError: cannot drop sequence "chris-woodward-gallery_address_id_seq" because other objects depend on it
//snip
severity_local: 'ERROR',
severity: 'ERROR',
code: '2BP01',
detail: 'default value for column id of table "chris-woodward-gallery_address" depends on sequence "chris-woodward-gallery_address_id_seq"',
hint: 'Use DROP ... CASCADE to drop the dependent objects too.',
file: 'dependency.c',
line: '1204',
}
PostgresError: cannot drop sequence "chris-woodward-gallery_address_id_seq" because other objects depend on it
//snip
severity_local: 'ERROR',
severity: 'ERROR',
code: '2BP01',
detail: 'default value for column id of table "chris-woodward-gallery_address" depends on sequence "chris-woodward-gallery_address_id_seq"',
hint: 'Use DROP ... CASCADE to drop the dependent objects too.',
file: 'dependency.c',
line: '1204',
}
2 replies
DTDrizzle Team
Created by Nick on 7/23/2024 in #help
Querying and typing a many to many relationship?
So I'm enjoying using drizzle, but querying a many to many relationship seems a bit verbose, which makes me think I'm doing it wrong. It's also making using drizzle-zod a bit confusing: So I've set up my tables, user and profile
// Drizzle relationships:
export const userRelations = relations(users, ({ many }) => ({
usersToProfiles: many(userToProfiles),
}));

export const profileRelations = relations(profiles, ({ many }) => ({
usersToProfiles: many(usersToProfiles),
}));

export const usersToProfilesRelations = relations(
usersToProfiles,
({ one }) => ({
user: one(users, {
fields: [usersToProfiles.userId],
references: [users.id],
}),
profiles: one(profiles, {
fields: [usersToProfiles.profileId],
references: [profiles.id],
}),
}),
);

// Querying all users and their profiles
const listings = await db.query.users.findMany({
with: {
usersToProfiles: {
with: {
profiles: true,
},
},
},
});
// Drizzle relationships:
export const userRelations = relations(users, ({ many }) => ({
usersToProfiles: many(userToProfiles),
}));

export const profileRelations = relations(profiles, ({ many }) => ({
usersToProfiles: many(usersToProfiles),
}));

export const usersToProfilesRelations = relations(
usersToProfiles,
({ one }) => ({
user: one(users, {
fields: [usersToProfiles.userId],
references: [users.id],
}),
profiles: one(profiles, {
fields: [usersToProfiles.profileId],
references: [profiles.id],
}),
}),
);

// Querying all users and their profiles
const listings = await db.query.users.findMany({
with: {
usersToProfiles: {
with: {
profiles: true,
},
},
},
});
I'm then not sure how to extend the User schema with its usersToProfiles and its Profiles:
export const userSchema = createInsertSchema(users);
export const UserWithProfilesSchema = userSchema.extend() // not sure how to extend here
export type UserWithProfileType = z.infer<typeof UserWithProfileSchema>;
export const userSchema = createInsertSchema(users);
export const UserWithProfilesSchema = userSchema.extend() // not sure how to extend here
export type UserWithProfileType = z.infer<typeof UserWithProfileSchema>;
1 replies
DTDrizzle Team
Created by Nick on 6/18/2024 in #help
Trying to get Drizzle, Lucia and Vercel-postress to work together (no changes to schema detected)
Hi! I'm new to drizzle and lucia and am just having a problem setting up both with vercel-postgres: I'm creating an adapter for Lucia in my schema.ts: export const createAdapter = (db: PgDatabase<any, any, any>) => new DrizzlePostgreSQLAdapter(db, sessionTable, userTable); and using it in db/index.ts. But this doesn't allow drizzle to see the session or user schemas (no changes are detected when I drizzle-kit push )
import { drizzle } from "drizzle-orm/vercel-postgres";
import { sql } from "@vercel/postgres";
import * as schema from "./schema";

export const db = drizzle(sql, { schema });
export const adapter = schema.createAdapter(db);
import { drizzle } from "drizzle-orm/vercel-postgres";
import { sql } from "@vercel/postgres";
import * as schema from "./schema";

export const db = drizzle(sql, { schema });
export const adapter = schema.createAdapter(db);
Any ideas? Sorry if it's obvious! Nick
7 replies