mnemo_cards/mnemo_cards_backend/lib/database/tables/statistics.dart

41 lines
1.6 KiB
Dart
Raw Normal View History

2025-12-13 13:27:05 +00:00
import 'package:drift/drift.dart';
2025-12-13 23:35:14 +00:00
import 'package:drift_postgres/drift_postgres.dart';
2025-12-13 13:27:05 +00:00
import 'users.dart';
2025-12-13 20:55:50 +00:00
import '../converters.dart' show generateUuid;
2025-12-13 13:27:05 +00:00
/// Таблица StudySessions - сессии изучения
class StudySessions extends Table {
2025-12-13 23:35:14 +00:00
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
TextColumn get id => text()
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
TextColumn get userId => text()
.references(Users, #id, onDelete: KeyAction.cascade)();
2025-12-13 13:27:05 +00:00
TextColumn get sessionId => text().nullable().unique()();
2025-12-13 23:35:14 +00:00
Column<PgDateTime> get startTime => customType(PgTypes.timestampWithTimezone)();
Column<PgDateTime> get endTime => customType(PgTypes.timestampWithTimezone)
.nullable()();
2025-12-13 13:27:05 +00:00
IntColumn get wordsLearned => integer().withDefault(const Constant(0))();
IntColumn get testsCompleted => integer().withDefault(const Constant(0))();
RealColumn get accuracy => real().withDefault(const Constant(0.0))();
TextColumn get packId => text().nullable()();
TextColumn get testId => text().nullable()();
// Audit
2025-12-13 23:35:14 +00:00
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
.withDefault(now())();
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
.withDefault(now())();
2025-12-14 20:36:05 +00:00
BoolColumn get isDeleted => boolean()
.withDefault(const Constant(false))
.customConstraint('')();
Column<PgDateTime> get deletedAt => customType(PgTypes.timestampWithTimezone)
.nullable()();
2025-12-13 20:55:50 +00:00
@override
Set<Column> get primaryKey => {id};
2025-12-13 13:27:05 +00:00
}