twonly-app/lib/src/database/tables/contact_groups.table.dart
otsmr deb712f21d
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
merge labels and shortcuts to contact groups
2026-09-01 23:10:04 +02:00

48 lines
1.5 KiB
Dart

import 'package:drift/drift.dart';
import 'package:twonly/src/database/tables/contacts.table.dart';
import 'package:twonly/src/database/tables/groups.table.dart';
@DataClassName('ContactGroup')
class ContactGroups extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get name => text()();
TextColumn get emoji => text().nullable()();
IntColumn get textColor => integer()();
IntColumn get backgroundColor => integer()();
BoolColumn get showAsShortcut =>
boolean().withDefault(const Constant(false))();
BoolColumn get showAsLabel => boolean().withDefault(const Constant(true))();
IntColumn get usageCounter => integer().withDefault(const Constant(0))();
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
}
@DataClassName('ContactGroupMember')
class ContactGroupMembers extends Table {
IntColumn get id => integer().autoIncrement()();
IntColumn get contactGroupId => integer().references(
ContactGroups,
#id,
onDelete: KeyAction.cascade,
)();
IntColumn get userId => integer().nullable().references(
Contacts,
#userId,
onDelete: KeyAction.cascade,
)();
TextColumn get groupId => text().nullable().references(
Groups,
#groupId,
onDelete: KeyAction.cascade,
)();
@override
List<Set<Column<Object>>> get uniqueKeys => [
{contactGroupId, userId},
{contactGroupId, groupId},
];
@override
List<String> get customConstraints => [
'CHECK ((user_id IS NOT NULL) != (group_id IS NOT NULL))',
];
}