migration partially working:
- upon migration, items appear in stock module - after restart, they are gone - only one item is actually persisted in the DB??? Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -2,4 +2,5 @@ description = "Umbrella : Stock"
|
|||||||
|
|
||||||
dependencies{
|
dependencies{
|
||||||
implementation(project(":core"))
|
implementation(project(":core"))
|
||||||
|
implementation("de.srsoftware:configuration.json:1.0.3")
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String BELOW = "below";
|
public static final String BELOW = "below";
|
||||||
public static final String CONFIG_DATABASE = "umbrella.modules.stock.database";
|
public static final String CONFIG_DATABASE = "umbrella.modules.stock.database";
|
||||||
|
public static final String CONFIG_ITEM_DB = "umbrella.modules.items.database";
|
||||||
public static final String ITEM = "item";
|
public static final String ITEM = "item";
|
||||||
public static final String ITEM_ID = "item_id";
|
public static final String ITEM_ID = "item_id";
|
||||||
public static final String ITEMS = "items";
|
public static final String ITEMS = "items";
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class SqliteDb extends BaseDb implements StockDb {
|
|||||||
if (rs.next()) propertyId = rs.getLong(1);
|
if (rs.next()) propertyId = rs.getLong(1);
|
||||||
rs.close();
|
rs.close();
|
||||||
if (propertyId == null || propertyId == 0) throw databaseException("Failed to create new property {0} in DB",name);
|
if (propertyId == null || propertyId == 0) throw databaseException("Failed to create new property {0} in DB",name);
|
||||||
insertInto(TABLE_ITEM_PROPERTIES,ITEM_ID,PROPERTY_ID,VALUE).values(itemId,propertyId,value).execute(db);
|
insertInto(TABLE_ITEM_PROPERTIES,ITEM_ID,PROPERTY_ID,VALUE).values(itemId,propertyId,value).execute(db).close();
|
||||||
return new Property(propertyId,name,value,unit);
|
return new Property(propertyId,name,value,unit);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw databaseException("Failed to create new property {0} in DB",name);
|
throw databaseException("Failed to create new property {0} in DB",name);
|
||||||
@@ -477,7 +477,7 @@ public class SqliteDb extends BaseDb implements StockDb {
|
|||||||
if ("".equals(value)){
|
if ("".equals(value)){
|
||||||
Query.delete().from(TABLE_ITEM_PROPERTIES).where(ITEM_ID,equal(itemId)).where(PROPERTY_ID,equal(existingPropId)).execute(db);
|
Query.delete().from(TABLE_ITEM_PROPERTIES).where(ITEM_ID,equal(itemId)).where(PROPERTY_ID,equal(existingPropId)).execute(db);
|
||||||
} else {
|
} else {
|
||||||
replaceInto(TABLE_ITEM_PROPERTIES,ITEM_ID,PROPERTY_ID,VALUE).values(itemId,existingPropId,value).execute(db);
|
replaceInto(TABLE_ITEM_PROPERTIES,ITEM_ID,PROPERTY_ID,VALUE).values(itemId,existingPropId,value).execute(db).close();
|
||||||
}
|
}
|
||||||
return prop.value(value);
|
return prop.value(value);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import static java.util.Comparator.comparing;
|
|||||||
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
import de.srsoftware.configuration.Configuration;
|
import de.srsoftware.configuration.Configuration;
|
||||||
|
import de.srsoftware.configuration.JsonConfig;
|
||||||
import de.srsoftware.tools.Path;
|
import de.srsoftware.tools.Path;
|
||||||
import de.srsoftware.tools.SessionToken;
|
import de.srsoftware.tools.SessionToken;
|
||||||
import de.srsoftware.umbrella.core.BaseHandler;
|
import de.srsoftware.umbrella.core.BaseHandler;
|
||||||
@@ -38,8 +39,16 @@ public class StockModule extends BaseHandler implements StockService {
|
|||||||
super();
|
super();
|
||||||
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
||||||
stockDb = new SqliteDb(connect(dbFile));
|
stockDb = new SqliteDb(connect(dbFile));
|
||||||
Optional<String> itemDbConfig = config.get("umbrella.modules.items.database");
|
Optional<String> itemDbConfig = config.get(CONFIG_ITEM_DB);
|
||||||
itemDbConfig.map(ItemDb::new).ifPresent(itemDb -> itemDb.migrateTo(stockDb));
|
itemDbConfig.map(ItemDb::new).ifPresent(itemDb -> itemDb.migrateTo(stockDb));
|
||||||
|
if (itemDbConfig.isPresent()){
|
||||||
|
try {
|
||||||
|
config.drop(CONFIG_ITEM_DB);
|
||||||
|
if (config instanceof JsonConfig jsonConfig) jsonConfig.save();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
ModuleRegistry.add(this);
|
ModuleRegistry.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user