mnemo_cards/mnemo_cards_backend/lib/database/tables/relations.dart
Dmitry 1ab5071345
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Admin Panel / Deploy Admin Panel (push) Waiting to run
Deploy Admin Panel / Admin Panel Verification (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
f
2025-12-14 02:35:14 +03:00

63 lines
2.6 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 'package:drift_postgres/drift_postgres.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)();
// Когда пользователь получил доступ к паку
Column<PgDateTime> get grantedAt => customType(PgTypes.timestampWithTimezone)
.withDefault(now())();
// Как пользователь получил пак (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};
}