I want to replace
@Column("uuid", {
primary: true,
name: "id",
default: () => "uuid_generate_v4()",
})
with
@PrimaryGeneratedColumn
in a file with the following content:
export class SomeClass {
@Column("uuid", {
primary: true,
name: "id",
default: () => "uuid_generate_v4()",
})
id: string;
@Column("timestamp with time zone", {
name: "created_at",
default: () => "now()",
})
created_at: Date;
@Column("timestamp with time zone", {
name: "updated_at",
default: () => "now()",
})
updated_at: Date;
@Column("uuid", { name: "other_id", unique: true })
other_id: string;
}
This is my current solution:
sed -E -i '' -e '/@Column\(\"uuid\", \{/,/\}\)?/c @PrimaryGeneratedColumn\(\"uuid\"\)' fileName
It basically works, but it's too inaccurate and also replaces other lines that shouldn't be replaced. I tried to add uuid_generate_v4() but couldn't get it to work, probably because of the line breaks.