Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
63 lines
2.5 KiB
Dart
63 lines
2.5 KiB
Dart
import 'package:drift/drift.dart';
|
||
import '../converters.dart';
|
||
import 'packs.dart';
|
||
|
||
/// Таблица Tests - тесты
|
||
class Tests extends Table {
|
||
IntColumn get id => integer().autoIncrement()();
|
||
|
||
TextColumn get name => text()();
|
||
TextColumn get color => text().nullable()();
|
||
TextColumn get cover => text().nullable()();
|
||
TextColumn get version => text().nullable()();
|
||
TextColumn get time => text().nullable()();
|
||
TextColumn get timeSubtitle => text().nullable()();
|
||
|
||
// Audit
|
||
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
||
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
||
BoolColumn get isDeleted => boolean().withDefault(const Constant(false))();
|
||
}
|
||
|
||
/// Таблица TestQuestions - вопросы тестов
|
||
class TestQuestions extends Table {
|
||
IntColumn get id => integer().autoIncrement()();
|
||
IntColumn get testId => integer().references(Tests, #id, onDelete: KeyAction.cascade)();
|
||
|
||
// Тип вопроса (enum as string)
|
||
TextColumn get questionType => text()();
|
||
TextColumn get body => text()();
|
||
|
||
// Audit
|
||
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
||
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
||
}
|
||
|
||
/// Таблица TestPackRelations - связь Tests с CardPacks (many-to-many)
|
||
class TestPackRelations extends Table {
|
||
IntColumn get testId => integer().references(Tests, #id, onDelete: KeyAction.cascade)();
|
||
IntColumn get packId => integer().references(CardPacks, #id, onDelete: KeyAction.cascade)();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {testId, packId};
|
||
}
|
||
|
||
/// Таблица TestStatistics - статистика прохождения тестов
|
||
class TestStatistics extends Table {
|
||
IntColumn get id => integer().autoIncrement()();
|
||
IntColumn get userId => integer()(); // Reference to Users, but not FK to avoid circular deps
|
||
IntColumn get testId => integer().references(Tests, #id, onDelete: KeyAction.cascade)();
|
||
|
||
// Результаты (JSON)
|
||
TextColumn get results => text()
|
||
.withDefault(const Constant('{}'))
|
||
.map(const JsonMapConverter())();
|
||
|
||
DateTimeColumn get completedAt => dateTime().withDefault(currentDateAndTime)();
|
||
|
||
// Audit
|
||
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
||
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
||
}
|
||
|
||
// Конвертеры импортированы из converters.dart
|