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 на стороне БД)
|
2025-12-20 18:26:15 +00:00
|
|
|
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-20 18:26:15 +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))();
|
2025-12-20 18:26:15 +00:00
|
|
|
|
2025-12-13 13:27:05 +00:00
|
|
|
TextColumn get packId => text().nullable()();
|
|
|
|
|
TextColumn get testId => text().nullable()();
|
2025-12-20 18:26:15 +00:00
|
|
|
|
2025-12-13 13:27:05 +00:00
|
|
|
// Audit
|
2025-12-20 18:26:15 +00:00
|
|
|
Column<PgDateTime> get createdAt =>
|
|
|
|
|
customType(PgTypes.timestampWithTimezone).withDefault(now())();
|
|
|
|
|
Column<PgDateTime> get updatedAt =>
|
|
|
|
|
customType(PgTypes.timestampWithTimezone).withDefault(now())();
|
|
|
|
|
BoolColumn get isDeleted =>
|
|
|
|
|
boolean().customConstraint('NOT NULL DEFAULT FALSE')();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|