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-13 20:55:50 +00:00
|
|
|
import '../converters.dart' show generateUuid, IntListConverter, StringListConverter;
|
2025-12-13 13:27:05 +00:00
|
|
|
|
|
|
|
|
/// Таблица CardPacks - наборы карточек
|
|
|
|
|
class CardPacks extends Table {
|
2025-12-13 23:35:14 +00:00
|
|
|
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
|
|
|
|
|
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 subtitle => text()();
|
|
|
|
|
TextColumn get description => text().nullable()();
|
|
|
|
|
|
|
|
|
|
// Визуальное оформление
|
|
|
|
|
TextColumn get color => text().nullable()();
|
|
|
|
|
TextColumn get cover => text().nullable()(); // URL обложки
|
|
|
|
|
|
|
|
|
|
// Параметры
|
|
|
|
|
IntColumn get size => integer()(); // количество карточек
|
|
|
|
|
TextColumn get version => text().nullable()();
|
|
|
|
|
IntColumn get order => integer().withDefault(const Constant(0))();
|
2025-12-13 22:00:36 +00:00
|
|
|
BoolColumn get enabled => boolean()
|
|
|
|
|
.withDefault(const Constant(true))
|
2025-12-13 23:35:14 +00:00
|
|
|
.customConstraint('')(); // PostgreSQL использует нативный BOOLEAN
|
2025-12-13 13:27:05 +00:00
|
|
|
|
|
|
|
|
// Порядок карточек (JSON array of IDs)
|
|
|
|
|
TextColumn get cardsOrder => text()
|
|
|
|
|
.withDefault(const Constant('[]'))
|
2025-12-13 20:55:50 +00:00
|
|
|
.map(const StringListConverter())();
|
2025-12-13 13:27:05 +00:00
|
|
|
|
|
|
|
|
// Store IDs для покупок
|
|
|
|
|
TextColumn get googlePlayId => text().nullable()();
|
|
|
|
|
TextColumn get rustoreId => text().nullable()();
|
|
|
|
|
TextColumn get appStoreId => text().nullable()();
|
|
|
|
|
|
|
|
|
|
// Цена
|
|
|
|
|
TextColumn get price => text().nullable()();
|
|
|
|
|
TextColumn get currency => text().withDefault(const Constant('RUB'))();
|
|
|
|
|
|
|
|
|
|
// Audit
|
2025-12-13 23:35:14 +00:00
|
|
|
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
|
|
|
|
|
.withDefault(now())();
|
|
|
|
|
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
|
|
|
|
|
.withDefault(now())();
|
2025-12-13 22:00:36 +00:00
|
|
|
BoolColumn get isDeleted => boolean()
|
|
|
|
|
.withDefault(const Constant(false))
|
2025-12-13 23:35:14 +00:00
|
|
|
.customConstraint('')(); // PostgreSQL использует нативный BOOLEAN
|
2025-12-13 20:55:50 +00:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Set<Column> get primaryKey => {id};
|
2025-12-13 13:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Таблица GameCards - карточки для изучения
|
|
|
|
|
class GameCards extends Table {
|
2025-12-13 23:35:14 +00:00
|
|
|
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
|
|
|
|
|
TextColumn get id => text()
|
|
|
|
|
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
|
|
|
|
|
TextColumn get packId => text()
|
|
|
|
|
.references(CardPacks, #id, onDelete: KeyAction.cascade)();
|
2025-12-13 13:27:05 +00:00
|
|
|
|
|
|
|
|
// Основной контент
|
|
|
|
|
TextColumn get original => text()(); // слово на иностранном языке
|
|
|
|
|
TextColumn get translation => text()(); // перевод
|
|
|
|
|
TextColumn get mnemo => text().nullable()(); // мнемоническая подсказка
|
|
|
|
|
|
|
|
|
|
// Изображения
|
|
|
|
|
TextColumn get image => text()(); // основное изображение
|
|
|
|
|
TextColumn get imageBack => text().nullable()(); // изображение на обратной стороне
|
|
|
|
|
|
|
|
|
|
// Произношение
|
|
|
|
|
TextColumn get transcription => text().nullable()();
|
|
|
|
|
TextColumn get transcriptionMnemo => text().nullable()();
|
|
|
|
|
|
|
|
|
|
// Дополнительная информация
|
|
|
|
|
TextColumn get back => text().nullable()(); // дополнительный текст
|
|
|
|
|
|
|
|
|
|
// Audit
|
2025-12-13 23:35:14 +00:00
|
|
|
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
|
|
|
|
|
.withDefault(now())();
|
|
|
|
|
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
|
|
|
|
|
.withDefault(now())();
|
2025-12-13 22:00:36 +00:00
|
|
|
BoolColumn get isDeleted => boolean()
|
|
|
|
|
.withDefault(const Constant(false))
|
2025-12-13 23:35:14 +00:00
|
|
|
.customConstraint('')(); // PostgreSQL использует нативный BOOLEAN
|
2025-12-13 20:55:50 +00:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Set<Column> get primaryKey => {id};
|
2025-12-13 13:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Таблица VoiceModels - голосовые файлы для карточек
|
|
|
|
|
class VoiceModels extends Table {
|
2025-12-13 23:35:14 +00:00
|
|
|
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
|
|
|
|
|
TextColumn get id => text()
|
|
|
|
|
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
|
|
|
|
|
TextColumn get cardId => text()
|
|
|
|
|
.references(GameCards, #id, onDelete: KeyAction.cascade)();
|
2025-12-13 13:27:05 +00:00
|
|
|
|
|
|
|
|
TextColumn get voiceUrl => text()(); // URL аудиофайла
|
|
|
|
|
TextColumn get language => text()(); // язык озвучки
|
|
|
|
|
|
2025-12-13 23:35:14 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IntListConverter импортирован из converters.dart
|