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
58 lines
2.1 KiB
Dart
58 lines
2.1 KiB
Dart
import 'package:drift/drift.dart';
|
|
import '../converters.dart';
|
|
import 'users.dart';
|
|
|
|
/// Таблица DiscountCampaigns - кампании скидок
|
|
class DiscountCampaigns extends Table {
|
|
IntColumn get id => integer().autoIncrement()();
|
|
|
|
TextColumn get name => text().nullable()();
|
|
|
|
DateTimeColumn get start => dateTime()();
|
|
DateTimeColumn get finish => dateTime()();
|
|
|
|
// Статус (enum as string)
|
|
TextColumn get status => text()(); // created, active, expired, disabled
|
|
|
|
// Теги (JSON array)
|
|
TextColumn get tags => text()
|
|
.withDefault(const Constant('[]'))
|
|
.map(const StringListConverter())();
|
|
|
|
// Audit
|
|
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
|
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
|
BoolColumn get isDeleted => boolean().withDefault(const Constant(false))();
|
|
}
|
|
|
|
/// Таблица Discounts - скидки
|
|
class Discounts extends Table {
|
|
IntColumn get id => integer().autoIncrement()();
|
|
IntColumn get campaignId => integer().references(DiscountCampaigns, #id, onDelete: KeyAction.cascade)();
|
|
|
|
// Процент скидки (0-100)
|
|
RealColumn get discountPercent => real()();
|
|
|
|
// Продукты (JSON array)
|
|
TextColumn get products => text()
|
|
.withDefault(const Constant('[]'))
|
|
.map(const JsonListConverter())();
|
|
|
|
// Audit
|
|
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
|
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
|
BoolColumn get isDeleted => boolean().withDefault(const Constant(false))();
|
|
}
|
|
|
|
/// Junction table для связи Discounts ↔ UserDatas (many-to-many)
|
|
class DiscountUserDatas extends Table {
|
|
IntColumn get discountId => integer().references(Discounts, #id, onDelete: KeyAction.cascade)();
|
|
IntColumn get userId => integer().references(Users, #id, onDelete: KeyAction.cascade)();
|
|
|
|
DateTimeColumn get grantedAt => dateTime().withDefault(currentDateAndTime)();
|
|
|
|
@override
|
|
Set<Column> get primaryKey => {discountId, userId};
|
|
}
|
|
|
|
// Конвертеры импортированы из converters.dart
|