Radu Dascalu
Radu Dascalu
Explore posts from servers
DTDrizzle Team
Created by Radu Dascalu on 3/20/2024 in #help
Relations between tables unclear
Consider the following schema where a User can create a Post, and each post can have multiple versions of its content. What is the best way for a Post to store the latestVersionId for quick access. I'm having trouble figuring that out, and also how to create a Post since a Post would need a PostVersion first, but a PostVersion needs a Post to link them together.
export const posts = pgTable("posts", {
id: serial("id").primaryKey(),

authorId: integer("author_id").notNull(),
parentPostId: integer("parent_post_id"),
latestVersionId: integer("latest_version_id") // Is this the best way to store a reference to the latest post_version?
.notNull() // It doesn't make sense for the latestVersionId to be null, so I set it as notNull. But in this case, how can I create a Post or a PostVersion? Either of these need the other during their creation
.references(() => recordVersions.id),
});

export const postsRelations = relations(posts, ({ one, many }) => ({
author: one(users, {
fields: [records.authorId],
references: [users.id],
}),
parentPost: one(posts, {
fields: [posts.parentPostId],
references: [posts.id],
}),
versions: many(postVersions),
}));

export const postVersions = pgTable("post_versions", {
id: serial("id").primaryKey(),

authorId: integer("author_id").notNull(),
postId: integer("postId").notNull(),

content: jsonb("content"),
});

export const postVersionsRelations = relations(postVersions, ({ one }) => ({
author: one(users, {
fields: [postVersions.authorId],
references: [users.id],
}),
post: one(posts, {
fields: [postVersions.postId],
references: [posts.id],
}),
}));
export const posts = pgTable("posts", {
id: serial("id").primaryKey(),

authorId: integer("author_id").notNull(),
parentPostId: integer("parent_post_id"),
latestVersionId: integer("latest_version_id") // Is this the best way to store a reference to the latest post_version?
.notNull() // It doesn't make sense for the latestVersionId to be null, so I set it as notNull. But in this case, how can I create a Post or a PostVersion? Either of these need the other during their creation
.references(() => recordVersions.id),
});

export const postsRelations = relations(posts, ({ one, many }) => ({
author: one(users, {
fields: [records.authorId],
references: [users.id],
}),
parentPost: one(posts, {
fields: [posts.parentPostId],
references: [posts.id],
}),
versions: many(postVersions),
}));

export const postVersions = pgTable("post_versions", {
id: serial("id").primaryKey(),

authorId: integer("author_id").notNull(),
postId: integer("postId").notNull(),

content: jsonb("content"),
});

export const postVersionsRelations = relations(postVersions, ({ one }) => ({
author: one(users, {
fields: [postVersions.authorId],
references: [users.id],
}),
post: one(posts, {
fields: [postVersions.postId],
references: [posts.id],
}),
}));
1 replies
RRailway
Created by Radu Dascalu on 3/19/2024 in #✋|help
Custom build script crashing
No description
32 replies
RRailway
Created by Radu Dascalu on 12/16/2023 in #✋|help
Failing to deploy pnpm monorepo but was successful before
Hi, I'm new to railway so please bear with me. I have a learning side project which I organized in a monorepo (https://github.com/duckradu/kameleon.social). I managed to deploy the 2 apps I have, fastify backend and solid-start frontend, about 8 days ago. Since then I have made lots of changes to my project. The biggest updates were - I noticed that I did not have a pnpm-workspace.yaml so I created one, I updated the minimum engine version required in package.json for both apps to be node >= 20 and lastly, decided to add a new railway service for a Posgres database. Now I am trying to deply the monorepo but both apps fail. Looking through the logs my best guess is that it doesn't use pnpm (anymore?).
42 replies