File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ type TypeName =
4343 | BooleanTypeName
4444 | DateTimeTypeName
4545 | DateTimeOffsetTypeName
46+ member this.SupportsCollation =
47+ match this with
48+ | StringTypeName _ -> true
49+ | _ -> false
4650 override this.ToString () =
4751 match this with
4852 | GuidTypeName -> " GUID"
Original file line number Diff line number Diff line change @@ -108,19 +108,30 @@ type private PostgresStatement(indexer : IParameterIndexer) as this =
108108 this.Expr.Name( col)
109109 ws
110110 |]
111- let inline changeType ( col : Name ) ( ty : TypeName ) ( collation : Name option ) =
111+ let inline changeType ( col : Name ) ( ty : TypeName ) ( collation : Name option ) changingType =
112112 seq {
113113 yield ! alterColumn col
114114 yield text " TYPE"
115115 yield ws
116116 yield ! this.Expr.TypeName( ty)
117117 match collation with
118- | None -> ()
119- | Some collation ->
118+ | Some collation when ty.SupportsCollation ->
120119 yield ws
121120 yield text " COLLATE"
122121 yield ws
123122 yield this.Expr.CollationName( collation)
123+ | _ -> ()
124+ if changingType then
125+ yield ws
126+ yield text " USING"
127+ yield ws
128+ yield text " CAST("
129+ yield this.Expr.Name( col)
130+ yield ws
131+ yield text " AS"
132+ yield ws
133+ yield ! this.Expr.TypeName( ty)
134+ yield text " )"
124135 }
125136 seq {
126137 yield text " ALTER TABLE"
@@ -165,10 +176,10 @@ type private PostgresStatement(indexer : IParameterIndexer) as this =
165176 yield text ( if change.NewNullable then " DROP NOT NULL" else " SET NOT NULL" )
166177 | ChangeType change ->
167178 let schemaColumn = change.ExistingInfo.Column |> Option.get
168- yield ! changeType change.Column change.NewType schemaColumn.Collation
179+ yield ! changeType change.Column change.NewType schemaColumn.Collation true
169180 | ChangeCollation change ->
170181 let schemaColumn = change.ExistingInfo.Column |> Option.get
171- yield ! changeType change.Column schemaColumn.ColumnTypeName ( Some change.NewCollation)
182+ yield ! changeType change.Column schemaColumn.ColumnTypeName ( Some change.NewCollation) false
172183 }
173184 override this.PrimaryKeyClause ( pk ) =
174185 seq {
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ ALTER TABLE "public"."smoketable1" ALTER COLUMN "float64column" DROP DEFAULT;
125125ALTER TABLE "smoketable1" ALTER COLUMN "stringncolumn" TYPE VARCHAR(80) COLLATE "C";
126126ALTER TABLE "smoketable1" ALTER COLUMN "float64column" DROP NOT NULL;
127127ALTER TABLE "smoketable1" ALTER COLUMN "float64column" SET NOT NULL;
128- ALTER TABLE "smoketable1" ALTER COLUMN "int16column" TYPE INT;
128+ ALTER TABLE "smoketable1" ALTER COLUMN "int16column" TYPE INT USING CAST("int16column" AS INT) ;
129129DROP INDEX "ix_smoketable2_parentid";
130130ALTER TABLE "smoketable2" DROP CONSTRAINT "smoketable2_friendid_fk_smoketablefriend_autocolumn" RESTRICT;
131131ALTER TABLE "smoketable2" DROP COLUMN "friendid" RESTRICT;
You can’t perform that action at this time.
0 commit comments