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:
Kononnable 2020-03-28 09:51:47 +01:00
parent 3cf7272b5b
commit c6538f8c67
7 changed files with 38 additions and 7 deletions

View File

@ -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}"`;
}
}

View File

@ -530,6 +530,6 @@ export default class MysqlDriver extends AbstractDriver {
return `() => ['${defaultValue.split(",").join("','")}']`;
}
return `() => \`${defaultValue}\``;
return `() => "'${defaultValue}'"`;
}
}

View File

@ -417,6 +417,6 @@ export default class OracleDriver extends AbstractDriver {
defaultVal = defaultVal.slice(0, -1);
}
return `() => \`${defaultVal}\``;
return `() => "${defaultVal}"`;
}
}

View File

@ -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}"`;
}
}

View File

@ -437,6 +437,6 @@ export default class SqliteDriver extends AbstractDriver {
return undefined;
}
return `() => \`${defVal}\``;
return `() => "${defVal}"`;
}
}

View 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;
}

View File

@ -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;
}