add test;
changes are necessary only in postgres driver it's the only one where typeorm support default value for json fields
This commit is contained in:
parent
3cf7272b5b
commit
c6538f8c67
@ -520,6 +520,6 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
|
||||
defaultValue = defaultValue.slice(1, -1);
|
||||
}
|
||||
|
||||
return `() => \`${defaultValue}\``;
|
||||
return `() => "${defaultValue}"`;
|
||||
}
|
||||
}
|
||||
|
@ -530,6 +530,6 @@ export default class MysqlDriver extends AbstractDriver {
|
||||
return `() => ['${defaultValue.split(",").join("','")}']`;
|
||||
}
|
||||
|
||||
return `() => \`${defaultValue}\``;
|
||||
return `() => "'${defaultValue}'"`;
|
||||
}
|
||||
}
|
||||
|
@ -417,6 +417,6 @@ export default class OracleDriver extends AbstractDriver {
|
||||
defaultVal = defaultVal.slice(0, -1);
|
||||
}
|
||||
|
||||
return `() => \`${defaultVal}\``;
|
||||
return `() => "${defaultVal}"`;
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +103,8 @@ export default class PostgresDriver extends AbstractDriver {
|
||||
const defaultValue = generated
|
||||
? undefined
|
||||
: PostgresDriver.ReturnDefaultValueFunction(
|
||||
resp.column_default
|
||||
resp.column_default,
|
||||
resp.data_type
|
||||
);
|
||||
|
||||
const columnTypes = this.MatchColumnTypes(
|
||||
@ -648,7 +649,8 @@ export default class PostgresDriver extends AbstractDriver {
|
||||
}
|
||||
|
||||
private static ReturnDefaultValueFunction(
|
||||
defVal: string | null
|
||||
defVal: string | null,
|
||||
dataType: string
|
||||
): string | undefined {
|
||||
let defaultValue = defVal;
|
||||
if (!defaultValue) {
|
||||
@ -656,6 +658,9 @@ export default class PostgresDriver extends AbstractDriver {
|
||||
}
|
||||
defaultValue = defaultValue.replace(/'::[\w ]*/, "'");
|
||||
|
||||
return `() => \`${defaultValue}\``;
|
||||
if (["json", "jsonb"].some(x => x === dataType)) {
|
||||
return `${defaultValue.slice(1, defaultValue.length - 1)}`;
|
||||
}
|
||||
return `() => "${defaultValue}"`;
|
||||
}
|
||||
}
|
||||
|
@ -437,6 +437,6 @@ export default class SqliteDriver extends AbstractDriver {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return `() => \`${defVal}\``;
|
||||
return `() => "${defVal}"`;
|
||||
}
|
||||
}
|
||||
|
22
test/integration/github-issues/248/entity/Post.ts
Normal file
22
test/integration/github-issues/248/entity/Post.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn, Index } from "typeorm";
|
||||
|
||||
@Entity("Post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column("json", {
|
||||
default: { type: null, values: true }
|
||||
})
|
||||
data: object;
|
||||
|
||||
@Column("jsonb", {
|
||||
default: { type: null, values: true }
|
||||
})
|
||||
data2: object;
|
||||
|
||||
@Column()
|
||||
text: string;
|
||||
|
||||
}
|
@ -132,6 +132,10 @@ function runTestForMultipleDrivers(
|
||||
return dbDrivers.filter(dbDriver =>
|
||||
["mysql", "mariadb"].includes(dbDriver)
|
||||
);
|
||||
case "248":
|
||||
return dbDrivers.filter(dbDriver =>
|
||||
dbDriver === "postgres"
|
||||
);
|
||||
default:
|
||||
return dbDrivers;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user