Initial project
This commit is contained in:
40
apps/im_app/lib/data/local/drift/app_database.dart
Normal file
40
apps/im_app/lib/data/local/drift/app_database.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:im_app/data/local/drift/tables/users.dart';
|
||||
|
||||
part 'app_database.g.dart';
|
||||
|
||||
@DriftDatabase(tables: [Users])
|
||||
class AppDatabase extends _$AppDatabase {
|
||||
AppDatabase(super.e);
|
||||
|
||||
@override
|
||||
int get schemaVersion => 1;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration {
|
||||
return MigrationStrategy(
|
||||
onCreate: (m) async {
|
||||
await m.createAll();
|
||||
},
|
||||
onUpgrade: (m, from, to) async {
|
||||
// 自动检测并添加缺失列
|
||||
for (final table in allTables) {
|
||||
//取原来的字段
|
||||
final existingColumns = await m.database
|
||||
.customSelect('PRAGMA table_info(${table.actualTableName})')
|
||||
.get();
|
||||
final existingNames = existingColumns
|
||||
.map((r) => r.data['name'] as String)
|
||||
.toSet();
|
||||
|
||||
for (final column in table.$columns) {
|
||||
if (!existingNames.contains(column.name)) {
|
||||
//字段缺失,添加。
|
||||
await m.addColumn(table, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
0
apps/im_app/lib/data/local/drift/daos/.gitkeep
Normal file
0
apps/im_app/lib/data/local/drift/daos/.gitkeep
Normal file
41
apps/im_app/lib/data/local/drift/tables/users.dart
Normal file
41
apps/im_app/lib/data/local/drift/tables/users.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
@DataClassName('User')
|
||||
class Users extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
IntColumn get uid => integer().nullable()();
|
||||
TextColumn get uuid => text().nullable()();
|
||||
IntColumn get lastOnline => integer().nullable()();
|
||||
TextColumn get profilePic => text().nullable()();
|
||||
TextColumn get profilePicGaussian => text().withDefault(const Constant(''))();
|
||||
TextColumn get nickname => text().nullable()();
|
||||
TextColumn get depositName => text().nullable()();
|
||||
IntColumn get hasSetDepositName => integer().withDefault(const Constant(0))();
|
||||
TextColumn get contact => text().nullable()();
|
||||
TextColumn get countryCode => text().nullable()();
|
||||
TextColumn get username => text().nullable()();
|
||||
IntColumn get role => integer().nullable()();
|
||||
IntColumn get relationship => integer().nullable()();
|
||||
IntColumn get friendStatus => integer().nullable()();
|
||||
TextColumn get bio => text().nullable()();
|
||||
TextColumn get userAlias => text().nullable()();
|
||||
IntColumn get requestAt => integer().nullable()();
|
||||
IntColumn get deletedAt => integer().nullable()();
|
||||
TextColumn get email => text().nullable()();
|
||||
TextColumn get recoveryEmail => text().nullable()();
|
||||
TextColumn get remark => text().nullable()();
|
||||
TextColumn get source => text().nullable()();
|
||||
IntColumn get addIndex => integer().nullable()();
|
||||
IntColumn get incomingSoundId => integer().withDefault(const Constant(0))();
|
||||
IntColumn get outgoingSoundId => integer().withDefault(const Constant(0))();
|
||||
IntColumn get notificationSoundId => integer().withDefault(const Constant(0))();
|
||||
IntColumn get sendMessageSoundId => integer().withDefault(const Constant(0))();
|
||||
IntColumn get groupNotificationSoundId => integer().withDefault(const Constant(0))();
|
||||
TextColumn get groupTags => text().withDefault(const Constant('[]'))();
|
||||
TextColumn get friendTags => text().withDefault(const Constant('[]'))();
|
||||
TextColumn get publicKey => text().nullable()();
|
||||
IntColumn get configBits => integer().withDefault(const Constant(0))();
|
||||
TextColumn get hint => text().nullable()();
|
||||
@override
|
||||
String get tableName => 'user';
|
||||
}
|
||||
Reference in New Issue
Block a user