This commit is contained in:
2026-07-11 17:47:40 +02:00
commit 6587779a58
66 changed files with 7325 additions and 0 deletions
+112
View File
@@ -0,0 +1,112 @@
import 'package:drift/drift.dart';
import 'package:drift_flutter/drift_flutter.dart';
import 'package:path_provider/path_provider.dart';
part 'app_database.g.dart';
@DataClassName('ProductRow')
class Products extends Table {
TextColumn get id => text()();
TextColumn get name => text()();
TextColumn get category => text()();
IntColumn get stockQuantity => integer()();
IntColumn get lowStockThreshold => integer()();
IntColumn get priceInCents => integer()();
TextColumn get imagePath => text().nullable()();
BoolColumn get active => boolean().withDefault(const Constant(true))();
@override
Set<Column> get primaryKey => {id};
}
@DataClassName('BarTabRow')
class BarTabs extends Table {
TextColumn get id => text()();
TextColumn get customerName => text()();
TextColumn get status => text().withDefault(const Constant('open'))();
DateTimeColumn get openedAt => dateTime()();
DateTimeColumn get closedAt => dateTime().nullable()();
@override
Set<Column> get primaryKey => {id};
}
@DataClassName('TabItemRow')
class TabItems extends Table {
TextColumn get id => text()();
TextColumn get tabId => text().references(
BarTabs,
#id,
onDelete: KeyAction.cascade,
)();
TextColumn get productId => text().references(
Products,
#id,
)();
TextColumn get productName => text()();
IntColumn get quantity => integer()();
IntColumn get unitPriceInCents => integer()();
DateTimeColumn get createdAt => dateTime()();
@override
Set<Column> get primaryKey => {id};
}
@DriftDatabase(
tables: [
Products,
BarTabs,
TabItems,
],
)
class AppDatabase extends _$AppDatabase {
AppDatabase([QueryExecutor? executor]) : super(executor ?? _openConnection());
@override
int get schemaVersion => 3;
@override
MigrationStrategy get migration {
return MigrationStrategy(
onCreate: (migrator) async {
await migrator.createAll();
},
onUpgrade: (migrator, from, to) async {
if (from < 2) {
await migrator.createTable(barTabs);
await migrator.createTable(tabItems);
}
if (from < 3) {
await migrator.addColumn(products, products.imagePath);
}
},
);
}
static QueryExecutor _openConnection() {
return driftDatabase(
name: 'kooltab',
native: const DriftNativeOptions(
databaseDirectory: getApplicationSupportDirectory,
),
);
}
}