mnemo_cards/mnemo_cards_backend/lib/database/tables/tasks.dart
Dmitry 0f49280805
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
fixes and format
2025-12-20 21:26:15 +03:00

123 lines
4.7 KiB
Dart

import 'package:drift/drift.dart';
import 'package:drift_postgres/drift_postgres.dart';
import '../converters.dart'
show generateUuid, JsonListConverter, JsonMapConverter, StringListConverter;
import 'users.dart';
/// Таблица Tasks - задачи системы
class Tasks extends Table {
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
TextColumn get id =>
text().withDefault(const CustomExpression('gen_random_uuid()::text'))();
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()();
Column<PgDateTime> get lastExecution =>
customType(PgTypes.timestampWithTimezone).nullable()();
// 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};
}
/// Таблица UserTasks - задачи пользователей
class UserTasks extends Table {
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
TextColumn get id =>
text().withDefault(const CustomExpression('gen_random_uuid()::text'))();
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())();
Column<PgDateTime> get createdAt =>
customType(PgTypes.timestampWithTimezone).withDefault(now())();
Column<PgDateTime> get expiresAt =>
customType(PgTypes.timestampWithTimezone)();
Column<PgDateTime> get completedAt =>
customType(PgTypes.timestampWithTimezone).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
Column<PgDateTime> get updatedAt =>
customType(PgTypes.timestampWithTimezone).withDefault(now())();
@override
Set<Column> get primaryKey => {id};
}
/// Таблица UserTaskProgresses - прогресс выполнения задач пользователями
class UserTaskProgresses extends Table {
// 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)();
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())();
Column<PgDateTime> get startedAt =>
customType(PgTypes.timestampWithTimezone).withDefault(now())();
Column<PgDateTime> get updatedAt =>
customType(PgTypes.timestampWithTimezone).withDefault(now())();
@override
Set<Column> get primaryKey => {id};
}
/// Таблица UserTaskResults - результаты выполнения задач
class UserTaskResults extends Table {
// 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)();
TextColumn get taskId => text()(); // Reference to UserTasks
// Результаты (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())();
@override
Set<Column> get primaryKey => {id};
}
// Конвертеры импортированы из converters.dart