Cayter
Cayter
Explore posts from servers
RRailway
Created by Cayter on 6/20/2024 in #✋|help
Weird start command behaviour
No description
90 replies
RRailway
Created by Cayter on 6/5/2024 in #✋|help
how does one automatically migrate db without pre-deploy actions?
Am using github branch auto deploy and just bumped into this post https://help.railway.app/feedback/pre-and-post-deployment-actions-2c2a4b35. Realised there's no way to run db:migrate command. Why is something fundamental like this not taken care of? Is there a workaround?
15 replies
DTDrizzle Team
Created by Cayter on 5/25/2023 in #help
Migrating from Prisma gradually
We're in the middle of migrating away from Prisma to Drizzle which we just found out that Drizzle has its own naming convention for FOREIGN KEY CONSTRAINT. To avoid surprises for this migration, we'd like to keep Prisma constraint names, I looked into the reference() type definitions, it seems that we don't have a way to customise the FOREIGN KEY CONSTRAINT name, is that correct? At the same time, the current generated constraint name is longer than Postgres's allowed length. How can we workaround this?
15 replies
DTDrizzle Team
Created by Cayter on 5/24/2023 in #help
How to transform to camelCase with json_agg()?
As topic. I can't find any example on how to go about this. The closest I can find is https://orm.drizzle.team/docs/sql#sqlmapwith, but this feels counter-productive as we will have to do it every time we need it. Is there a better way?
1 replies
DTDrizzle Team
Created by Cayter on 5/23/2023 in #help
How to use select?
I have a SQL query
SELECT
row_to_json(departments.*) as department,
row_to_json(job_titles.*) as job_title,
team_member_compensations.*,
team_member_terminations.*
FROM
team_member_compensations
LEFT JOIN departments ON team_member_compensations.department_id = departments.id
LEFT JOIN job_titles ON team_member_compensations.job_title_id = job_titles.id
LEFT JOIN team_member_terminations ON team_member_terminations.team_member_compensation_id = team_member_compensations.id
WHERE ...
SELECT
row_to_json(departments.*) as department,
row_to_json(job_titles.*) as job_title,
team_member_compensations.*,
team_member_terminations.*
FROM
team_member_compensations
LEFT JOIN departments ON team_member_compensations.department_id = departments.id
LEFT JOIN job_titles ON team_member_compensations.job_title_id = job_titles.id
LEFT JOIN team_member_terminations ON team_member_terminations.team_member_compensation_id = team_member_compensations.id
WHERE ...
I am trying to translate the select but couldn't get it to work, any idea what's wrong?
db.select({
department: sql<typeof departments>`row_to_json(${departments}.*)`.as(
"department",
),
jobTitle: sql<typeof jobTitles>`row_to_json(${jobTitles}.*)`.as(
"job_title",
),
teamMemberCompensation: teamMemberCompensations,
teamMemberTermination: teamMemberTerminations,
})
.from(teamMemberCompensations)
.leftJoin(
departments,
eq(departments.id, teamMemberCompensations.departmentId),
)
.leftJoin(jobTitles, eq(jobTitles.id, teamMemberCompensations.jobTitleId))
.leftJoin(
teamMemberTerminations,
eq(
teamMemberTerminations.teamMemberCompensationId,
teamMemberCompensations.id,
),
)
.where(...)
db.select({
department: sql<typeof departments>`row_to_json(${departments}.*)`.as(
"department",
),
jobTitle: sql<typeof jobTitles>`row_to_json(${jobTitles}.*)`.as(
"job_title",
),
teamMemberCompensation: teamMemberCompensations,
teamMemberTermination: teamMemberTerminations,
})
.from(teamMemberCompensations)
.leftJoin(
departments,
eq(departments.id, teamMemberCompensations.departmentId),
)
.leftJoin(jobTitles, eq(jobTitles.id, teamMemberCompensations.jobTitleId))
.leftJoin(
teamMemberTerminations,
eq(
teamMemberTerminations.teamMemberCompensationId,
teamMemberCompensations.id,
),
)
.where(...)
1 replies