@@ -116,6 +116,7 @@ protected override string GetComparisonDDLStatements(params TypeSchemaAndName[]
116116 {
117117 var sb = new StringBuilder ( ) ;
118118 var seqcols = new List < NativeTuple < ColumnInfo , string [ ] , bool > > ( ) ; //序列
119+ var indexSb = new StringBuilder ( ) ;
119120 foreach ( var obj in objects )
120121 {
121122 if ( sb . Length > 0 ) sb . Append ( "\r \n " ) ;
@@ -185,20 +186,20 @@ protected override string GetComparisonDDLStatements(params TypeSchemaAndName[]
185186 //创建表的索引
186187 foreach ( var uk in tb . Indexes )
187188 {
188- sb . Append ( "CREATE " ) ;
189+ indexSb . Append ( "CREATE " ) ;
189190 if ( uk . IsUnique )
190- sb . Append ( "UNIQUE " ) ;
191- sb . Append ( "INDEX " ) ;
192- sb . Append ( uk . Name ) . Append ( " ON " ) . Append ( _commonUtils . QuoteSqlName ( ReplaceIndexName ( createTableName , tbname [ 1 ] ) ) ) ;
193- sb . Append ( "(" ) ;
191+ indexSb . Append ( "UNIQUE " ) ;
192+ indexSb . Append ( "INDEX " ) ;
193+ indexSb . Append ( uk . Name ) . Append ( " ON " ) . Append ( _commonUtils . QuoteSqlName ( ReplaceIndexName ( createTableName , tbname [ 1 ] ) ) ) ;
194+ indexSb . Append ( "(" ) ;
194195 foreach ( var tbcol in uk . Columns )
195196 {
196- sb . Append ( _commonUtils . QuoteSqlName ( tbcol . Column . Attribute . Name ) ) ;
197+ indexSb . Append ( _commonUtils . QuoteSqlName ( tbcol . Column . Attribute . Name ) ) ;
197198 if ( tbcol . IsDesc )
198- sb . Append ( " DESC" ) ;
199- sb . Append ( ", " ) ;
199+ indexSb . Append ( " DESC" ) ;
200+ indexSb . Append ( ", " ) ;
200201 }
201- sb . Remove ( sb . Length - 2 , 2 ) . Append ( ");\r \n " ) ;
202+ indexSb . Remove ( indexSb . Length - 2 , 2 ) . Append ( ");\r \n " ) ;
202203 }
203204 //备注
204205 foreach ( var tbcol in tb . ColumnsByPosition )
@@ -221,6 +222,7 @@ protected override string GetComparisonDDLStatements(params TypeSchemaAndName[]
221222 else
222223 tboldname = null ; //如果新表已经存在,不走改表名逻辑
223224 }
225+
224226 foreach ( var seqcol in seqcols )
225227 {
226228 var tbname = seqcol . Item2 ;
@@ -236,6 +238,9 @@ protected override string GetComparisonDDLStatements(params TypeSchemaAndName[]
236238 //sb.Append(" SELECT case when max(").Append(colname2).Append(") is null then 0 else setval('").Append(seqname).Append("', max(").Append(colname2).Append(")) end FROM ").Append(tbname2).Append(";\r\n");
237239 }
238240 }
241+
242+ sb . Append ( indexSb ) ;
243+
239244 return sb . Length == 0 ? null : sb . ToString ( ) ;
240245 }
241246 }
0 commit comments