Custom Types aren't inheriting the schema name but is undefined
I have a working table that is currently being created as
my_schema.user but when I try to add a custom type (bytea) then that particular column is setting the schema value to undefined.
In my ~db/my-schema.ts I have an export.
This is my user.ts file.
Do custom types inherit a custom schema name?3 Replies
The solution was to wipe all migrations and the database and to recreate everything.
Now the
bytea is being created as part of the initial table.
If you don't declare the name of the field in the data-type like this
my_col: text("my_col") and if you share those declarations between tables, it can cause problems. For instance, if I do this: const shared_fields = { x: integer(), y: integer(), z: integer() }; and then const tbl = mySchema.table("tbl", { id: integer(), ...shared_fields });
I say this because I saw you spreading ...timestamps fields.
I stopped sharing same-instances of shared fields for the reason that, when I inspected my own shared_fields thing, I noticed that the object gets modified for each table that you attach it to (to add the name of the field which had been omitted from x, y and z.) and that's not something you really want.
Instead, what I do now is to spread the result of a function that returns the shared fields so, e.g. ...shared.fields() where the fields() function returns a new instance of {x: integer(), y: integer(), z: integer() } every time.
Not sure if that caused your problem, but I believe it's possibleI found that when adding a new
bytea column the migration SQL generated by Drizzle is correct, but altering an existing column's data type to bytea produces this error. Due to this inconsistency, I believe this is a bug on customType in drizzle-kit.