lib: Implement versioning in the database and provide upgrade function.