mnemo_cards/mnemo_cards_backend/lib/database/tables/auth.dart
Dmitry 550b56276e
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Mobile App CI / test (push) Waiting to run
Mobile App CI / build-android (push) Blocked by required conditions
Mobile App CI / build-ios (push) Blocked by required conditions
Web App CI / test (push) Waiting to run
Web App 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
Deploy Telegram Bot / Deploy Telegram Bot (push) Waiting to run
postgress fix
2025-12-13 23:55:50 +03:00

59 lines
2.1 KiB
Dart

import 'package:drift/drift.dart';
import 'users.dart';
import '../converters.dart' show generateUuid;
/// Таблица Tokens - токены авторизации пользователей
class Tokens extends Table {
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
TextColumn get userId => text().references(Users, #id, onDelete: KeyAction.cascade)();
TextColumn get token => text().unique()();
TextColumn get externalUserId => text()();
DateTimeColumn get created => dateTime().withDefault(currentDateAndTime)();
DateTimeColumn get expires => dateTime()();
@override
Set<Column> get primaryKey => {id};
@override
List<String> get customConstraints => [
'CONSTRAINT valid_expiry CHECK (expires > created)',
];
}
/// Таблица RefreshTokens - refresh токены для JWT
class RefreshTokens extends Table {
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
TextColumn get userId => text().references(Users, #id, onDelete: KeyAction.cascade)();
TextColumn get jti => text().unique()(); // JWT ID
BoolColumn get isBlacklisted => boolean().withDefault(const Constant(false))();
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
DateTimeColumn get expiresAt => dateTime()();
@override
Set<Column> get primaryKey => {id};
}
/// Таблица TelegramAuthCodes - коды для авторизации через Telegram
class TelegramAuthCodes extends Table {
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
TextColumn get code => text().unique()();
TextColumn get telegramUserId => text()();
TextColumn get telegramUsername => text().nullable()();
TextColumn get firstName => text().nullable()();
TextColumn get lastName => text().nullable()();
BoolColumn get isUsed => boolean().withDefault(const Constant(false))();
DateTimeColumn get usedAt => dateTime().nullable()();
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
DateTimeColumn get expiresAt => dateTime()();
@override
Set<Column> get primaryKey => {id};
}