sonamu 0.11.6 → 0.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/migration/code-generation.d.ts.map +1 -1
- package/dist/migration/code-generation.js +23 -8
- package/dist/migration/migration-set.d.ts.map +1 -1
- package/dist/migration/migration-set.js +14 -7
- package/dist/migration/postgresql-schema-reader.d.ts +1 -0
- package/dist/migration/postgresql-schema-reader.d.ts.map +1 -1
- package/dist/migration/postgresql-schema-reader.js +21 -7
- package/package.json +1 -1
- package/src/migration/code-generation.ts +37 -8
- package/src/migration/migration-set.ts +12 -2
- package/src/migration/postgresql-schema-reader.ts +21 -5
|
@@ -39,6 +39,7 @@ export type PgColumn = {
|
|
|
39
39
|
character_maximum_length: number | null;
|
|
40
40
|
precision: number | null;
|
|
41
41
|
numeric_scale: number | null;
|
|
42
|
+
atttypmod?: number | null;
|
|
42
43
|
is_nullable: string;
|
|
43
44
|
column_default: string | null;
|
|
44
45
|
is_generated: string; // 's' = STORED, 'v' = VIRTUAL, '' = none
|
|
@@ -76,6 +77,21 @@ type TableSchemaRows = {
|
|
|
76
77
|
|
|
77
78
|
type RawCapableKnex = Pick<Knex, "raw">;
|
|
78
79
|
|
|
80
|
+
function decodeNumericTypeModifier(
|
|
81
|
+
typeModifier: number | null | undefined,
|
|
82
|
+
): Pick<MigrationColumn, "precision" | "scale"> | null {
|
|
83
|
+
if (typeModifier === undefined || typeModifier === null || typeModifier < 4) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// information_schema가 잃는 배열 typmod와 음수 scale을 PostgreSQL 내부 표현에서 복원한다.
|
|
88
|
+
const modifier = typeModifier - 4;
|
|
89
|
+
const precision = modifier >>> 16;
|
|
90
|
+
const unsignedScale = modifier & 0x7ff;
|
|
91
|
+
const scale = unsignedScale >= 1024 ? unsignedScale - 2048 : unsignedScale;
|
|
92
|
+
return { precision, scale };
|
|
93
|
+
}
|
|
94
|
+
|
|
79
95
|
class PostgreSQLSchemaReaderClass {
|
|
80
96
|
private readonly genericIndexTypes = new Set(["btree", "hash", "gin", "gist", "pgroonga"]);
|
|
81
97
|
|
|
@@ -348,6 +364,7 @@ class PostgreSQLSchemaReaderClass {
|
|
|
348
364
|
) AS character_maximum_length,
|
|
349
365
|
COALESCE(c.datetime_precision, c.numeric_precision) AS precision,
|
|
350
366
|
c.numeric_scale,
|
|
367
|
+
a.atttypmod,
|
|
351
368
|
c.is_nullable,
|
|
352
369
|
c.column_default,
|
|
353
370
|
COALESCE(a.attgenerated, '') as is_generated,
|
|
@@ -987,14 +1004,13 @@ class PostgreSQLSchemaReaderClass {
|
|
|
987
1004
|
|
|
988
1005
|
// NumberOrNumeric types
|
|
989
1006
|
if (udt_name === "numeric") {
|
|
1007
|
+
const numericMetadata =
|
|
1008
|
+
decodeNumericTypeModifier(dbColumn.atttypmod) ??
|
|
1009
|
+
(precision !== null && numeric_scale !== null ? { precision, scale: numeric_scale } : {});
|
|
990
1010
|
return {
|
|
991
1011
|
type: `numberOrNumeric${singleOrArray}`,
|
|
992
1012
|
numberType: "numeric",
|
|
993
|
-
...
|
|
994
|
-
numeric_scale !== null && {
|
|
995
|
-
precision: precision,
|
|
996
|
-
scale: numeric_scale,
|
|
997
|
-
}),
|
|
1013
|
+
...numericMetadata,
|
|
998
1014
|
};
|
|
999
1015
|
}
|
|
1000
1016
|
if (udt_name === "float4") {
|