Xafets
Xafets
DTDrizzle Team
Created by Xafets on 10/9/2023 in #help
`db:push` with `customType` causes data loss
Running db:push consecutively without changing the schema causes alterations and truncation, only for customType columns: You're about to change dollars column type from numeric(16, 2) to numeric(16,2) with 50 items
6 replies
DTDrizzle Team
Created by Xafets on 8/1/2023 in #help
Unchanged schema, `db:push:pg` generates faulty `ALTER` statements
Schema:
CREATE TABLE IF NOT EXISTS "private"."users" (
"created_at" timestamp NOT NULL,
"updated_at" timestamp NOT NULL,
...
}
CREATE TABLE IF NOT EXISTS "private"."users" (
"created_at" timestamp NOT NULL,
"updated_at" timestamp NOT NULL,
...
}
Running db:push:pg successively, with no changes to schema:
truncate table "private"."users" cascade;
ALTER TABLE "private"."users" ALTER COLUMN "created_at" SET NOT NULL;
truncate table "private"."users" cascade;
ALTER TABLE "private"."users" ALTER COLUMN "updated_at" SET NOT NULL;
truncate table "private"."users" cascade;
ALTER TABLE "private"."users" ALTER COLUMN "created_at" SET NOT NULL;
truncate table "private"."users" cascade;
ALTER TABLE "private"."users" ALTER COLUMN "updated_at" SET NOT NULL;
1 replies
DTDrizzle Team
Created by Xafets on 8/1/2023 in #help
Get `id` of inserted row
Is this the right way to get the id of an insert? It feels incredibly cumbersome for such a common pattern, so feel like I'm doing something wrong:
const { resultId } = (await Database.insert(UsersTable).values(userInsert).returning({resultId: UsersTable.id}))[0]
const { resultId } = (await Database.insert(UsersTable).values(userInsert).returning({resultId: UsersTable.id}))[0]
23 replies
DTDrizzle Team
Created by Xafets on 8/1/2023 in #help
Column primary key not working
What am I doing wrong when defining my primary key here? column:
const customPrimaryKey = customType<{
data: number;
notNull: true;
default: true;
}>({
dataType() {
return `id bigint generated always as identity primary key`;
},
});
const customPrimaryKey = customType<{
data: number;
notNull: true;
default: true;
}>({
dataType() {
return `id bigint generated always as identity primary key`;
},
});
Generated SQL:
CREATE TABLE IF NOT EXISTS "users" (
"id" "bigint generated always as identity primary key",
CREATE TABLE IF NOT EXISTS "users" (
"id" "bigint generated always as identity primary key",
Error:
error: type "bigint generated always as identity primary key" does not exist
error: type "bigint generated always as identity primary key" does not exist
2 replies