Skip to content

Commit

Permalink
Fix: 修正数据库migration错误,ADD COLUMN前增加检查
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed Oct 19, 2021
1 parent 5692563 commit 0ee9704
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
18 changes: 9 additions & 9 deletions lib/network/app_dio/app_dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ class AppDio with DioMixin implements Dio {
PersistCookieJar(storage: FileStorage(dioConfig!.cookiesPath))));
}

if (kDebugMode) {
interceptors.add(LogInterceptor(
responseBody: false,
error: true,
requestHeader: false,
responseHeader: false,
request: true,
requestBody: true));
}
// if (kDebugMode) {
// interceptors.add(LogInterceptor(
// responseBody: false,
// error: true,
// requestHeader: false,
// responseHeader: false,
// request: true,
// requestBody: true));
// }

interceptors.add(DioFirebasePerformanceInterceptor());

Expand Down
2 changes: 1 addition & 1 deletion lib/network/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Future<GalleryList?> getGallery({
final AdvanceSearchController _searchController = Get.find();
DioHttpClient dioHttpClient = DioHttpClient(dioConfig: ehDioConfig);

logger.d('df ${ehDioConfig.domainFronting}');
logger.v('df ${ehDioConfig.domainFronting}');

late final String _url;
switch (galleryListType) {
Expand Down
38 changes: 33 additions & 5 deletions lib/store/floor/database.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:fehviewer/utils/logger.dart';
import 'package:floor/floor.dart';
import 'package:sqflite/sqflite.dart' as sqflite;

Expand All @@ -12,7 +13,7 @@ import 'entity/tag_translat.dart';

part 'database.g.dart';

@Database(version: 7, entities: [GalleryTask, GalleryImageTask, TagTranslat])
@Database(version: 8, entities: [GalleryTask, GalleryImageTask, TagTranslat])
abstract class EhDatabase extends FloorDatabase {
GalleryTaskDao get galleryTaskDao;

Expand All @@ -27,7 +28,8 @@ final ehMigrations = [
migration3to4,
migration4to5,
migration5to6,
migration6to7,
migration6to8,
migration7to8,
];

// create migration
Expand Down Expand Up @@ -55,6 +57,32 @@ final migration5to6 = Migration(5, 6, (database) async {
await database.execute('ALTER TABLE GalleryTask ADD COLUMN uploader TEXT');
});

final migration6to7 = Migration(6, 7, (database) async {
await database.execute('ALTER TABLE GalleryTask ADD COLUMN jsonString TEXT');
});
final migration7to8 =
Migration(7, 8, (database) => _addColumnJsonString(database));

final migration6to8 =
Migration(6, 8, (database) => _addColumnJsonString(database));

Future _addColumnJsonString(sqflite.Database database) async {
await _addColumn(
database,
tabName: 'GalleryTask',
columnName: 'jsonString',
type: 'TEXT',
);
}

Future _addColumn(
sqflite.Database database, {
required String tabName,
required String columnName,
required String type,
}) async {
final columnExiste = await database.rawQuery(
'select * from sqlite_master WHERE name=? and sql like ?',
[tabName, '%`$columnName`%']);
logger.i('$columnName columnExiste ${columnExiste.isNotEmpty}');
if (columnExiste.isEmpty) {
await database.execute('ALTER TABLE $tabName ADD COLUMN $columnName $type');
}
}
2 changes: 1 addition & 1 deletion lib/store/floor/database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: fehviewer

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.1.26+316
version: 1.1.26+317

environment:
sdk: '>=2.14.0 <3.0.0'
Expand Down

0 comments on commit 0ee9704

Please sign in to comment.