Closed joshuaja closed 2 months ago
In the postgres adaptor I've seen code like this:
packages/drizzle/src/postgres/schema/traverseFields.ts line 661
const baseExtraConfig: BaseExtraConfig = {
orderIdx: (cols) => index(`${selectTableName}_order_idx`).on(cols.order),
parentFk: (cols) =>
foreignKey({
name: `${selectTableName}_parent_fk`,
columns: [cols.parent],
foreignColumns: [adapter.tables[parentTableName].id],
}).onDelete('cascade'),
parentIdx: (cols) => index(`${selectTableName}_parent_idx`).on(cols.parent),
}
So I wonder in the case of arrays is what you're seeing just an empty string in that case, hence the leading _
.
So I wonder in the case of arrays is what you're seeing just an empty string in that case, hence the leading
_
.
Good find! I was thinking the same thing - it smells of string concatenation.
@BlainMaguire - looks like a little above that in the file is where the array column names are specified:
const baseColumns: Record<string, PgColumnBuilder> = {
_order: integer('_order').notNull(),
_parentID: parentIDColumnMap[parentIDColType]('_parent_id').notNull(),
}
We used _
anytime there was a chance that the table could have a conflicting column name due to field names from the config being mixed with payload internal column names. This is by design. Suppose in your tenants array you also had a field with name: 'order'
.
Does that answer the question?
It would be trivial for us to add to the db adapter configuration additional properties for orderColumnName
, parentColumnName
, etc. But I don't think it would add a whole lot of value and makes our code slightly more complex for little gain.
I'm interested in your feedback. I'm changing this to a discussion since I don't see any issue here.
Link to reproduction
https://github.com/DapperMountain/payload-3-bun-template
Environment Info
Describe the Bug
_rels
tables and tables created from arrays have different column naming syntax for some reason.Additionally (nit): The
id
field in the array table (users_tenants
) should be positioned as the first column in the table and uses a different UUID format than the otherid
fields.Example
users_rels
tableorder
andparent_id
users_tenants
table_order
and_parent_id
Reproduction Steps
Set up a users collection like this. It should create the tables for us to reproduce the issue.
Adapters and Plugins
db-postgres