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
54 lines
2.5 KiB
Dart
54 lines
2.5 KiB
Dart
import 'package:drift/drift.dart';
|
||
import '../postgres_constants.dart';
|
||
import 'users.dart';
|
||
import 'packs.dart' show CardPacks, GameCards, VoiceModels;
|
||
|
||
/// Junction table для связи Users ↔ CardPacks (многие ко многим)
|
||
/// Хранит информацию о том, какие паки куплены пользователем
|
||
class UserPacks extends Table {
|
||
TextColumn get userId => text().references(Users, #id, onDelete: KeyAction.cascade)();
|
||
TextColumn get packId => text().references(CardPacks, #id, onDelete: KeyAction.cascade)();
|
||
|
||
// Когда пользователь получил доступ к паку
|
||
DateTimeColumn get grantedAt => dateTime().withDefault(currentTimestamp)();
|
||
|
||
// Как пользователь получил пак (purchase, promo, free, admin)
|
||
TextColumn get grantType => text().withDefault(const Constant('purchase'))();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {userId, packId};
|
||
}
|
||
|
||
/// Таблица PreviewCards - связь CardPacks с preview карточками
|
||
/// Хранит какие карточки показывать в превью пака
|
||
class PreviewCards extends Table {
|
||
TextColumn get packId => text().references(CardPacks, #id, onDelete: KeyAction.cascade)();
|
||
TextColumn get cardId => text().references(GameCards, #id, onDelete: KeyAction.cascade)();
|
||
|
||
IntColumn get order => integer().withDefault(const Constant(0))();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {packId, cardId};
|
||
}
|
||
|
||
/// Таблица CardPackCards - связь CardPacks с GameCards (many-to-many)
|
||
/// Хранит какие карточки принадлежат какому паку
|
||
class CardPackCards extends Table {
|
||
TextColumn get packId => text().references(CardPacks, #id, onDelete: KeyAction.cascade)();
|
||
TextColumn get cardId => text().references(GameCards, #id, onDelete: KeyAction.cascade)();
|
||
|
||
IntColumn get order => integer().withDefault(const Constant(0))();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {packId, cardId};
|
||
}
|
||
|
||
/// Таблица CardVoices - связь GameCards с VoiceModels (many-to-many)
|
||
/// Хранит какие голосовые файлы принадлежат какой карточке
|
||
class CardVoices extends Table {
|
||
TextColumn get cardId => text().references(GameCards, #id, onDelete: KeyAction.cascade)();
|
||
TextColumn get voiceId => text().references(VoiceModels, #id, onDelete: KeyAction.cascade)();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {cardId, voiceId};
|
||
}
|