Open rscarson14 opened 8 years ago
This doc on Schema-migrations might help you.
public static boolean createIfNeedColumn(Class<? extends Model> type, String column) {
boolean isFound = false;
TableInfo tableInfo = new TableInfo(type);
Collection<Field> columns = new TableInfo(type).getFields();
for (Field f : columns) {
if (column.equals(f.getName())) {
isFound = true;
break;
}
}
if (!isFound) {
ActiveAndroid.execSQL("ALTER TABLE " + tableInfo.getTableName() + " ADD COLUMN " + column + " TEXT;");
}
return isFound;
}
I apologize if this is not the place for this, I am new to SQLite and ORMs.
I am working to roll out an update for an app and need to migrate my database. Some of the tables have had columns added or removed, etc. In ActiveAndroid, schema migrations are performed by writing a migration script. It's easy for me to understand how to do this when dealing with basic data types, but I am confused how to add columns that are mapped to other objects/classes.
For example, below is an existing Model:
And I am updating it to be:
How do I add this column using the basic
ALTER TABLE GatewayDevice ADD COLUMN controller <type>
structure?