add_usercode.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import 'package:vitalapp/database/db.dart';
  2. import 'interface/database_patch.dart';
  3. import 'package:fis_common/logger/logger.dart';
  4. ///新增表patients、diagnosis中的userCode字段
  5. class DatabasePatchAddUserCode extends IDatabasePatch {
  6. @override
  7. Future<int> performTask(int version) async {
  8. if (version == 0) {
  9. logger.w("DatabasePatchAddUserCode performTask version:$version.");
  10. try {
  11. // 新增userCode字段
  12. String alterTableQueryPatients = '''
  13. ALTER TABLE patients
  14. ADD COLUMN userCode VARCHAR(100) NOT NULL DEFAULT ''
  15. ''';
  16. await db.database.execute(alterTableQueryPatients);
  17. String alterTableQueryDiagnosis = '''
  18. ALTER TABLE diagnosis
  19. ADD COLUMN userCode VARCHAR(100) NOT NULL DEFAULT ''
  20. ''';
  21. await db.database.execute(alterTableQueryDiagnosis);
  22. return await super.performTask(version + 1);
  23. } catch (e) {
  24. logger.e("DatabasePatchAddUserCode performTask version:$version.", e);
  25. return version;
  26. }
  27. } else {
  28. return version;
  29. }
  30. }
  31. }