sync page
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class AppConstant {
|
||||
static const String appName = "Apskel POS";
|
||||
|
||||
static const String dbName = "apskel_pos.db";
|
||||
static const int cacheExpire = 10; // in minutes
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user