Closed chriskolenko closed 5 years ago
Oh.. and typeorm needs to be upgraded.
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);
}
}
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.
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.
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.
Would you except a PR to fix?
Absolutely! Is it a matter of just upgrading typeorm?
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.
Sorry, newbie to primeCMS here. I'm getting this error and not exactly sure on the steps to fix it. Any thoughts? Thanks
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";
@tolumide-ng why i have to run this command? Pg dont have natively this?
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: https://github.com/typeorm/typeorm/pull/3537
Might have to create another querystring override? https://github.com/birkir/prime/blob/7b0f33c6002cab328fef538acbd553a684fb6b8e/packages/prime-core/src/utils/connect.ts#L13