jsingleton37
jsingleton37
DTDrizzle Team
Created by jsingleton37 on 12/16/2024 in #help
Running into some type errors with query.where
And that schema for transferPortalEntries looks like
export const transferPortalEntries = pgTable(
'transfer_portal_entries',
{
id: serial('id').primaryKey(),
playerId: integer('player_id')
.references(() => players.id)
.notNull(),
entryDate: date('entry_date').notNull(),
transferStatus: transferStatusEnum('transfer_status').notNull().default('Entered'),
isGradTransfer: boolean('is_grad_transfer').notNull().default(false),
previousSchoolId: integer('previous_school_id')
.references(() => schoolReferences.id)
.notNull(),
commitmentSchoolId: integer('commitment_school_id').references(() => schoolReferences.id),
commitmentDate: date('commitment_date'),
createdAt: timestamp('created_at').notNull().defaultNow(),
updatedAt: timestamp('updated_at').notNull().defaultNow(),
lastStatusChangeAt: timestamp('last_status_change_at').notNull().defaultNow(),
},
(table) => [
uniqueIndex('unique_player_entry').on(table.playerId, table.entryDate),
uniqueIndex('transfer_portal_entries_date_idx').on(table.entryDate),
],
)
export const transferPortalEntries = pgTable(
'transfer_portal_entries',
{
id: serial('id').primaryKey(),
playerId: integer('player_id')
.references(() => players.id)
.notNull(),
entryDate: date('entry_date').notNull(),
transferStatus: transferStatusEnum('transfer_status').notNull().default('Entered'),
isGradTransfer: boolean('is_grad_transfer').notNull().default(false),
previousSchoolId: integer('previous_school_id')
.references(() => schoolReferences.id)
.notNull(),
commitmentSchoolId: integer('commitment_school_id').references(() => schoolReferences.id),
commitmentDate: date('commitment_date'),
createdAt: timestamp('created_at').notNull().defaultNow(),
updatedAt: timestamp('updated_at').notNull().defaultNow(),
lastStatusChangeAt: timestamp('last_status_change_at').notNull().defaultNow(),
},
(table) => [
uniqueIndex('unique_player_entry').on(table.playerId, table.entryDate),
uniqueIndex('transfer_portal_entries_date_idx').on(table.entryDate),
],
)
So there is an entryDate
13 replies
DTDrizzle Team
Created by jsingleton37 on 12/16/2024 in #help
Running into some type errors with query.where
So I think it's something with
sql`EXTRACT(YEAR FROM ${transferPortalEntries.entryDate}) = ${filters.year}`
sql`EXTRACT(YEAR FROM ${transferPortalEntries.entryDate}) = ${filters.year}`
Added a different filter and that works just fine
13 replies
DTDrizzle Team
Created by jsingleton37 on 12/16/2024 in #help
Running into some type errors with query.where
Yea I have done drizzle-kit push for my schemas or else the original query minus the .where() wouldn't return anything. It returns data if I remove the .where()
13 replies
DTDrizzle Team
Created by jsingleton37 on 12/16/2024 in #help
Running into some type errors with query.where
I also have an issue where status: 'All' won't return becuase of
invalid input value for enum transfer_status: "All"
invalid input value for enum transfer_status: "All"
So need to figure that out as well
13 replies
DTDrizzle Team
Created by jsingleton37 on 12/16/2024 in #help
Running into some type errors with query.where
And nothing returns, if I remove the .where() it returns data. The current filters are { filters: { year: 2025, status: 'All' } } being passed in.
13 replies
DTDrizzle Team
Created by jsingleton37 on 12/16/2024 in #help
Running into some type errors with query.where
Odd, I did
const filtersArray: (SQL | undefined)[] = []
if (filters.year) {
filtersArray.push(sql`EXTRACT(YEAR FROM ${transferPortalEntries.entryDate}) = ${filters.year}`)
}
let query = db
.select({
id: transferPortalEntries.id,
entryDate: transferPortalEntries.entryDate,
transferStatus: transferPortalEntries.transferStatus,
isGradTransfer: transferPortalEntries.isGradTransfer,
createdAt: transferPortalEntries.createdAt,
updatedAt: transferPortalEntries.updatedAt,
lastStatusChangeAt: transferPortalEntries.lastStatusChangeAt,
firstName: players.firstName,
lastName: players.lastName,
height: players.height,
weight: players.weight,
highSchool: players.highSchool,
hometown: players.hometown,
state: players.state,
playerImageUrl: players.playerImageUrl,
instagramHandle: players.instagramHandle,
twitterHandle: players.twitterHandle,
position: positions.name,
positionAbbreviation: positions.abbreviation,
classYear: classYears.name,
classYearAbbreviation: classYears.abbreviation,
previousSchoolName: previousSchool.name,
previousSchoolSanityId: previousSchool.sanityId,
commitmentSchoolName: commitmentSchool.name,
commitmentSchoolSanityId: commitmentSchool.sanityId,
commitmentDate: transferPortalEntries.commitmentDate,
})
.from(transferPortalEntries)
.innerJoin(players, eq(transferPortalEntries.playerId, players.id))
.innerJoin(positions, eq(players.positionId, positions.id))
.innerJoin(classYears, eq(players.classYearId, classYears.id))
.innerJoin(previousSchool, eq(transferPortalEntries.previousSchoolId, previousSchool.id))
.leftJoin(commitmentSchool, eq(transferPortalEntries.commitmentSchoolId, commitmentSchool.id))
.where(and(...filtersArray))
const filtersArray: (SQL | undefined)[] = []
if (filters.year) {
filtersArray.push(sql`EXTRACT(YEAR FROM ${transferPortalEntries.entryDate}) = ${filters.year}`)
}
let query = db
.select({
id: transferPortalEntries.id,
entryDate: transferPortalEntries.entryDate,
transferStatus: transferPortalEntries.transferStatus,
isGradTransfer: transferPortalEntries.isGradTransfer,
createdAt: transferPortalEntries.createdAt,
updatedAt: transferPortalEntries.updatedAt,
lastStatusChangeAt: transferPortalEntries.lastStatusChangeAt,
firstName: players.firstName,
lastName: players.lastName,
height: players.height,
weight: players.weight,
highSchool: players.highSchool,
hometown: players.hometown,
state: players.state,
playerImageUrl: players.playerImageUrl,
instagramHandle: players.instagramHandle,
twitterHandle: players.twitterHandle,
position: positions.name,
positionAbbreviation: positions.abbreviation,
classYear: classYears.name,
classYearAbbreviation: classYears.abbreviation,
previousSchoolName: previousSchool.name,
previousSchoolSanityId: previousSchool.sanityId,
commitmentSchoolName: commitmentSchool.name,
commitmentSchoolSanityId: commitmentSchool.sanityId,
commitmentDate: transferPortalEntries.commitmentDate,
})
.from(transferPortalEntries)
.innerJoin(players, eq(transferPortalEntries.playerId, players.id))
.innerJoin(positions, eq(players.positionId, positions.id))
.innerJoin(classYears, eq(players.classYearId, classYears.id))
.innerJoin(previousSchool, eq(transferPortalEntries.previousSchoolId, previousSchool.id))
.leftJoin(commitmentSchool, eq(transferPortalEntries.commitmentSchoolId, commitmentSchool.id))
.where(and(...filtersArray))
13 replies
DTDrizzle Team
Created by jsingleton37 on 12/16/2024 in #help
Running into some type errors with query.where
Is that before building the original query?
13 replies
DTDrizzle Team
Created by jsingleton37 on 12/12/2024 in #help
I messed up my supabase and drizzle setup
Was just curious if there was a way I could delete some migrations for the latest tables along with the .sql
19 replies
DTDrizzle Team
Created by jsingleton37 on 12/12/2024 in #help
I messed up my supabase and drizzle setup
Ah ok, yea I have some of my tables that I need to keep because it's being used in production
19 replies
DTDrizzle Team
Created by jsingleton37 on 12/12/2024 in #help
I messed up my supabase and drizzle setup
🤔 that would also delete those in use though?
19 replies
DTDrizzle Team
Created by jsingleton37 on 12/12/2024 in #help
I messed up my supabase and drizzle setup
What if I just want to start from scratch
19 replies
DTDrizzle Team
Created by jsingleton37 on 12/12/2024 in #help
I messed up my supabase and drizzle setup
How exactly do I do that without messing up the ones that I do use?
19 replies
DTDrizzle Team
Created by jsingleton37 on 12/12/2024 in #help
I messed up my supabase and drizzle setup
None of the new tables added in that branch are being used in production by I honestly don’t know the best way to clean everything up
19 replies
DTDrizzle Team
Created by jsingleton37 on 12/12/2024 in #help
I messed up my supabase and drizzle setup
I also can’t run the generate command at the moment but I was told that due to something I did that I don’t fully recall doing 😅
19 replies
DTDrizzle Team
Created by jsingleton37 on 12/12/2024 in #help
I messed up my supabase and drizzle setup
19 replies
DTDrizzle Team
Created by jsingleton37 on 12/12/2024 in #help
I messed up my supabase and drizzle setup
19 replies
DTDrizzle Team
Created by jsingleton37 on 12/12/2024 in #help
Column of relation already exists
I just upgraded from 0.36.4 to 0.38.1 of drizzle-orm and 0.28.1 to 0.30.0 of drizzle-kit and now I can't even do drizzle-kit generate 😭 I get
Error: [supabase/migrations/meta/0017_snapshot.json, supabase/migrations/meta/0018_snapshot.json] are pointing to a parent snapshot: supabase/migrations/meta/0017_snapshot.json/snapshot.json which is a collision.
Error: [supabase/migrations/meta/0017_snapshot.json, supabase/migrations/meta/0018_snapshot.json] are pointing to a parent snapshot: supabase/migrations/meta/0017_snapshot.json/snapshot.json which is a collision.
3 replies
DTDrizzle Team
Created by jsingleton37 on 9/2/2024 in #help
What is the best way to get distinct values from a table?
Oh nice! So I can just do
export async function getYearsThatHaveVotes({ division }: { division: string }) {
const distinctYearsWithVotes = await db
.selectDistinct({
year: weeklyFinalRankings.year,
})
.from(weeklyFinalRankings)

return distinctYearsWithVotes
}
export async function getYearsThatHaveVotes({ division }: { division: string }) {
const distinctYearsWithVotes = await db
.selectDistinct({
year: weeklyFinalRankings.year,
})
.from(weeklyFinalRankings)

return distinctYearsWithVotes
}
3 replies
DTDrizzle Team
Created by jsingleton37 on 6/10/2024 in #help
onConflictDoNothing still incrementing primaryKey
AFAIK this is the default behavior
9 replies
DTDrizzle Team
Created by jsingleton37 on 7/27/2024 in #help
Confused about onConflictDoUpdate when having a constraint
Ah sweet! That fixes it! Also makes me realize I need to update the unique to be on division, week, and year 😅
4 replies