mnemo_cards/mnemo_cards_backend/lib/database/tables/tasks.dart
Dmitry 550b56276e
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Mobile App CI / test (push) Waiting to run
Mobile App CI / build-android (push) Blocked by required conditions
Mobile App CI / build-ios (push) Blocked by required conditions
Web App CI / test (push) Waiting to run
Web App 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
Deploy Telegram Bot / Deploy Telegram Bot (push) Waiting to run
postgress fix
2025-12-13 23:55:50 +03:00

101 lines
3.8 KiB
Dart

import 'package:drift/drift.dart';
import '../converters.dart' show generateUuid, JsonListConverter, JsonMapConverter, StringListConverter;
import 'users.dart';
/// Таблица Tasks - задачи системы
class Tasks extends Table {
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
TextColumn get name => text()();
IntColumn get minCycleMillis => integer()();
IntColumn get maxCycleMillis => integer()();
IntColumn get intervalMillis => integer()();
IntColumn get timeoutMillis => integer()();
TextColumn get status => text().nullable()();
TextColumn get description => text().nullable()();
DateTimeColumn get lastExecution => dateTime().nullable()();
// Audit
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
@override
Set<Column> get primaryKey => {id};
}
/// Таблица UserTasks - задачи пользователей
class UserTasks extends Table {
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
TextColumn get title => text()();
TextColumn get description => text()();
TextColumn get type => text()(); // app_internal, external, social
TextColumn get difficulty => text()(); // easy, medium, hard
TextColumn get status => text()(); // available, in_progress, completed, expired, failed
// Награды (JSON array)
TextColumn get rewards => text()
.withDefault(const Constant('[]'))
.map(const JsonListConverter())();
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
DateTimeColumn get expiresAt => dateTime()();
DateTimeColumn get completedAt => dateTime().nullable()();
TextColumn get proofUrl => text().nullable()();
TextColumn get instructions => text().nullable()();
// Теги (JSON array)
TextColumn get tags => text()
.withDefault(const Constant('[]'))
.map(const StringListConverter())();
TextColumn get imageUrl => text().nullable()();
// Audit
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
@override
Set<Column> get primaryKey => {id};
}
/// Таблица UserTaskProgresses - прогресс выполнения задач пользователями
class UserTaskProgresses extends Table {
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
TextColumn get userId => text().references(Users, #id, onDelete: KeyAction.cascade)();
TextColumn get taskId => text()(); // Reference to UserTasks, but not FK to avoid circular deps
// Прогресс (JSON)
TextColumn get progress => text()
.withDefault(const Constant('{}'))
.map(const JsonMapConverter())();
DateTimeColumn get startedAt => dateTime().withDefault(currentDateAndTime)();
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
@override
Set<Column> get primaryKey => {id};
}
/// Таблица UserTaskResults - результаты выполнения задач
class UserTaskResults extends Table {
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
TextColumn get userId => text().references(Users, #id, onDelete: KeyAction.cascade)();
TextColumn get taskId => text()(); // Reference to UserTasks
// Результаты (JSON)
TextColumn get results => text()
.withDefault(const Constant('{}'))
.map(const JsonMapConverter())();
DateTimeColumn get completedAt => dateTime().withDefault(currentDateAndTime)();
// Audit
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
@override
Set<Column> get primaryKey => {id};
}
// Конвертеры импортированы из converters.dart