category local

This commit is contained in:
efrilm
2025-09-20 04:36:22 +07:00
parent c12d6525fa
commit 5b980d237f
12 changed files with 3443 additions and 515 deletions
+45 -3
View File
@@ -23,7 +23,7 @@ class DatabaseHelper {
return await openDatabase(
path,
version: 2, // Updated version for printer table
version: 3, // Updated version for categories table
onCreate: _onCreate,
onUpgrade: _onUpgrade,
);
@@ -66,7 +66,22 @@ class DatabaseHelper {
)
''');
// Printer table - NEW
// Categories table - NEW
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
)
''');
// Printer table
await db.execute('''
CREATE TABLE printers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -85,6 +100,11 @@ class DatabaseHelper {
'CREATE INDEX idx_products_category_id ON products(category_id)');
await db.execute('CREATE INDEX idx_products_name ON products(name)');
await db.execute('CREATE INDEX idx_products_sku ON products(sku)');
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)');
await db.execute('CREATE INDEX idx_printers_code ON printers(code)');
await db.execute('CREATE INDEX idx_printers_type ON printers(type)');
}
@@ -105,10 +125,32 @@ class DatabaseHelper {
)
''');
// Add indexes for printer table
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)');
}
}
Future<void> close() async {