quasar_here
quasar_here
DTDrizzle Team
Created by Jaxwn on 8/20/2023 in #help
Is there something wrong with my schema?
Actually I'm a guy who took the OP post to solve my issue because I didn't want to create another post
23 replies
DTDrizzle Team
Created by Jaxwn on 8/20/2023 in #help
Is there something wrong with my schema?
@angelelz I appreciate your help very much and congratulations for becoming a Drizzle Advocate I got a error when trying to run this migration and according to ChatGPT (I'm not proficient in databases myself), Postgres doesn't support update on current_timestamp that's why it recommended to use triggers instead
23 replies
DTDrizzle Team
Created by Jaxwn on 8/20/2023 in #help
Is there something wrong with my schema?
Btw if this could be done in typescript as a function or something I think it will be better
23 replies
DTDrizzle Team
Created by Jaxwn on 8/20/2023 in #help
Is there something wrong with my schema?
Sure, I appreciate it:
CREATE TABLE IF NOT EXISTS "users" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"name" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
);
CREATE TABLE IF NOT EXISTS "users" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"name" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
);
Right now I created a trigger:
CREATE OR REPLACE FUNCTION update_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION update_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
And I'm calling after the users table creation with:
CREATE TRIGGER users_update_trigger
BEFORE UPDATE ON users
FOR EACH ROW
EXECUTE FUNCTION update_updated_at();
CREATE TRIGGER users_update_trigger
BEFORE UPDATE ON users
FOR EACH ROW
EXECUTE FUNCTION update_updated_at();
Can it get better?
23 replies
DTDrizzle Team
Created by Jaxwn on 8/20/2023 in #help
Is there something wrong with my schema?
It did not worked, i'm struggling for hours for such a simple feature lmao
Running migrations...
error: syntax error at or near "on"
Running migrations...
error: syntax error at or near "on"
23 replies
DTDrizzle Team
Created by Jaxwn on 8/20/2023 in #help
Is there something wrong with my schema?
I'm using postgres so I have an error: Property onUpdateNow does not exist on type PgTimestampBuilder
23 replies