13
13
import cn .devezhao .persist4j .Field ;
14
14
import cn .devezhao .persist4j .Record ;
15
15
import cn .devezhao .persist4j .engine .ID ;
16
+ import cn .devezhao .persist4j .util .support .QueryHelper ;
16
17
import com .rebuild .core .Application ;
17
18
import com .rebuild .core .metadata .EntityHelper ;
18
19
import com .rebuild .core .metadata .MetadataHelper ;
23
24
import com .rebuild .core .support .ConfigurationItem ;
24
25
import com .rebuild .core .support .KVStorage ;
25
26
import com .rebuild .core .support .RebuildConfiguration ;
27
+ import com .rebuild .core .support .integration .QiniuCloud ;
26
28
import lombok .extern .slf4j .Slf4j ;
27
29
import org .apache .commons .lang .BooleanUtils ;
28
30
@@ -37,6 +39,7 @@ public class DatabaseFixer {
37
39
38
40
private static final String KEY_41 = "DataMigratorV41" ;
39
41
private static final String KEY_346 = "DatabaseFixerV346" ;
42
+ private static final String KEY_370 = "DatabaseFixerV370" ;
40
43
41
44
/**
42
45
* 辅助数据库升级
@@ -69,6 +72,19 @@ public static void fixIfNeed() {
69
72
}
70
73
});
71
74
}
75
+
76
+ if (dbVer <= 55 && !BooleanUtils .toBoolean (KVStorage .getCustomValue (KEY_370 ))) {
77
+ log .info ("Database fixing `V370` ..." );
78
+ ThreadPool .exec (() -> {
79
+ try {
80
+ fixV370 ();
81
+ KVStorage .setCustomValue (KEY_370 , "true" );
82
+ log .info ("Database fixed `V370` all succeeded" );
83
+ } catch (Exception ex ) {
84
+ log .error ("Database fixing `V370` failed : {}" , ThrowableUtils .getRootCause (ex ).getLocalizedMessage ());
85
+ }
86
+ });
87
+ }
72
88
}
73
89
74
90
// #41:多引用字段改为三方表
@@ -130,4 +146,16 @@ private static void fixV346() {
130
146
}
131
147
}
132
148
}
149
+
150
+ // V370:补充附件文件名称
151
+ private static void fixV370 () {
152
+ Object [][] atts = QueryHelper .readArray (
153
+ Application .createQueryNoFilter ("select attachmentId,filePath from Attachment" ));
154
+ for (Object [] o : atts ) {
155
+ String fileName = QiniuCloud .parseFileName ((String ) o [1 ]);
156
+ Record record = EntityHelper .forUpdate ((ID ) o [0 ], UserService .SYSTEM_USER , false );
157
+ record .setString ("fileName" , fileName );
158
+ Application .getCommonsService ().update (record , false );
159
+ }
160
+ }
133
161
}
0 commit comments