Skip to content

Commit

Permalink
Change trigger to only update timestamp when not manually changed (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleJune authored Dec 4, 2021
1 parent ce9ab9c commit 0695e7b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ export class PostgresMigrate<GenerateOptions = unknown>
);
`;
await transaction.queryArray`
CREATE FUNCTION trigger_migration_timestamp()
RETURNS TRIGGER AS $$
CREATE FUNCTION trigger_migration_timestamp() RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
IF NEW.updated_at = OLD.updated_at THEN
NEW.updated_at = now();
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
Expand Down

0 comments on commit 0695e7b

Please sign in to comment.