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
85 lines
3.2 KiB
Dart
85 lines
3.2 KiB
Dart
import 'package:drift/drift.dart';
|
||
import '../converters.dart';
|
||
import '../postgres_constants.dart';
|
||
|
||
/// Таблица Users - основная информация о пользователях
|
||
class Users extends Table {
|
||
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
|
||
TextColumn get externalUserId => text().unique()();
|
||
TextColumn get name => text().nullable()();
|
||
TextColumn get email => text().nullable()();
|
||
BoolColumn get admin => boolean().withDefault(const Constant(false))();
|
||
|
||
// UserSettings (JSON)
|
||
TextColumn get userSettings => text().nullable()();
|
||
|
||
// Purchases (JSON array)
|
||
TextColumn get purchases => text()
|
||
.withDefault(const Constant('[]'))
|
||
.map(const StringListConverter())();
|
||
|
||
// Audit fields
|
||
DateTimeColumn get createdAt => dateTime().withDefault(currentTimestamp)();
|
||
DateTimeColumn get updatedAt => dateTime().withDefault(currentTimestamp)();
|
||
BoolColumn get isDeleted => boolean().withDefault(const Constant(false))();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {id};
|
||
|
||
@override
|
||
List<String> get customConstraints => [
|
||
'CONSTRAINT valid_email CHECK (email IS NULL OR email LIKE \'%@%\')',
|
||
];
|
||
}
|
||
|
||
/// Таблица UserDatas - расширенная информация о пользователе
|
||
class UserDatas extends Table {
|
||
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
|
||
TextColumn get userId => text().unique().references(Users, #id, onDelete: KeyAction.cascade)();
|
||
|
||
// Статистика
|
||
IntColumn get totalStudyTimeMinutes => integer().withDefault(const Constant(0))();
|
||
IntColumn get currentStreak => integer().withDefault(const Constant(0))();
|
||
IntColumn get longestStreak => integer().withDefault(const Constant(0))();
|
||
IntColumn get totalCards => integer().withDefault(const Constant(0))();
|
||
IntColumn get totalTests => integer().withDefault(const Constant(0))();
|
||
|
||
// Временные метки
|
||
DateTimeColumn get lastTimeOnline => dateTime().nullable()();
|
||
DateTimeColumn get registrationDate => dateTime().withDefault(currentTimestamp)();
|
||
TextColumn get lastTestSessionToken => text().nullable()();
|
||
|
||
// Сложные структуры (JSON)
|
||
TextColumn get words => text()
|
||
.withDefault(const Constant('[]'))
|
||
.map(const JsonListConverter())();
|
||
|
||
TextColumn get tags => text()
|
||
.withDefault(const Constant('[]'))
|
||
.map(const StringListConverter())();
|
||
|
||
TextColumn get packProgress => text()
|
||
.withDefault(const Constant('[]'))
|
||
.map(const JsonListConverter())();
|
||
|
||
TextColumn get studyDates => text()
|
||
.withDefault(const Constant('[]'))
|
||
.map(const DateTimeListConverter())();
|
||
|
||
TextColumn get achievements => text()
|
||
.withDefault(const Constant('[]'))
|
||
.map(const JsonListConverter())();
|
||
|
||
TextColumn get categoryMinutes => text()
|
||
.withDefault(const Constant('{}'))
|
||
.map(const JsonMapConverter())();
|
||
|
||
// Audit
|
||
DateTimeColumn get createdAt => dateTime().withDefault(currentTimestamp)();
|
||
DateTimeColumn get updatedAt => dateTime().withDefault(currentTimestamp)();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {id};
|
||
}
|
||
|
||
// Конвертеры импортированы из converters.dart
|