Migration.m 899 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // Migration.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2021/1/8.
  6. // Copyright © 2021 JCZ. All rights reserved.
  7. //
  8. #import "Migration.h"
  9. #import "FMDB.h"
  10. @interface Migration()
  11. @property (nonatomic, copy) NSString *myName;
  12. @property (nonatomic, assign) uint64_t myVersion;
  13. @property (nonatomic, strong) NSArray *updateArray;
  14. @end
  15. @implementation Migration
  16. - (instancetype)initWithName:(NSString *)name andVersion:(uint64_t)version andExecuteUpdateArray:(NSArray *)updateArray {
  17. if (self = [super init]) {
  18. _myName = name;
  19. _myVersion = version;
  20. _updateArray = updateArray;
  21. }
  22. return self;
  23. }
  24. - (NSString *)name {
  25. return _myName;
  26. }
  27. - (uint64_t)version {
  28. return _myVersion;
  29. }
  30. - (BOOL)migrateDatabase:(FMDatabase *)database error:(out NSError *__autoreleasing *)error {
  31. for (NSString *updateStr in _updateArray) {
  32. [database executeUpdate:updateStr];
  33. }
  34. return YES;
  35. }
  36. @end