48 lines
2.1 KiB
Dart
48 lines
2.1 KiB
Dart
import 'package:drift/drift.dart';
|
|
|
|
// ── Tables ────────────────────────────────────────────────────────────────────
|
|
|
|
class Accounts extends Table {
|
|
IntColumn get id => integer().autoIncrement()();
|
|
TextColumn get name => text()();
|
|
TextColumn get type => text()(); // checking, savings, credit, cash
|
|
RealColumn get balance => real().withDefault(const Constant(0.0))();
|
|
BoolColumn get isClosed => boolean().withDefault(const Constant(false))();
|
|
IntColumn get sortOrder => integer().withDefault(const Constant(0))();
|
|
}
|
|
|
|
class CategoryGroups extends Table {
|
|
IntColumn get id => integer().autoIncrement()();
|
|
TextColumn get name => text()();
|
|
IntColumn get sortOrder => integer().withDefault(const Constant(0))();
|
|
}
|
|
|
|
class Categories extends Table {
|
|
IntColumn get id => integer().autoIncrement()();
|
|
TextColumn get name => text()();
|
|
IntColumn get groupId => integer().references(CategoryGroups, #id)();
|
|
RealColumn get budgeted => real().withDefault(const Constant(0.0))();
|
|
IntColumn get sortOrder => integer().withDefault(const Constant(0))();
|
|
TextColumn get icon => text().nullable()();
|
|
}
|
|
|
|
class Transactions extends Table {
|
|
IntColumn get id => integer().autoIncrement()();
|
|
IntColumn get accountId => integer().references(Accounts, #id)();
|
|
IntColumn get categoryId => integer().references(Categories, #id).nullable()();
|
|
TextColumn get payee => text()();
|
|
TextColumn get notes => text().nullable()();
|
|
RealColumn get amount => real()(); // positive = income, negative = expense
|
|
DateTimeColumn get date => dateTime()();
|
|
BoolColumn get cleared => boolean().withDefault(const Constant(false))();
|
|
IntColumn get sortOrder => integer().withDefault(const Constant(0))();
|
|
}
|
|
|
|
class Budgets extends Table {
|
|
IntColumn get id => integer().autoIncrement()();
|
|
IntColumn get categoryId => integer().references(Categories, #id)();
|
|
TextColumn get month => text()(); // "2026-07"
|
|
RealColumn get budgeted => real().withDefault(const Constant(0.0))();
|
|
IntColumn get sortOrder => integer().withDefault(const Constant(0))();
|
|
}
|