Jaguar-dart / jaguar_orm

Source-generated ORM with relations (one-to-one, one-to-many, many-to-many), preloading, cascading, polymorphic relations, etc
https://jaguar-dart.github.io
BSD 3-Clause "New" or "Revised" License
217 stars 52 forks source link

Add onUpgrade option #119

Closed jamespet77 closed 5 years ago

jamespet77 commented 5 years ago

It would be nice to have somewhat of an upgrade option for changing db table schema.

possibly change file https://github.com/Jaguar-dart/jaguar_orm/blob/feature/alter_sqflite/sqflite/lib/src/adapter.dart#L25

to:

/// Connects to the database Future connect({onUpgradeDB}) async { if (_connection == null) { _connection = await sqf.openDatabase(path, version: version,onUpgrade: onUpgradeDB); } }

This would open up the possibility to make table changes on startup when a db is upgraded.

tejainece commented 5 years ago

@jaumard

jaumard commented 5 years ago

@linuxjet you already have the FomConnexion https://github.com/Jaguar-dart/jaguar_orm/blob/feature/alter_sqflite/sqflite/lib/src/adapter.dart#L20 where you can pass directly an SQFlite instance, it's better to use that, if we start added onUpgrade, someone will after want onDowngrade and then another field and we'll have to proxy all the fields ^^ The FromConnexion is here if you need more configuration :) what do you think. ?

jamespet77 commented 5 years ago

Not exactly sure where you are headed with that, unless you just assume creating the Sqlite connection first manually and preform the upgrade process then passing the connection to the adapter?

jaumard commented 5 years ago

Yes here is what I use:

final adapter = SqfliteAdapter.fromConnection(await openDatabase(file, version: databaseVersion, onUpgrade: (db, currentVersion, newVersion) async {
      //do what you need on upgrade
    }, onDowngrade: (db, currentVersion, newVersion) async {
                  //do what you need on downgrade
    }, onCreate: (db, version) async {
            //do what you need on create
    }, onOpen: (db) async {
      //do what you need on open
}));
jamespet77 commented 5 years ago

ok. thx