Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryFailedError: function uuid_generate_v4() does not exist #126

Closed
chriskolenko opened this issue Mar 18, 2019 · 11 comments
Closed

QueryFailedError: function uuid_generate_v4() does not exist #126

chriskolenko opened this issue Mar 18, 2019 · 11 comments

Comments

@chriskolenko
Copy link

Apparently most new installations of Postgres don't include the extension uuid-ossp

However typeorm have added in an extra option:
uuidExtension: pgcrypto to allow for this:
typeorm/typeorm#3537

Might have to create another querystring override?

@chriskolenko
Copy link
Author

Oh.. and typeorm needs to be upgraded.

@agustif
Copy link

agustif commented Mar 18, 2019

I've been implementing this in a separated typeorm project, with an external dependency uuid and using @BeforeInsert from typeorm when creating the Entity.

just as an fyi, in case it helps you patch this temporarily, not suggesting not to use postgres add-on.

import { Entity, PrimaryColumn, Column, BeforeInsert, BaseEntity } from 'typeorm';
import { v4 } from 'uuid';
import * as bcrypt from 'bcryptjs';

@Entity('users')
export class User extends BaseEntity {
	@PrimaryColumn('uuid') id: string;

	@Column('varchar', { length: 255 })
	firstName: string;

	@Column('varchar', { length: 255 })
	lastName: string;

	@Column('text') email: string;

	@Column('text') password: string;

	@Column('boolean', { default: false })
	confirmed: boolean;

	@BeforeInsert()
	addId() {
		this.id = v4();
	}
	async hashPassword() {
		this.password = await bcrypt.hash(this.password, 10);
	}
}

@chriskolenko
Copy link
Author

chriskolenko commented Mar 19, 2019

Looks like pgcrypto extension isn't 100%

    {
        "message": "null value in column \"id\" violates not-null constraint",
        "locations": [{
            "line": 2,
            "column": 3
        }],
        "path": ["onboard"],
        "extensions": {
            "code": "INTERNAL_SERVER_ERROR",
            "exception": {
                "message": "null value in column \"id\" violates not-null constraint",
                "name": "QueryFailedError",
                "length": 204,
                "severity": "ERROR",
                "code": "23502",
                "detail": "Failing row contains (null, viper@..., f, null).",
                "schema": "public",
                "table": "user_email",
                "column": "id",
                "file": "execMain.c",
                "line": "2017",
                "routine": "ExecConstraints",
                "query": "INSERT INTO \"user_email\"(\"id\", \"address\", \"verified\", \"userId\") VALUES (DEFAULT, $1, $2, DEFAULT) RETURNING \"id\", \"verified\"",
                "parameters": ["viper@....", 0]
            }
        }
    }

EDIT:
Ignore above.. I created the DB schema with an older version of the application. I was doing some bad things which got me into that state.

Everything is working good with pgcrypto.

@birkir
Copy link
Owner

birkir commented Mar 19, 2019

Both circleci and heroku install this by default. I would say it's almost mandatory to have uuid support in postgres today. TypeORM will attempt to enable the extension on start.

Are you guys running on windows maybe? I am all for fixing platform issues.

@birkir birkir closed this as completed Mar 20, 2019
@chriskolenko
Copy link
Author

I'm using the stable helm chart and install postgres on kubernetes.

The maintainers have refused to install this deprecated plugin. Which has forced TypeORM to implement a fix. Which was merged a few weeks back.

@chriskolenko
Copy link
Author

Would you except a PR to fix?

@birkir
Copy link
Owner

birkir commented Mar 21, 2019

Absolutely! Is it a matter of just upgrading typeorm?

@chriskolenko
Copy link
Author

Upgrading typeorm and also passing on the extra settings from the ENV db connection string. Can give this a crack in a couple days time.

@chroline
Copy link

Sorry, newbie to primeCMS here. I'm getting this error and not exactly sure on the steps to fix it. Any thoughts? Thanks

@tolumide-ng
Copy link

Sorry, newbie to primeCMS here. I'm getting this error and not exactly sure on the steps to fix it. Any thoughts? Thanks

You need to create the extension uuid_ossp on the database you're using:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

@tupizz
Copy link

tupizz commented Jun 30, 2020

@tolumide-ng why i have to run this command? Pg dont have natively this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants