express-typescript-boilerplate
express-typescript-boilerplate copied to clipboard
[bug] JSONB seeding not working
Hi! I created the following model:
@Entity()
export class Resource {
@PrimaryColumn('uuid')
public id: string;
@IsNotEmpty()
@Column()
public source: string;
@IsNotEmpty()
@Column({ type: 'jsonb', nullable: true })
public data: any;
@UpdateDateColumn({ name: 'updated_at' })
public updatedAt: Date;
@CreateDateColumn({ name: 'created_at' })
public createdAt: Date;
}
And this is my Factory:
define(Resource, (faker: typeof Faker) => {
const source = faker.company.companyName();
const resource = new Resource();
resource.id = uuid.v1();
resource.source = source;
resource.data = { foo: 'bar' }; // <<<<<<<<<
return resource;
});
The issue, is that I am unable to seed the data
field with a JSON or an Array. Only strings seem to work. Every other kind of object throws:
Could not run seed Error: Could not save entity
at EntityFactory.<anonymous> (/node_modules/typeorm-seeding/dist/typeorm-seeding.js:103:27)
at Generator.throw (<anonymous>)
at rejected (/node_modules/typeorm-seeding/dist/typeorm-seeding.js:30:65)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
This is probably an error due to the data type JSON and/or JSONB (available in PostgreSQL). Maybe a bug? Thanks in advance!
@humbertowoody have you tried setting the data
type to simple-json
? that seems to work for me