fix: writer/reader correctness and determinism issues
- merge: cloneTable keeps relationships; skip-tables applies to new schemas - diff: detect schema description/owner changes - prisma: reader no longer turns relation fields into columns, enum detection via declared names; writer type mapping is ordered - typeorm writer: keep explicit SQL types that cannot be inferred - drizzle: enum columns call the enum constant; reader resolves them - mysql/mssql/sqlite writers: honour OutputPath, deterministic column and constraint order; mssql live execute covers full schema - template: ToYAML recovers from panics; Merge nil-pointer loop - regenerate drizzle fixtures
This commit is contained in:
@@ -266,35 +266,37 @@ func (w *Writer) sqlTypeToPrisma(sqlType string, schema *models.Schema) string {
|
||||
}
|
||||
}
|
||||
|
||||
// Standard type mapping
|
||||
typeMap := map[string]string{
|
||||
"text": "String",
|
||||
"varchar": "String",
|
||||
"character varying": "String",
|
||||
"char": "String",
|
||||
"boolean": "Boolean",
|
||||
"bool": "Boolean",
|
||||
"integer": "Int",
|
||||
"int": "Int",
|
||||
"int4": "Int",
|
||||
"bigint": "BigInt",
|
||||
"int8": "BigInt",
|
||||
"double precision": "Float",
|
||||
"float": "Float",
|
||||
"float8": "Float",
|
||||
"decimal": "Decimal",
|
||||
"numeric": "Decimal",
|
||||
"timestamp": "DateTime",
|
||||
"timestamptz": "DateTime",
|
||||
"date": "DateTime",
|
||||
"jsonb": "Json",
|
||||
"json": "Json",
|
||||
"bytea": "Bytes",
|
||||
// Ordered so more specific patterns win (bigint/int8 before int); map
|
||||
// iteration would make the result nondeterministic.
|
||||
typeMap := []struct{ pattern, prismaType string }{
|
||||
{"bigint", "BigInt"},
|
||||
{"int8", "BigInt"},
|
||||
{"text", "String"},
|
||||
{"varchar", "String"},
|
||||
{"character varying", "String"},
|
||||
{"char", "String"},
|
||||
{"boolean", "Boolean"},
|
||||
{"bool", "Boolean"},
|
||||
{"integer", "Int"},
|
||||
{"int4", "Int"},
|
||||
{"int", "Int"},
|
||||
{"double precision", "Float"},
|
||||
{"float8", "Float"},
|
||||
{"float", "Float"},
|
||||
{"decimal", "Decimal"},
|
||||
{"numeric", "Decimal"},
|
||||
{"timestamptz", "DateTime"},
|
||||
{"timestamp", "DateTime"},
|
||||
{"date", "DateTime"},
|
||||
{"jsonb", "Json"},
|
||||
{"json", "Json"},
|
||||
{"bytea", "Bytes"},
|
||||
}
|
||||
|
||||
for sqlPattern, prismaType := range typeMap {
|
||||
if strings.Contains(strings.ToLower(sqlType), sqlPattern) {
|
||||
return prismaType
|
||||
lower := strings.ToLower(sqlType)
|
||||
for _, m := range typeMap {
|
||||
if strings.Contains(lower, m.pattern) {
|
||||
return m.prismaType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user