stephen
stephen
Explore posts from servers
DTDrizzle Team
Created by stephen on 4/15/2024 in #help
Query `with` returning no results?
(the reason the IDs don't match is that I create a fresh database for every test.
5 replies
DTDrizzle Team
Created by stephen on 4/15/2024 in #help
Query `with` returning no results?
When I console log the foundRecipes, however, I see:
{
foundRecipes: [
{
id: 'xlo9mpndtshrghoj21fxrp2p',
title: 'Pumpkin Pie',
description: 'A delicious pumpkin pie recipe',
author: null,
recipeTags: []
}
]
}
{
foundRecipes: [
{
id: 'xlo9mpndtshrghoj21fxrp2p',
title: 'Pumpkin Pie',
description: 'A delicious pumpkin pie recipe',
author: null,
recipeTags: []
}
]
}
5 replies
DTDrizzle Team
Created by stephen on 4/15/2024 in #help
Query `with` returning no results?
Here's me proving that the tag is associated.
sqlite> select * from recipes where title = 'Pumpkin Pie';
vswb2i9sbtcweiaj1gjmnqob||A delicious pumpkin pie recipe|0|["Preheat oven to 425 F.","Whisk pumpkin, sweetened condensed milk, eggs, spices and salt in medium bowl until smooth.","Pour into crust. Bake 15 minutes.","Reduce oven temperature to 350 F and continue baking 35 to 40 minutes or until knife inserted 1 inch from crust comes out clean.","Cool. Garnish as desired. Store leftovers covered in refrigerator."]||||NYTimes Cooking|https://cooking.nytimes.com/recipes/1015622-pumpkin-pie|bmktsg6ssujrt0yvhy6x8ha9|Pumpkin Pie||2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00

sqlite> select * from recipe_tags where recipe_id = 'vswb2i9sbtcweiaj1gjmnqob';
vswb2i9sbtcweiaj1gjmnqob|g1b9ahshzfsbs1kgtxq9u1ib|2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00
vswb2i9sbtcweiaj1gjmnqob|huysxg747uz46cisjk6ujboi|2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00
vswb2i9sbtcweiaj1gjmnqob|opyfmuutya73gbcfd8wjmcfw|2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00
vswb2i9sbtcweiaj1gjmnqob|qrg0o1r1i558tcbvo9q7eisd|2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00
vswb2i9sbtcweiaj1gjmnqob|vfhq9iw3gi09464otnzymvr9|2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00

sqlite> select * from tags where id = 'g1b9ahshzfsbs1kgtxq9u1ib';
g1b9ahshzfsbs1kgtxq9u1ib|thanksgiving|0||2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00
sqlite> select * from recipes where title = 'Pumpkin Pie';
vswb2i9sbtcweiaj1gjmnqob||A delicious pumpkin pie recipe|0|["Preheat oven to 425 F.","Whisk pumpkin, sweetened condensed milk, eggs, spices and salt in medium bowl until smooth.","Pour into crust. Bake 15 minutes.","Reduce oven temperature to 350 F and continue baking 35 to 40 minutes or until knife inserted 1 inch from crust comes out clean.","Cool. Garnish as desired. Store leftovers covered in refrigerator."]||||NYTimes Cooking|https://cooking.nytimes.com/recipes/1015622-pumpkin-pie|bmktsg6ssujrt0yvhy6x8ha9|Pumpkin Pie||2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00

sqlite> select * from recipe_tags where recipe_id = 'vswb2i9sbtcweiaj1gjmnqob';
vswb2i9sbtcweiaj1gjmnqob|g1b9ahshzfsbs1kgtxq9u1ib|2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00
vswb2i9sbtcweiaj1gjmnqob|huysxg747uz46cisjk6ujboi|2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00
vswb2i9sbtcweiaj1gjmnqob|opyfmuutya73gbcfd8wjmcfw|2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00
vswb2i9sbtcweiaj1gjmnqob|qrg0o1r1i558tcbvo9q7eisd|2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00
vswb2i9sbtcweiaj1gjmnqob|vfhq9iw3gi09464otnzymvr9|2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00

sqlite> select * from tags where id = 'g1b9ahshzfsbs1kgtxq9u1ib';
g1b9ahshzfsbs1kgtxq9u1ib|thanksgiving|0||2024-04-14T16:26:27-05:00|2024-04-14T16:26:27-05:00
5 replies
DTDrizzle Team
Created by hacktographer on 8/25/2023 in #help
How are you all seeding your database?
For some reason if your use esbuild-register and had an error, you can try use tsx instead:
😂
11 replies
DTDrizzle Team
Created by stephen on 3/21/2024 in #help
Schema is "wrong" resulting in "foreign key mismatch" error
My questions: 1. Should drizzle error if I don't have the correct relations? 2. If I find that I have a missing relation, what's the proper order of operations for that to get picked up by the schema generation to create a migration? 3. Is there a way to "force" this change to occur?
4 replies
DTDrizzle Team
Created by stephen on 3/21/2024 in #help
Schema is "wrong" resulting in "foreign key mismatch" error
sqlite> .schema menu_recipes
CREATE TABLE `menu_recipes` (
`menu_id` text NOT NULL,
`recipe_id` text NOT NULL,
`added_by` text,
`created_date` text,
`updated_date` text,
`menu_course_id` text,
PRIMARY KEY(`menu_id`, `recipe_id`),
FOREIGN KEY (`menu_id`) REFERENCES `menus`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`recipe_id`) REFERENCES `recipes`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`added_by`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`menu_course_id`) REFERENCES `menu_courses`(`id`) ON UPDATE cascade ON DELETE no action
);
sqlite> .schema menu_course_recipes
CREATE TABLE `menu_course_recipes` (
`menu_course_id` text NOT NULL,
`recipe_id` text NOT NULL,
PRIMARY KEY(`menu_course_id`, `recipe_id`),
FOREIGN KEY (`menu_course_id`) REFERENCES `menu_courses`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`recipe_id`) REFERENCES `menu_recipes`(`id`) ON UPDATE no action ON DELETE cascade
);
sqlite> .schema menu_recipes
CREATE TABLE `menu_recipes` (
`menu_id` text NOT NULL,
`recipe_id` text NOT NULL,
`added_by` text,
`created_date` text,
`updated_date` text,
`menu_course_id` text,
PRIMARY KEY(`menu_id`, `recipe_id`),
FOREIGN KEY (`menu_id`) REFERENCES `menus`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`recipe_id`) REFERENCES `recipes`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`added_by`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`menu_course_id`) REFERENCES `menu_courses`(`id`) ON UPDATE cascade ON DELETE no action
);
sqlite> .schema menu_course_recipes
CREATE TABLE `menu_course_recipes` (
`menu_course_id` text NOT NULL,
`recipe_id` text NOT NULL,
PRIMARY KEY(`menu_course_id`, `recipe_id`),
FOREIGN KEY (`menu_course_id`) REFERENCES `menu_courses`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`recipe_id`) REFERENCES `menu_recipes`(`id`) ON UPDATE no action ON DELETE cascade
);
4 replies
DTDrizzle Team
Created by stephen on 3/21/2024 in #help
Schema is "wrong" resulting in "foreign key mismatch" error
I found this SO thread (https://stackoverflow.com/questions/6848608/sqlite-foreign-key-mismatch-error), and tried adding this to my menuRecipesRelations:
export const menuRecipesRelations = relations(menuRecipes, ({ one }) => ({
+ menuCourseRecipes: one(menuCourseRecipes, { fields: [menuRecipes.menuCourseId, menuRecipes.recipeId], references: [menuCourseRecipes.menuCourseId, menuCourseRecipes.menuRecipeId] }),
}));
export const menuRecipesRelations = relations(menuRecipes, ({ one }) => ({
+ menuCourseRecipes: one(menuCourseRecipes, { fields: [menuRecipes.menuCourseId, menuRecipes.recipeId], references: [menuCourseRecipes.menuCourseId, menuCourseRecipes.menuRecipeId] }),
}));
Getting this to be picked up when I run db:gen, however, is challenging.
"scripts": {
"db:gen": "drizzle-kit generate:sqlite",
"db:migrate": "drizzle-kit generate:sqlite --out ./drizzle --schema ./app/db/schema.ts",
"db:studio": "drizzle-kit studio --verbose --port 5555",
"db:seed": "tsx ./app/db/seed.ts",
}
"scripts": {
"db:gen": "drizzle-kit generate:sqlite",
"db:migrate": "drizzle-kit generate:sqlite --out ./drizzle --schema ./app/db/schema.ts",
"db:studio": "drizzle-kit studio --verbose --port 5555",
"db:seed": "tsx ./app/db/seed.ts",
}
4 replies
DTDrizzle Team
Created by hacktographer on 8/25/2023 in #help
How are you all seeding your database?
Okay, so I was able to solve this by using tsx instead of ts-node. Not sure why.
11 replies
DTDrizzle Team
Created by hacktographer on 8/25/2023 in #help
How are you all seeding your database?
I found this follow up video (https://www.youtube.com/watch?v=n9rtLhMN3cc). I have a very similar approach, but am struggling with actually getting the script to run and i"m curious if others have solved this.
$ ts-node ./app/db/seed.ts
TypeError: Unknown file extension ".ts" for /Users/stephenweiss/code/plated/app/db/seed.ts
$ ts-node ./app/db/seed.ts
TypeError: Unknown file extension ".ts" for /Users/stephenweiss/code/plated/app/db/seed.ts
11 replies
DTDrizzle Team
Created by stephen on 3/15/2024 in #help
Studio: Not Enough Info to Infer Relation
(I was looking at the wrong table's relations ... 😬 )
11 replies
DTDrizzle Team
Created by stephen on 3/15/2024 in #help
Studio: Not Enough Info to Infer Relation
yup! i got it! 😅
11 replies
DTDrizzle Team
Created by stephen on 3/15/2024 in #help
Studio: Not Enough Info to Infer Relation
i think i see it 🤦‍♀️
11 replies
DTDrizzle Team
Created by stephen on 3/15/2024 in #help
Studio: Not Enough Info to Infer Relation
jk
11 replies
DTDrizzle Team
Created by stephen on 3/15/2024 in #help
Studio: Not Enough Info to Infer Relation
/Users/stephenweiss/code/plated/node_modules/drizzle-orm/relations.cjs:261
throw new Error(
^

Error: There is not enough information to infer relation "__public__.menuRecipes.menu"
at normalizeRelation (/Users/stephenweiss/code/plated/node_modules/drizzle-orm/relations.cjs:261:9)
at /Users/stephenweiss/code/plated/node_modules/@drizzle-team/studio/index.js:73:67
at Array.map (<anonymous>)
at /Users/stephenweiss/code/plated/node_modules/@drizzle-team/studio/index.js:72:42
at Array.map (<anonymous>)
at extractRelations (/Users/stephenweiss/code/plated/node_modules/@drizzle-team/studio/index.js:71:51)
at sqliteQueryEngine (/Users/stephenweiss/code/plated/node_modules/@drizzle-team/studio/index.js:293:16)
at queryEngineForSetup (/Users/stephenweiss/code/plated/node_modules/@drizzle-team/studio/index.js:716:12)
at Command.<anonymous> (/Users/stephenweiss/code/plated/node_modules/drizzle-kit/bin.cjs:63755:62)

Node.js v20.11.1
error: script "db:studio" exited with code 1
/Users/stephenweiss/code/plated/node_modules/drizzle-orm/relations.cjs:261
throw new Error(
^

Error: There is not enough information to infer relation "__public__.menuRecipes.menu"
at normalizeRelation (/Users/stephenweiss/code/plated/node_modules/drizzle-orm/relations.cjs:261:9)
at /Users/stephenweiss/code/plated/node_modules/@drizzle-team/studio/index.js:73:67
at Array.map (<anonymous>)
at /Users/stephenweiss/code/plated/node_modules/@drizzle-team/studio/index.js:72:42
at Array.map (<anonymous>)
at extractRelations (/Users/stephenweiss/code/plated/node_modules/@drizzle-team/studio/index.js:71:51)
at sqliteQueryEngine (/Users/stephenweiss/code/plated/node_modules/@drizzle-team/studio/index.js:293:16)
at queryEngineForSetup (/Users/stephenweiss/code/plated/node_modules/@drizzle-team/studio/index.js:716:12)
at Command.<anonymous> (/Users/stephenweiss/code/plated/node_modules/drizzle-kit/bin.cjs:63755:62)

Node.js v20.11.1
error: script "db:studio" exited with code 1
11 replies
DTDrizzle Team
Created by stephen on 3/15/2024 in #help
Studio: Not Enough Info to Infer Relation
export const menuCourses = sqliteTable('menu_courses', {
id: text('id').$default(() => createId()).primaryKey(),
menuId: text('menu_id').references(() => menus.id, { onDelete: "cascade" }).notNull(),
name: text('name'),
});

export const menuCoursesRelations = relations(menuCourses, ({ one, many }) => ({
menu: one(menus, { fields: [menuCourses.menuId], references: [menus.id] }),
menuCourseRecipes: many(menuRecipes),
}));

export const menuRecipes = sqliteTable('menu_recipes', {
id: text('id').$default(() => createId()).primaryKey(),
menuId: text('menu_id').references(() => menus.id, { onDelete: "cascade" }).notNull(),
// recipeId: text('recipe_id').references(() => recipes.id, { onDelete: "cascade" }).notNull(),
menuCourseId: text('menu_course_id').references(() => menuCourses.id, { onUpdate: "cascade" }),
});

export const menuRecipesRelations = relations(menuRecipes, ({ one }) => ({
menuCourse: one(menuCourses),
}));

export const menuCourseRecipes = sqliteTable('menu_course_recipes', {
menuCourseId: text('menu_course_id').references(() => menuCourses.id, { onDelete: "cascade" }).notNull(),
menuRecipeId: text('recipe_id').references(() => menuRecipes.id, { onDelete: "cascade" }).notNull(),
}, (t) => ({
pk: primaryKey({ columns: [t.menuCourseId, t.menuRecipeId] }),
}));

export const menuCourseRecipesRelations = relations(menuCourseRecipes, ({ one }) => ({
menuCourses: one(menuCourses, {
fields: [menuCourseRecipes.menuCourseId],
references: [menuCourses.id],
}),
menuRecipes: one(menuRecipes, {
fields: [menuCourseRecipes.menuRecipeId],
references: [menuRecipes.id],
}),
}));
export const menuCourses = sqliteTable('menu_courses', {
id: text('id').$default(() => createId()).primaryKey(),
menuId: text('menu_id').references(() => menus.id, { onDelete: "cascade" }).notNull(),
name: text('name'),
});

export const menuCoursesRelations = relations(menuCourses, ({ one, many }) => ({
menu: one(menus, { fields: [menuCourses.menuId], references: [menus.id] }),
menuCourseRecipes: many(menuRecipes),
}));

export const menuRecipes = sqliteTable('menu_recipes', {
id: text('id').$default(() => createId()).primaryKey(),
menuId: text('menu_id').references(() => menus.id, { onDelete: "cascade" }).notNull(),
// recipeId: text('recipe_id').references(() => recipes.id, { onDelete: "cascade" }).notNull(),
menuCourseId: text('menu_course_id').references(() => menuCourses.id, { onUpdate: "cascade" }),
});

export const menuRecipesRelations = relations(menuRecipes, ({ one }) => ({
menuCourse: one(menuCourses),
}));

export const menuCourseRecipes = sqliteTable('menu_course_recipes', {
menuCourseId: text('menu_course_id').references(() => menuCourses.id, { onDelete: "cascade" }).notNull(),
menuRecipeId: text('recipe_id').references(() => menuRecipes.id, { onDelete: "cascade" }).notNull(),
}, (t) => ({
pk: primaryKey({ columns: [t.menuCourseId, t.menuRecipeId] }),
}));

export const menuCourseRecipesRelations = relations(menuCourseRecipes, ({ one }) => ({
menuCourses: one(menuCourses, {
fields: [menuCourseRecipes.menuCourseId],
references: [menuCourses.id],
}),
menuRecipes: one(menuRecipes, {
fields: [menuCourseRecipes.menuRecipeId],
references: [menuRecipes.id],
}),
}));
11 replies
DTDrizzle Team
Created by stephen on 3/15/2024 in #help
Studio: Not Enough Info to Infer Relation
Thanks! Now I'm trying to follow the pattern for a many-to-many and am getting stuck.
11 replies
DTDrizzle Team
Created by stephen on 3/15/2024 in #help
Studio: Not Enough Info to Infer Relation
thanks @solo ! i think i've got dozens of these relations configured incorrectly it seems... can you point me to the docs where i might learn more about this second argument?
11 replies
DTDrizzle Team
Created by stephen on 3/13/2024 in #help
Creating migrations with Enums present (postgres)
that's such an easy fix! ha!
3 replies