Corrige esquema DB: agrega es_recurrente en CREATE TABLE y migración a v3

This commit is contained in:
Super User
2026-06-17 20:10:24 -04:00
parent fa5bf380b8
commit 9553461f44

View File

@@ -19,7 +19,7 @@ class DatabaseHelper {
Future<Database> _initDB(String filePath) async { Future<Database> _initDB(String filePath) async {
final dbPath = await getDatabasesPath(); final dbPath = await getDatabasesPath();
final path = join(dbPath, filePath); final path = join(dbPath, filePath);
return await openDatabase(path, version: 2, onCreate: _createDB, onUpgrade: _upgradeDB, onConfigure: _onConfigure); return await openDatabase(path, version: 3, onCreate: _createDB, onUpgrade: _upgradeDB, onConfigure: _onConfigure);
} }
Future _onConfigure(Database db) async { Future _onConfigure(Database db) async {
@@ -27,9 +27,11 @@ class DatabaseHelper {
} }
Future _upgradeDB(Database db, int oldVersion, int newVersion) async { Future _upgradeDB(Database db, int oldVersion, int newVersion) async {
if (oldVersion < 2) { if (oldVersion < 3) {
try {
await db.execute( await db.execute(
"ALTER TABLE servicios ADD COLUMN es_recurrente INTEGER NOT NULL DEFAULT 0"); "ALTER TABLE servicios ADD COLUMN es_recurrente INTEGER NOT NULL DEFAULT 0");
} catch (_) {}
} }
} }
@@ -41,7 +43,8 @@ class DatabaseHelper {
icono TEXT NOT NULL, icono TEXT NOT NULL,
color INTEGER NOT NULL, color INTEGER NOT NULL,
dia_vencimiento INTEGER NOT NULL, dia_vencimiento INTEGER NOT NULL,
fecha_creacion TEXT NOT NULL fecha_creacion TEXT NOT NULL,
es_recurrente INTEGER NOT NULL DEFAULT 0
) )
'''); ''');
await db.execute(''' await db.execute('''