isar / isar/hive

We need to support versioning in Hive DB. Please help

Open
#887 3 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Question**
We had 4 keys in Hive DB and app is live. We changed the requirement and updated Hive DB with 4 more params. But if we run new code over old code. app crashes

**Code sample**
import 'package:hive/hive.dart';
part 'hive_oehub_message.g.dart';

@HiveType(typeId: 3, adapterName: "OEHubMessageAdapter")
class HiveOEHubMessage extends HiveObject {
@HiveField(0)
String expiryDate;
@HiveField(1)
int id;
@HiveField(2)
int isRead;
@HiveField(3)
String message;
@HiveField(4)
String summary;
@HiveField(5)
String thumbnail;
@HiveField(6)
String title;
@HiveField(7)
String url;
@HiveField(8)
String notificationType;
@HiveField(9)
String publishedOn;
@HiveField(10)
String timstampLastRetrived;
@HiveField(11)
String urerId;
@HiveField(12)
String isDelete;
@HiveField(13)
String validFrom;
@HiveField(14)
String messageType;

HiveOEHubMessage(
{required this.expiryDate,
required this.id,
required this.isDelete,
required this.isRead,
required this.message,
required this.publishedOn,
required this.summary,
required this.thumbnail,
required this.timstampLastRetrived,
required this.title,
required this.notificationType,
required this.urerId,
required this.url,
required this.validFrom,
required this.messageType});
}

New file is

import 'package:hive/hive.dart';
part 'hive_oehub_message.g.dart';

@HiveType(typeId: 3, adapterName: "OEHubMessageAdapter")
class HiveOEHubMessage extends HiveObject {
@HiveField(0)
String expiryDate;
@HiveField(1)
int id;
@HiveField(2)
int isRead;
@HiveField(3)
String message;
@HiveField(4)
String summary;
@HiveField(5)
String thumbnail;
@HiveField(6)
String title;
@HiveField(7)
String url;
@HiveField(8)
String notificationType;
@HiveField(9)
String publishedOn;
@HiveField(10)
String timstampLastRetrived;
@HiveField(11)
String urerId;
@HiveField(12)
String isDelete;
@HiveField(13)
String validFrom;
@HiveField(14)
String messageType;
@HiveField(15)
int likeCount = 0;
@HiveField(16)
int commentCount = 0;
@HiveField(17)
int shareCount = 0;
@HiveField(18)
int userLiked = 0;
@HiveField(19)
int mappingId = 0;

HiveOEHubMessage(
{required this.expiryDate,
required this.id,
required this.isDelete,
required this.isRead,
required this.message,
required this.publishedOn,
required this.summary,
required this.thumbnail,
required this.timstampLastRetrived,
required this.title,
required this.notificationType,
required this.urerId,
required this.url,
required this.validFrom,
required this.messageType,
required this.likeCount,
required this.commentCount,
required this.shareCount,
required this.userLiked,
required this.mappingId});
}

**Version**
- Platform: iOS, Android
- Flutter version: 2.8.1
- Hive version:
- hive: ^2.0.4
hive_flutter: ^1.1.0

Let us know how to migrate old data in to new.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.