@@ -2,7 +2,12 @@ import 'package:drift/drift.dart';
22import 'package:drift_flutter/drift_flutter.dart' ;
33import 'package:path/path.dart' as path;
44
5- import '../../utilities/stack_file_system.dart' ;
5+ import '../../../models/shopinbit/shopinbit_order_model.dart'
6+ show ShopInBitCategory, ShopInBitOrderStatus;
7+ import '../../../utilities/stack_file_system.dart' ;
8+ import 'tables/cakepay_orders.dart' ;
9+ import 'tables/shopin_bit_settings.dart' ;
10+ import 'tables/shopin_bit_tickets.dart' ;
611
712part 'shared_database.g.dart' ;
813
@@ -21,25 +26,39 @@ abstract final class SharedDrift {
2126 }
2227}
2328
24- class CakepayOrders extends Table {
25- TextColumn get orderId => text ()();
29+ @DriftDatabase (
30+ tables: [CakepayOrders , ShopinBitSettings , ShopInBitTickets ],
31+ daos: [ShopinBitSettingsDao ],
32+ )
33+ final class SharedDatabase extends _$SharedDatabase {
34+ SharedDatabase ._([QueryExecutor ? executor])
35+ : super (executor ?? _openConnection ());
2636
2737 @override
28- Set <Column > get primaryKey => {orderId};
29- }
30-
31- class ShopinBitSettings extends Table {
32- // Single row table - always row 0
33- IntColumn get id => integer ().withDefault (const Constant (0 ))();
34-
35- BoolColumn get guidelinesAccepted =>
36- boolean ().withDefault (const Constant (false ))();
37- BoolColumn get setupComplete =>
38- boolean ().withDefault (const Constant (false ))();
39- TextColumn get displayName => text ().nullable ()();
38+ int get schemaVersion => 2 ;
4039
4140 @override
42- Set <Column > get primaryKey => {id};
41+ MigrationStrategy get migration => MigrationStrategy (
42+ onUpgrade: (m, from, to) async {
43+ if (from == 1 && to == 2 ) {
44+ await m.createTable (shopinBitSettings);
45+ await m.createTable (shopInBitTickets);
46+ }
47+ },
48+ );
49+
50+ static QueryExecutor _openConnection () {
51+ return driftDatabase (
52+ name: "shared" ,
53+ native : DriftNativeOptions (
54+ shareAcrossIsolates: true ,
55+ databasePath: () async {
56+ final dir = await StackFileSystem .applicationDriftDirectory ();
57+ return path.join (dir.path, "shared" , "shared.db" );
58+ },
59+ ),
60+ );
61+ }
4362}
4463
4564@DriftAccessor (tables: [ShopinBitSettings ])
@@ -74,37 +93,3 @@ class ShopinBitSettingsDao extends DatabaseAccessor<SharedDatabase>
7493 )..where ((t) => t.id.equals (0 ))).write (changes);
7594 }
7695}
77-
78- @DriftDatabase (
79- tables: [CakepayOrders , ShopinBitSettings ],
80- daos: [ShopinBitSettingsDao ],
81- )
82- final class SharedDatabase extends _$SharedDatabase {
83- SharedDatabase ._([QueryExecutor ? executor])
84- : super (executor ?? _openConnection ());
85-
86- @override
87- int get schemaVersion => 2 ;
88-
89- @override
90- MigrationStrategy get migration => MigrationStrategy (
91- onUpgrade: (m, from, to) async {
92- if (from == 1 && to == 2 ) {
93- await m.createTable (shopinBitSettings);
94- }
95- },
96- );
97-
98- static QueryExecutor _openConnection () {
99- return driftDatabase (
100- name: "shared" ,
101- native : DriftNativeOptions (
102- shareAcrossIsolates: true ,
103- databasePath: () async {
104- final dir = await StackFileSystem .applicationDriftDirectory ();
105- return path.join (dir.path, "shared" , "shared.db" );
106- },
107- ),
108- );
109- }
110- }
0 commit comments