sync page

This commit is contained in:
efrilm
2025-10-24 23:20:41 +07:00
parent 6892895021
commit 79e109cfe4
10 changed files with 669 additions and 63 deletions
+5 -41
View File
@@ -2,6 +2,8 @@ import 'dart:async';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
import '../constant/app_constant.dart';
class DatabaseHelper {
static Database? _database;
@@ -11,11 +13,11 @@ class DatabaseHelper {
}
Future<Database> _initDatabase() async {
String path = join(await getDatabasesPath(), 'db_pos.db');
String path = join(await getDatabasesPath(), AppConstant.dbName);
return await openDatabase(
path,
version: 1, // Updated version for categories table
version: 2, // Updated version for categories table
onCreate: _onCreate,
onUpgrade: _onUpgrade,
);
@@ -106,46 +108,8 @@ class DatabaseHelper {
Future<void> _onUpgrade(Database db, int oldVersion, int newVersion) async {
if (oldVersion < 2) {
// Add printer table in version 2
await db.execute('''
CREATE TABLE printers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
code TEXT UNIQUE NOT NULL,
name TEXT NOT NULL,
address TEXT,
paper TEXT,
type TEXT,
created_at TEXT,
updated_at TEXT
)
''');
await db.execute('CREATE INDEX idx_printers_code ON printers(code)');
await db.execute('CREATE INDEX idx_printers_type ON printers(type)');
}
if (oldVersion < 3) {
// Add categories table in version 3
await db.execute('''
CREATE TABLE categories (
id TEXT PRIMARY KEY,
organization_id TEXT,
name TEXT NOT NULL,
description TEXT,
business_type TEXT,
metadata TEXT,
is_active INTEGER DEFAULT 1,
created_at TEXT,
updated_at TEXT
)
''');
await db.execute('CREATE INDEX idx_categories_name ON categories(name)');
await db.execute(
'CREATE INDEX idx_categories_organization_id ON categories(organization_id)',
);
await db.execute(
'CREATE INDEX idx_categories_is_active ON categories(is_active)',
'ALTER TABLE categories ADD COLUMN "order" INTEGER DEFAULT 0',
);
}
}