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-20 18:26:15 +00:00
|
|
|
import '../converters.dart'
|
|
|
|
|
show generateUuid, JsonListConverter, JsonMapConverter, StringListConverter;
|
2025-12-13 13:27:05 +00:00
|
|
|
import 'users.dart';
|
|
|
|
|
|
|
|
|
|
/// Таблица Tasks - задачи системы
|
|
|
|
|
class Tasks 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'))();
|
|
|
|
|
|
2025-12-13 13:27:05 +00:00
|
|
|
TextColumn get name => text()();
|
|
|
|
|
IntColumn get minCycleMillis => integer()();
|
|
|
|
|
IntColumn get maxCycleMillis => integer()();
|
|
|
|
|
IntColumn get intervalMillis => integer()();
|
|
|
|
|
IntColumn get timeoutMillis => integer()();
|
2025-12-20 18:26:15 +00:00
|
|
|
|
2025-12-13 13:27:05 +00:00
|
|
|
TextColumn get status => text().nullable()();
|
|
|
|
|
TextColumn get description => text().nullable()();
|
2025-12-20 18:26:15 +00:00
|
|
|
Column<PgDateTime> get lastExecution =>
|
|
|
|
|
customType(PgTypes.timestampWithTimezone).nullable()();
|
|
|
|
|
|
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())();
|
|
|
|
|
|
2025-12-13 20:55:50 +00:00
|
|
|
@override
|
|
|
|
|
Set<Column> get primaryKey => {id};
|
2025-12-13 13:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Таблица UserTasks - задачи пользователей
|
|
|
|
|
class UserTasks 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'))();
|
|
|
|
|
|
2025-12-13 13:27:05 +00:00
|
|
|
TextColumn get title => text()();
|
|
|
|
|
TextColumn get description => text()();
|
2025-12-20 18:26:15 +00:00
|
|
|
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
|
|
|
|
|
|
2025-12-13 13:27:05 +00:00
|
|
|
// Награды (JSON array)
|
2025-12-20 18:26:15 +00:00
|
|
|
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()();
|
|
|
|
|
|
2025-12-13 13:27:05 +00:00
|
|
|
TextColumn get proofUrl => text().nullable()();
|
|
|
|
|
TextColumn get instructions => text().nullable()();
|
2025-12-20 18:26:15 +00:00
|
|
|
|
2025-12-13 13:27:05 +00:00
|
|
|
// Теги (JSON array)
|
|
|
|
|
TextColumn get tags => text()
|
|
|
|
|
.withDefault(const Constant('[]'))
|
|
|
|
|
.map(const StringListConverter())();
|
2025-12-20 18:26:15 +00:00
|
|
|
|
2025-12-13 13:27:05 +00:00
|
|
|
TextColumn get imageUrl => 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 updatedAt =>
|
|
|
|
|
customType(PgTypes.timestampWithTimezone).withDefault(now())();
|
|
|
|
|
|
2025-12-13 20:55:50 +00:00
|
|
|
@override
|
|
|
|
|
Set<Column> get primaryKey => {id};
|
2025-12-13 13:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Таблица UserTaskProgresses - прогресс выполнения задач пользователями
|
|
|
|
|
class UserTaskProgresses 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)();
|
|
|
|
|
TextColumn get taskId =>
|
|
|
|
|
text()(); // Reference to UserTasks, but not FK to avoid circular deps
|
2025-12-13 13:27:05 +00:00
|
|
|
|
|
|
|
|
// Прогресс (JSON)
|
2025-12-20 18:26:15 +00:00
|
|
|
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())();
|
|
|
|
|
|
2025-12-13 20:55:50 +00:00
|
|
|
@override
|
|
|
|
|
Set<Column> get primaryKey => {id};
|
2025-12-13 13:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Таблица UserTaskResults - результаты выполнения задач
|
|
|
|
|
class UserTaskResults 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)();
|
|
|
|
|
TextColumn get taskId => text()(); // Reference to UserTasks
|
|
|
|
|
|
2025-12-13 13:27:05 +00:00
|
|
|
// Результаты (JSON)
|
2025-12-20 18:26:15 +00:00
|
|
|
TextColumn get results =>
|
|
|
|
|
text().withDefault(const Constant('{}')).map(const JsonMapConverter())();
|
|
|
|
|
|
|
|
|
|
Column<PgDateTime> get completedAt =>
|
|
|
|
|
customType(PgTypes.timestampWithTimezone).withDefault(now())();
|
|
|
|
|
|
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())();
|
|
|
|
|
|
2025-12-13 20:55:50 +00:00
|
|
|
@override
|
|
|
|
|
Set<Column> get primaryKey => {id};
|
2025-12-13 13:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Конвертеры импортированы из converters.dart
|