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
99 lines
3.8 KiB
Dart
99 lines
3.8 KiB
Dart
import 'package:drift/drift.dart';
|
||
import 'package:drift_postgres/drift_postgres.dart';
|
||
import '../converters.dart' show generateUuid, JsonMapConverter;
|
||
import 'packs.dart';
|
||
|
||
/// Таблица Tests - тесты
|
||
class Tests extends Table {
|
||
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
|
||
TextColumn get id => text()
|
||
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
|
||
|
||
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
|
||
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
|
||
.withDefault(now())();
|
||
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
|
||
.withDefault(now())();
|
||
BoolColumn get isDeleted => boolean()
|
||
.withDefault(const Constant(false))
|
||
.customConstraint('')(); // PostgreSQL использует нативный BOOLEAN
|
||
Column<PgDateTime> get deletedAt => customType(PgTypes.timestampWithTimezone)
|
||
.nullable()();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {id};
|
||
}
|
||
|
||
/// Таблица TestQuestions - вопросы тестов
|
||
class TestQuestions extends Table {
|
||
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
|
||
TextColumn get id => text()
|
||
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
|
||
TextColumn get testId => text()
|
||
.references(Tests, #id, onDelete: KeyAction.cascade)();
|
||
|
||
// Тип вопроса (enum as string)
|
||
TextColumn get questionType => text()();
|
||
TextColumn get body => text()();
|
||
|
||
// Audit
|
||
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
|
||
.withDefault(now())();
|
||
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
|
||
.withDefault(now())();
|
||
BoolColumn get isDeleted => boolean()
|
||
.withDefault(const Constant(false))
|
||
.customConstraint('')();
|
||
Column<PgDateTime> get deletedAt => customType(PgTypes.timestampWithTimezone)
|
||
.nullable()();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {id};
|
||
}
|
||
|
||
/// Таблица TestPackRelations - связь Tests с CardPacks (many-to-many)
|
||
class TestPackRelations extends Table {
|
||
TextColumn get testId => text()
|
||
.references(Tests, #id, onDelete: KeyAction.cascade)();
|
||
TextColumn get packId => text()
|
||
.references(CardPacks, #id, onDelete: KeyAction.cascade)();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {testId, packId};
|
||
}
|
||
|
||
/// Таблица TestStatistics - статистика прохождения тестов
|
||
class TestStatistics extends Table {
|
||
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
|
||
TextColumn get id => text()
|
||
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
|
||
TextColumn get userId => text()(); // Reference to Users, but not FK to avoid circular deps
|
||
TextColumn get testId => text()
|
||
.references(Tests, #id, onDelete: KeyAction.cascade)();
|
||
|
||
// Результаты (JSON)
|
||
TextColumn get results => text()
|
||
.withDefault(const Constant('{}'))
|
||
.map(const JsonMapConverter())();
|
||
|
||
Column<PgDateTime> get completedAt => customType(PgTypes.timestampWithTimezone)
|
||
.withDefault(now())();
|
||
|
||
// Audit
|
||
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
|
||
.withDefault(now())();
|
||
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
|
||
.withDefault(now())();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {id};
|
||
}
|
||
|
||
// Конвертеры импортированы из converters.dart
|