diff options
Diffstat (limited to 'src/site/table_versioning.mkd')
-rw-r--r-- | src/site/table_versioning.mkd | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/site/table_versioning.mkd b/src/site/table_versioning.mkd index 2e95aaa..480dd22 100644 --- a/src/site/table_versioning.mkd +++ b/src/site/table_versioning.mkd @@ -26,4 +26,34 @@ both of which allow for non-linear upgrades. If the upgrade method call is succ The actual upgrade procedure is beyond the scope of iciql and is your responsibility to implement. This is simply a mechanism to automatically identify when an upgrade is necessary.
**NOTE:**<br/>
-The database entry of the *iq_versions* table is specified as SCHEMANAME='' and TABLENAME=''.
\ No newline at end of file +The database entry of the *iq_versions* table is specified as SCHEMANAME='' and TABLENAME=''.
+
+### Effective use of Versioning with a DAO
+
+When Iciql identifies that a version upgrade is necessary it will call the appropriate method and give you a `Db` instance. With the `Db` instance you may open a version-specific [DAO](dao.html) instance that could give you a clean way to define all your upgrade commands.
+
+---JAVA---
+public interface V2Upgrade extends Dao {
+
+ @SqlStatement("ALTER TABLE PRODUCT ADD COLUMN TEST INT DEFAULT 0")
+ void updateProductTable();
+
+ @SqlStatement("UPDATE PRODUCT SET CATEGORY = :new WHERE CATEGORY = :old"")
+ void renameCategory(@Bind("old") String oldName, @Bind("new") String newName);
+}
+
+public class MyUpgrader implements DbUpgrader {
+
+ public boolean upgradeDatabase(Db db, int fromVersion, int toVersion) {
+
+ if (2 == toVersion) {
+ V2Upgrade dao = db.open(V2Upgrade.class);
+ dao.updateProductTable();
+ dao.renameCategory("Condiments", "Dressings");
+ return true;
+ }
+
+ return false;
+ }
+
+---JAVA---
\ No newline at end of file |