简体   繁体   中英

Is there a mechanism to upgrade/create database on a Ubuntu .deb package?

For example, android platform has something like:

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
    db.execSQL("DROP TABLE ....");
    db.execSQL("ATER TABLE ....");
    onCreate(db);
}

Which is very good to handle upgrades, etc.

Is there a similar strategy for .deb packages? I know I can use the debian/control, debian/preinst to get current version, debian/postinst to handle then the database upgrade, but it's not as neat of a solution.

Nope, there isn't. It doesn't need to be much less clean, though. Your postinst just needs to have something like

case "$1" in
    configure)
        oldver=$2
        if dpkg --compare-versions "$oldver" -lt 1.2.3; then
            sqlite3 mydb.db 'DROP TABLE W...'
            sqlite3 mydb.db 'ALTER TABLE X...'
        fi
        if dpkg --compare-versions "$oldver" -lt 1.3.4; then
            sqlite3 mydb.db 'DROP TABLE Y...'
            sqlite3 mydb.db 'ALTER TABLE Z...'
        fi
    ;;
...
esac

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM