mnemo_cards/mnemo_cards_backend/lib/database/tables/relations.dart
Dmitry 77b4ce91b5
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
postgress
2025-12-13 16:27:05 +03:00

53 lines
2.5 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:drift/drift.dart';
import 'users.dart';
import 'packs.dart' show CardPacks, GameCards, VoiceModels;
/// Junction table для связи Users ↔ CardPacks (многие ко многим)
/// Хранит информацию о том, какие паки куплены пользователем
class UserPacks extends Table {
IntColumn get userId => integer().references(Users, #id, onDelete: KeyAction.cascade)();
IntColumn get packId => integer().references(CardPacks, #id, onDelete: KeyAction.cascade)();
// Когда пользователь получил доступ к паку
DateTimeColumn get grantedAt => dateTime().withDefault(currentDateAndTime)();
// Как пользователь получил пак (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 {
IntColumn get packId => integer().references(CardPacks, #id, onDelete: KeyAction.cascade)();
IntColumn get cardId => integer().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 {
IntColumn get packId => integer().references(CardPacks, #id, onDelete: KeyAction.cascade)();
IntColumn get cardId => integer().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 {
IntColumn get cardId => integer().references(GameCards, #id, onDelete: KeyAction.cascade)();
IntColumn get voiceId => integer().references(VoiceModels, #id, onDelete: KeyAction.cascade)();
@override
Set<Column> get primaryKey => {cardId, voiceId};
}