[New] Added updated to version
This commit is contained in:
parent
c64fdf81d7
commit
7084467104
|
@ -81,7 +81,7 @@ public abstract class CachedElementMap<T extends StrolchRootElement> extends Tra
|
|||
element.setVersion(getBy(tx, element.getType(), element.getId(), true).getVersion());
|
||||
Version.updateVersionFor(element, tx.getCertificate().getUsername(), deleted);
|
||||
} else {
|
||||
Version.setInitialVersionFor(element, -1, tx.getCertificate().getUsername());
|
||||
Version.updateVersionFor(element, 0, tx.getCertificate().getUsername(), deleted);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -287,6 +287,8 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
|
|||
|
||||
byType.put(element.getId(), element);
|
||||
|
||||
Version.updateVersionFor(element, 0, tx.getCertificate().getUsername(), false);
|
||||
|
||||
// now make read only
|
||||
element.setReadOnly();
|
||||
}
|
||||
|
@ -320,6 +322,8 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
|
|||
|
||||
byType.put(element.getId(), element);
|
||||
|
||||
Version.updateVersionFor(element, 0, tx.getCertificate().getUsername(), false);
|
||||
|
||||
// now make read only
|
||||
element.setReadOnly();
|
||||
}
|
||||
|
|
|
@ -52,7 +52,8 @@ public class Tags {
|
|||
public static final String POLICY = "Policy";
|
||||
|
||||
public static final String VERSION = "Version";
|
||||
public static final String CREATED_AT = "CreatedAt";
|
||||
public static final String CREATED = "Created";
|
||||
public static final String UPDATED = "Updated";
|
||||
public static final String CREATED_BY = "CreatedBy";
|
||||
public static final String DELETED = "Deleted";
|
||||
|
||||
|
@ -119,7 +120,8 @@ public class Tags {
|
|||
public static final String POLICIES = "policies";
|
||||
|
||||
public static final String VERSION = "version";
|
||||
public static final String CREATED_AT = "createdAt";
|
||||
public static final String CREATED = "created";
|
||||
public static final String UPDATED = "updated";
|
||||
public static final String CREATED_BY = "createdBy";
|
||||
public static final String DELETED = "deleted";
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ public class Version {
|
|||
private final Locator locator;
|
||||
private final int version;
|
||||
private final String createdBy;
|
||||
private final Date createdAt;
|
||||
private final Date created;
|
||||
private final Date updated;
|
||||
private final boolean deleted;
|
||||
|
||||
/**
|
||||
|
@ -40,11 +41,11 @@ public class Version {
|
|||
*
|
||||
* @param version
|
||||
* the integer version which must be >= 0 and should be incremented for each new version of an object
|
||||
* @param createdBy
|
||||
* @param created
|
||||
* the username of the creator of this object
|
||||
*/
|
||||
public Version(Locator locator, int version, String createdBy, boolean deleted) {
|
||||
this(locator, version, createdBy, new Date(), deleted);
|
||||
public Version(Locator locator, int version, String created, boolean deleted) {
|
||||
this(locator, version, created, new Date(), new Date(), deleted);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,18 +55,21 @@ public class Version {
|
|||
* the integer version which must be >= 0 and should be incremented for each new version of an object
|
||||
* @param createdBy
|
||||
* the username of the creator of this object
|
||||
* @param createdAt
|
||||
* @param created
|
||||
* date when the version was created
|
||||
* @param updated
|
||||
* date when the version was updated
|
||||
*/
|
||||
public Version(Locator locator, int version, String createdBy, Date createdAt, boolean deleted) {
|
||||
public Version(Locator locator, int version, String createdBy, Date created, Date updated, boolean deleted) {
|
||||
DBC.PRE.assertTrue("Version must by >= 0", version >= 0);
|
||||
DBC.PRE.assertNotNull("locator must be set!", locator);
|
||||
DBC.PRE.assertNotNull("createdBy must be set!", createdBy);
|
||||
DBC.PRE.assertNotNull("createdAt must be set!", createdAt);
|
||||
DBC.PRE.assertNotNull("createdAt must be set!", created);
|
||||
this.locator = locator;
|
||||
this.version = version;
|
||||
this.createdBy = createdBy;
|
||||
this.createdAt = createdAt;
|
||||
this.created = created;
|
||||
this.updated = updated;
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
|
@ -129,8 +133,17 @@ public class Version {
|
|||
*
|
||||
* @return the date when this version was created
|
||||
*/
|
||||
public Date getCreatedAt() {
|
||||
return this.createdAt;
|
||||
public Date getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date when this version was update
|
||||
*
|
||||
* @return the date when this version was update
|
||||
*/
|
||||
public Date getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,8 +187,10 @@ public class Version {
|
|||
builder.append(this.locator);
|
||||
builder.append(", createdBy=");
|
||||
builder.append(this.createdBy);
|
||||
builder.append(", createdAt=");
|
||||
builder.append(ISO8601FormatFactory.getInstance().formatDate(this.createdAt));
|
||||
builder.append(", created=");
|
||||
builder.append(ISO8601FormatFactory.getInstance().formatDate(this.created));
|
||||
builder.append(", updated=");
|
||||
builder.append(ISO8601FormatFactory.getInstance().formatDate(this.updated));
|
||||
builder.append(", deleted=");
|
||||
builder.append(this.deleted);
|
||||
builder.append("]");
|
||||
|
@ -224,11 +239,43 @@ public class Version {
|
|||
* if true, then the version will be marked as deleted, i.e. this object was removed from the element maps
|
||||
*/
|
||||
public static void updateVersionFor(StrolchRootElement element, String username, boolean deleted) {
|
||||
int v = !element.hasVersion() ? 0 : element.getVersion().getVersion() + 1;
|
||||
Version version = new Version(element.getLocator(), v, username, deleted);
|
||||
Version version;
|
||||
if (element.hasVersion()) {
|
||||
int v = element.getVersion().getVersion() + 1;
|
||||
Date created = element.getVersion().getCreated();
|
||||
version = new Version(element.getLocator(), v, username, created, new Date(), deleted);
|
||||
} else {
|
||||
version = new Version(element.getLocator(), 0, username, deleted);
|
||||
}
|
||||
|
||||
element.setVersion(version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new version on the given element. If the element has no version yet, then the result will be version 0,
|
||||
* otherwise the version will be an increment to the current version
|
||||
*
|
||||
* @param element
|
||||
* the element for which to create a new version
|
||||
* @param username
|
||||
* the username of the user who created this version of the object
|
||||
* @param version
|
||||
* the version to use
|
||||
* @param deleted
|
||||
* if true, then the version will be marked as deleted, i.e. this object was removed from the element maps
|
||||
*/
|
||||
public static void updateVersionFor(StrolchRootElement element, int version, String username, boolean deleted) {
|
||||
Version v;
|
||||
if (element.hasVersion()) {
|
||||
Date created = element.getVersion().getCreated();
|
||||
v = new Version(element.getLocator(), version, username, created, new Date(), deleted);
|
||||
} else {
|
||||
v = new Version(element.getLocator(), version, username, deleted);
|
||||
}
|
||||
|
||||
element.setVersion(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
|
|
@ -381,11 +381,25 @@ public class StrolchElementFromJsonVisitor {
|
|||
|
||||
int v = versionJ.get(Json.VERSION).getAsInt();
|
||||
String createdBy = versionJ.get(Json.CREATED_BY).getAsString();
|
||||
String createdAtS = versionJ.get(Json.CREATED_AT).getAsString();
|
||||
Date createdAt = ISO8601FormatFactory.getInstance().parseDate(createdAtS);
|
||||
|
||||
String createdS;
|
||||
if (versionJ.has("createdAt"))
|
||||
createdS = versionJ.get("createdAt").getAsString();
|
||||
else
|
||||
createdS = versionJ.get(Json.CREATED).getAsString();
|
||||
Date created = ISO8601FormatFactory.getInstance().parseDate(createdS);
|
||||
|
||||
Date updated;
|
||||
if (versionJ.has(Json.UPDATED)) {
|
||||
String updatedS = versionJ.get(Json.UPDATED).getAsString();
|
||||
updated = ISO8601FormatFactory.getInstance().parseDate(updatedS);
|
||||
} else {
|
||||
updated = created;
|
||||
}
|
||||
|
||||
boolean deleted = versionJ.get(Json.DELETED).getAsBoolean();
|
||||
|
||||
Version version = new Version(rootElement.getLocator(), v, createdBy, createdAt, deleted);
|
||||
Version version = new Version(rootElement.getLocator(), v, createdBy, created, updated, deleted);
|
||||
rootElement.setVersion(version);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -653,7 +653,8 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor<JsonEl
|
|||
JsonObject versionJ = new JsonObject();
|
||||
versionJ.addProperty(Json.VERSION, version.getVersion());
|
||||
versionJ.addProperty(Json.CREATED_BY, version.getCreatedBy());
|
||||
versionJ.addProperty(Json.CREATED_AT, formatDate(version.getCreatedAt()));
|
||||
versionJ.addProperty(Json.CREATED, formatDate(version.getCreated()));
|
||||
versionJ.addProperty(Json.UPDATED, formatDate(version.getUpdated()));
|
||||
versionJ.addProperty(Json.DELETED, version.isDeleted());
|
||||
rootJ.add(Json.VERSION, versionJ);
|
||||
}
|
||||
|
|
|
@ -191,7 +191,9 @@ public class StrolchElementDeepEqualsVisitor implements StrolchElementVisitor<Li
|
|||
addLocator(srcVersion.getLocator().append(Tags.VERSION));
|
||||
if (!srcVersion.getCreatedBy().equals(dstVersion.getCreatedBy()))
|
||||
addLocator(srcVersion.getLocator().append(Tags.VERSION));
|
||||
if (!srcVersion.getCreatedAt().equals(dstVersion.getCreatedAt()))
|
||||
if (!srcVersion.getCreated().equals(dstVersion.getCreated()))
|
||||
addLocator(srcVersion.getLocator().append(Tags.VERSION));
|
||||
if (!srcVersion.getUpdated().equals(dstVersion.getUpdated()))
|
||||
addLocator(srcVersion.getLocator().append(Tags.VERSION));
|
||||
if (srcVersion.isDeleted() != dstVersion.isDeleted())
|
||||
addLocator(srcVersion.getLocator().append(Tags.VERSION));
|
||||
|
|
|
@ -365,10 +365,24 @@ public class StrolchElementFromDomVisitor {
|
|||
|
||||
int v = Integer.parseInt(versionElem.getAttribute(Tags.VERSION));
|
||||
String createdBy = versionElem.getAttribute(Tags.CREATED_BY);
|
||||
String createdAtS = versionElem.getAttribute(Tags.CREATED_AT);
|
||||
Date createdAt = ISO8601FormatFactory.getInstance().parseDate(createdAtS);
|
||||
|
||||
String createdS;
|
||||
if (versionElem.hasAttribute("CreatedAt"))
|
||||
createdS = versionElem.getAttribute("CreatedAt");
|
||||
else
|
||||
createdS = versionElem.getAttribute(Tags.CREATED);
|
||||
Date created = ISO8601FormatFactory.getInstance().parseDate(createdS);
|
||||
|
||||
Date updated;
|
||||
if (versionElem.hasAttribute(Tags.UPDATED)) {
|
||||
String updatedS = versionElem.getAttribute(Tags.UPDATED);
|
||||
updated = ISO8601FormatFactory.getInstance().parseDate(updatedS);
|
||||
} else {
|
||||
updated = created;
|
||||
}
|
||||
|
||||
boolean deleted = StringHelper.parseBoolean(versionElem.getAttribute(Tags.DELETED));
|
||||
Version version = new Version(rootElement.getLocator(), v, createdBy, createdAt, deleted);
|
||||
Version version = new Version(rootElement.getLocator(), v, createdBy, created, updated, deleted);
|
||||
|
||||
rootElement.setVersion(version);
|
||||
}
|
||||
|
|
|
@ -232,7 +232,8 @@ public class StrolchElementToDomVisitor implements StrolchRootElementVisitor<Doc
|
|||
Element element = document.createElement(Tags.VERSION);
|
||||
element.setAttribute(Tags.VERSION, Integer.toString(version.getVersion()));
|
||||
element.setAttribute(Tags.CREATED_BY, version.getCreatedBy());
|
||||
element.setAttribute(Tags.CREATED_AT, ISO8601FormatFactory.getInstance().formatDate(version.getCreatedAt()));
|
||||
element.setAttribute(Tags.CREATED, ISO8601FormatFactory.getInstance().formatDate(version.getCreated()));
|
||||
element.setAttribute(Tags.UPDATED, ISO8601FormatFactory.getInstance().formatDate(version.getUpdated()));
|
||||
element.setAttribute(Tags.DELETED, Boolean.toString(version.isDeleted()));
|
||||
return element;
|
||||
}
|
||||
|
|
|
@ -270,8 +270,10 @@ public class StrolchElementToSaxVisitor implements StrolchRootElementVisitor<Voi
|
|||
|
||||
attributes.addAttribute(null, null, Tags.VERSION, Tags.CDATA, Integer.toString(version.getVersion()));
|
||||
attributes.addAttribute(null, null, Tags.CREATED_BY, Tags.CDATA, version.getCreatedBy());
|
||||
attributes.addAttribute(null, null, Tags.CREATED_AT, Tags.CDATA,
|
||||
ISO8601FormatFactory.getInstance().formatDate(version.getCreatedAt()));
|
||||
attributes.addAttribute(null, null, Tags.CREATED, Tags.CDATA,
|
||||
ISO8601FormatFactory.getInstance().formatDate(version.getCreated()));
|
||||
attributes.addAttribute(null, null, Tags.UPDATED, Tags.CDATA,
|
||||
ISO8601FormatFactory.getInstance().formatDate(version.getUpdated()));
|
||||
attributes.addAttribute(null, null, Tags.DELETED, Tags.CDATA, Boolean.toString(version.isDeleted()));
|
||||
|
||||
return attributes;
|
||||
|
|
|
@ -176,8 +176,8 @@ public class StrolchElementToSaxWriterVisitor implements StrolchRootElementVisit
|
|||
Version version = rootElement.getVersion();
|
||||
this.writer.writeAttribute(Tags.VERSION, Integer.toString(version.getVersion()));
|
||||
this.writer.writeAttribute(Tags.CREATED_BY, version.getCreatedBy());
|
||||
this.writer
|
||||
.writeAttribute(Tags.CREATED_AT, ISO8601FormatFactory.getInstance().formatDate(version.getCreatedAt()));
|
||||
this.writer.writeAttribute(Tags.CREATED, ISO8601FormatFactory.getInstance().formatDate(version.getCreated()));
|
||||
this.writer.writeAttribute(Tags.UPDATED, ISO8601FormatFactory.getInstance().formatDate(version.getUpdated()));
|
||||
this.writer.writeAttribute(Tags.DELETED, Boolean.toString(version.isDeleted()));
|
||||
}
|
||||
|
||||
|
|
|
@ -265,12 +265,25 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
String versionS = attributes.getValue(Tags.VERSION);
|
||||
int v = Integer.parseInt(versionS);
|
||||
String createdBy = attributes.getValue(Tags.CREATED_BY);
|
||||
String createdAtS = attributes.getValue(Tags.CREATED_AT);
|
||||
Date createdAt = ISO8601FormatFactory.getInstance().parseDate(createdAtS);
|
||||
|
||||
String createdS;
|
||||
createdS = attributes.getValue("CreatedAt");
|
||||
if (createdS == null)
|
||||
createdS = attributes.getValue(Tags.CREATED);
|
||||
Date created = ISO8601FormatFactory.getInstance().parseDate(createdS);
|
||||
|
||||
String updatedS = attributes.getValue(Tags.UPDATED);
|
||||
Date updated;
|
||||
if (updatedS == null)
|
||||
updated = created;
|
||||
else
|
||||
updated = ISO8601FormatFactory.getInstance().parseDate(updatedS);
|
||||
|
||||
String deletedS = attributes.getValue(Tags.DELETED);
|
||||
boolean deleted = StringHelper.parseBoolean(deletedS);
|
||||
|
||||
Version version = new Version(this.parameterizedElement.getLocator(), v, createdBy, createdAt, deleted);
|
||||
Version version = new Version(this.parameterizedElement.getLocator(), v, createdBy, created, updated,
|
||||
deleted);
|
||||
((StrolchRootElement) this.parameterizedElement).setVersion(version);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -41,11 +41,11 @@ public class PostgreSqlActivityDao extends PostgresqlDao<Activity> implements Ac
|
|||
|
||||
public static final String ACTIVITIES = "activities";
|
||||
|
||||
private static final String insertAsXmlSqlS = "insert into {0} (id, version, created_by, created_at, deleted, latest, name, type, state, asxml) values (?, ?, ?, ?, ?, ?, ?, ?, ?::order_state, ?)";
|
||||
private static final String insertAsJsonSqlS = "insert into {0} (id, version, created_by, created_at, deleted, latest, name, type, state, asjson) values (?, ?, ?, ?, ?, ?, ?, ?, ?::order_state, ?)";
|
||||
private static final String insertAsXmlSqlS = "insert into {0} (id, version, created_by, created_at, updated_at, deleted, latest, name, type, state, asxml) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?::order_state, ?)";
|
||||
private static final String insertAsJsonSqlS = "insert into {0} (id, version, created_by, created_at, updated_at, deleted, latest, name, type, state, asjson) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?::order_state, ?)";
|
||||
|
||||
private static final String updateAsXmlSqlS = "update {0} set created_by = ?, created_at = ?, deleted = ?, latest = ?, name = ?, type = ?, state = ?::order_state, asxml = ? where id = ? and version = ?";
|
||||
private static final String updateAsJsonSqlS = "update {0} set created_by = ?, created_at = ?, deleted = ?, latest = ?, name = ?, type = ?, state = ?::order_state, asjson = ? where id = ? and version = ?";
|
||||
private static final String updateAsXmlSqlS = "update {0} set created_by = ?, created_at = ?, updated_at = ?, deleted = ?, latest = ?, name = ?, type = ?, state = ?::order_state, asxml = ? where id = ? and version = ?";
|
||||
private static final String updateAsJsonSqlS = "update {0} set created_by = ?, created_at = ?, updated_at = ?, deleted = ?, latest = ?, name = ?, type = ?, state = ?::order_state, asjson = ? where id = ? and version = ?";
|
||||
|
||||
private static final String updateLatestSqlS = "update {0} SET latest = false WHERE id = ? AND version = ?";
|
||||
|
||||
|
@ -111,18 +111,20 @@ public class PostgreSqlActivityDao extends PostgresqlDao<Activity> implements Ac
|
|||
// version
|
||||
preparedStatement.setInt(2, activity.getVersion().getVersion());
|
||||
preparedStatement.setString(3, activity.getVersion().getCreatedBy());
|
||||
preparedStatement.setTimestamp(4, new Timestamp(activity.getVersion().getCreatedAt().getTime()),
|
||||
preparedStatement.setTimestamp(4, new Timestamp(activity.getVersion().getCreated().getTime()),
|
||||
Calendar.getInstance());
|
||||
preparedStatement.setBoolean(5, activity.getVersion().isDeleted());
|
||||
preparedStatement.setTimestamp(5, new Timestamp(activity.getVersion().getUpdated().getTime()),
|
||||
Calendar.getInstance());
|
||||
preparedStatement.setBoolean(6, activity.getVersion().isDeleted());
|
||||
|
||||
preparedStatement.setBoolean(6, !activity.getVersion().isDeleted());
|
||||
preparedStatement.setBoolean(7, !activity.getVersion().isDeleted());
|
||||
|
||||
// attributes
|
||||
preparedStatement.setString(7, activity.getName());
|
||||
preparedStatement.setString(8, activity.getType());
|
||||
preparedStatement.setString(9, activity.getState().name());
|
||||
preparedStatement.setString(8, activity.getName());
|
||||
preparedStatement.setString(9, activity.getType());
|
||||
preparedStatement.setString(10, activity.getState().name());
|
||||
|
||||
SQLXML sqlxml = writeObject(preparedStatement, activity, 10);
|
||||
SQLXML sqlxml = writeObject(preparedStatement, activity, 11);
|
||||
|
||||
try {
|
||||
int modCount = preparedStatement.executeUpdate();
|
||||
|
@ -204,22 +206,24 @@ public class PostgreSqlActivityDao extends PostgresqlDao<Activity> implements Ac
|
|||
|
||||
// version
|
||||
preparedStatement.setString(1, activity.getVersion().getCreatedBy());
|
||||
preparedStatement.setTimestamp(2, new Timestamp(activity.getVersion().getCreatedAt().getTime()),
|
||||
preparedStatement.setTimestamp(2, new Timestamp(activity.getVersion().getCreated().getTime()),
|
||||
Calendar.getInstance());
|
||||
preparedStatement.setBoolean(3, activity.getVersion().isDeleted());
|
||||
preparedStatement.setTimestamp(3, new Timestamp(activity.getVersion().getUpdated().getTime()),
|
||||
Calendar.getInstance());
|
||||
preparedStatement.setBoolean(4, activity.getVersion().isDeleted());
|
||||
|
||||
preparedStatement.setBoolean(4, !activity.getVersion().isDeleted());
|
||||
preparedStatement.setBoolean(5, !activity.getVersion().isDeleted());
|
||||
|
||||
// attributes
|
||||
preparedStatement.setString(5, activity.getName());
|
||||
preparedStatement.setString(6, activity.getType());
|
||||
preparedStatement.setString(7, activity.getState().name());
|
||||
preparedStatement.setString(6, activity.getName());
|
||||
preparedStatement.setString(7, activity.getType());
|
||||
preparedStatement.setString(8, activity.getState().name());
|
||||
|
||||
SQLXML sqlxml = writeObject(preparedStatement, activity, 8);
|
||||
SQLXML sqlxml = writeObject(preparedStatement, activity, 9);
|
||||
|
||||
// primary key
|
||||
preparedStatement.setString(9, activity.getId());
|
||||
preparedStatement.setInt(10, activity.getVersion().getVersion());
|
||||
preparedStatement.setString(10, activity.getId());
|
||||
preparedStatement.setInt(11, activity.getVersion().getVersion());
|
||||
|
||||
try {
|
||||
int modCount = preparedStatement.executeUpdate();
|
||||
|
|
|
@ -41,11 +41,11 @@ public class PostgreSqlOrderDao extends PostgresqlDao<Order> implements OrderDao
|
|||
|
||||
public static final String ORDERS = "orders";
|
||||
|
||||
private static final String insertAsXmlSqlS = "insert into {0} (id, version, created_by, created_at, deleted, latest, name, type, state, date, asxml) values (?, ?, ?, ?, ?, ?, ?, ?, ?::order_state, ?, ?)";
|
||||
private static final String insertAsJsonSqlS = "insert into {0} (id, version, created_by, created_at, deleted, latest, name, type, state, date, asjson) values (?, ?, ?, ?, ?, ?, ?, ?, ?::order_state, ?, ?)";
|
||||
private static final String insertAsXmlSqlS = "insert into {0} (id, version, created_by, created_at, updated_at, deleted, latest, name, type, state, date, asxml) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?::order_state, ?, ?)";
|
||||
private static final String insertAsJsonSqlS = "insert into {0} (id, version, created_by, created_at, updated_at, deleted, latest, name, type, state, date, asjson) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?::order_state, ?, ?)";
|
||||
|
||||
private static final String updateAsXmlSqlS = "update {0} set created_by = ?, created_at = ?, deleted = ?, latest = ?, name = ?, type = ?, state = ?::order_state, date = ?, asxml = ? where id = ? and version = ?";
|
||||
private static final String updateAsJsonSqlS = "update {0} set created_by = ?, created_at = ?, deleted = ?, latest = ?, name = ?, type = ?, state = ?::order_state, date = ?, asjson = ? where id = ? and version = ?";
|
||||
private static final String updateAsXmlSqlS = "update {0} set created_by = ?, created_at = ?, updated_at = ?, deleted = ?, latest = ?, name = ?, type = ?, state = ?::order_state, date = ?, asxml = ? where id = ? and version = ?";
|
||||
private static final String updateAsJsonSqlS = "update {0} set created_by = ?, created_at = ?, updated_at = ?, deleted = ?, latest = ?, name = ?, type = ?, state = ?::order_state, date = ?, asjson = ? where id = ? and version = ?";
|
||||
|
||||
private static final String updateLatestSqlS = "update {0} SET latest = false WHERE id = ? AND version = ?";
|
||||
|
||||
|
@ -111,19 +111,21 @@ public class PostgreSqlOrderDao extends PostgresqlDao<Order> implements OrderDao
|
|||
// version
|
||||
preparedStatement.setInt(2, order.getVersion().getVersion());
|
||||
preparedStatement.setString(3, order.getVersion().getCreatedBy());
|
||||
preparedStatement.setTimestamp(4, new Timestamp(order.getVersion().getCreatedAt().getTime()),
|
||||
Calendar.getInstance());
|
||||
preparedStatement.setBoolean(5, order.getVersion().isDeleted());
|
||||
preparedStatement
|
||||
.setTimestamp(4, new Timestamp(order.getVersion().getCreated().getTime()), Calendar.getInstance());
|
||||
preparedStatement
|
||||
.setTimestamp(5, new Timestamp(order.getVersion().getUpdated().getTime()), Calendar.getInstance());
|
||||
preparedStatement.setBoolean(6, order.getVersion().isDeleted());
|
||||
|
||||
preparedStatement.setBoolean(6, !order.getVersion().isDeleted());
|
||||
preparedStatement.setBoolean(7, !order.getVersion().isDeleted());
|
||||
|
||||
// attributes
|
||||
preparedStatement.setString(7, order.getName());
|
||||
preparedStatement.setString(8, order.getType());
|
||||
preparedStatement.setString(9, order.getState().name());
|
||||
preparedStatement.setTimestamp(10, new Timestamp(order.getDate().getTime()), Calendar.getInstance());
|
||||
preparedStatement.setString(8, order.getName());
|
||||
preparedStatement.setString(9, order.getType());
|
||||
preparedStatement.setString(10, order.getState().name());
|
||||
preparedStatement.setTimestamp(11, new Timestamp(order.getDate().getTime()), Calendar.getInstance());
|
||||
|
||||
SQLXML sqlxml = writeObject(preparedStatement, order, 11);
|
||||
SQLXML sqlxml = writeObject(preparedStatement, order, 12);
|
||||
|
||||
try {
|
||||
int modCount = preparedStatement.executeUpdate();
|
||||
|
@ -205,23 +207,25 @@ public class PostgreSqlOrderDao extends PostgresqlDao<Order> implements OrderDao
|
|||
|
||||
// version
|
||||
preparedStatement.setString(1, order.getVersion().getCreatedBy());
|
||||
preparedStatement.setTimestamp(2, new Timestamp(order.getVersion().getCreatedAt().getTime()),
|
||||
Calendar.getInstance());
|
||||
preparedStatement.setBoolean(3, order.getVersion().isDeleted());
|
||||
preparedStatement
|
||||
.setTimestamp(2, new Timestamp(order.getVersion().getCreated().getTime()), Calendar.getInstance());
|
||||
preparedStatement
|
||||
.setTimestamp(3, new Timestamp(order.getVersion().getUpdated().getTime()), Calendar.getInstance());
|
||||
preparedStatement.setBoolean(4, order.getVersion().isDeleted());
|
||||
|
||||
preparedStatement.setBoolean(4, !order.getVersion().isDeleted());
|
||||
preparedStatement.setBoolean(5, !order.getVersion().isDeleted());
|
||||
|
||||
// attributes
|
||||
preparedStatement.setString(5, order.getName());
|
||||
preparedStatement.setString(6, order.getType());
|
||||
preparedStatement.setString(7, order.getState().name());
|
||||
preparedStatement.setTimestamp(8, new Timestamp(order.getDate().getTime()), Calendar.getInstance());
|
||||
preparedStatement.setString(6, order.getName());
|
||||
preparedStatement.setString(7, order.getType());
|
||||
preparedStatement.setString(8, order.getState().name());
|
||||
preparedStatement.setTimestamp(9, new Timestamp(order.getDate().getTime()), Calendar.getInstance());
|
||||
|
||||
SQLXML sqlxml = writeObject(preparedStatement, order, 9);
|
||||
SQLXML sqlxml = writeObject(preparedStatement, order, 10);
|
||||
|
||||
// primary key
|
||||
preparedStatement.setString(10, order.getId());
|
||||
preparedStatement.setInt(11, order.getVersion().getVersion());
|
||||
preparedStatement.setString(11, order.getId());
|
||||
preparedStatement.setInt(12, order.getVersion().getVersion());
|
||||
|
||||
try {
|
||||
int modCount = preparedStatement.executeUpdate();
|
||||
|
|
|
@ -41,11 +41,11 @@ public class PostgreSqlResourceDao extends PostgresqlDao<Resource> implements Re
|
|||
|
||||
public static final String RESOURCES = "resources";
|
||||
|
||||
private static final String insertAsXmlSqlS = "insert into {0} (id, version, created_by, created_at, deleted, latest, name, type, asxml) values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String insertAsJsonSqlS = "insert into {0} (id, version, created_by, created_at, deleted, latest, name, type, asjson) values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String insertAsXmlSqlS = "insert into {0} (id, version, created_by, updated_at, created_at, deleted, latest, name, type, asxml) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String insertAsJsonSqlS = "insert into {0} (id, version, created_by, updated_at, created_at, deleted, latest, name, type, asjson) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
private static final String updateAsXmlSqlS = "update {0} set created_by = ?, created_at = ?, deleted = ?, latest = ?, name = ?, type = ?, asxml = ? where id = ? and version = ?";
|
||||
private static final String updateAsJsonSqlS = "update {0} set created_by = ?, created_at = ?, deleted = ?, latest = ?, name = ?, type = ?, asjson = ? where id = ? and version = ?";
|
||||
private static final String updateAsXmlSqlS = "update {0} set created_by = ?, created_at = ?, updated_at = ?, deleted = ?, latest = ?, name = ?, type = ?, asxml = ? where id = ? and version = ?";
|
||||
private static final String updateAsJsonSqlS = "update {0} set created_by = ?, created_at = ?, updated_at = ?, deleted = ?, latest = ?, name = ?, type = ?, asjson = ? where id = ? and version = ?";
|
||||
|
||||
private static final String updateLatestSqlS = "update {0} SET latest = false WHERE id = ? AND version = ?";
|
||||
|
||||
|
@ -111,17 +111,19 @@ public class PostgreSqlResourceDao extends PostgresqlDao<Resource> implements Re
|
|||
// version
|
||||
preparedStatement.setInt(2, resource.getVersion().getVersion());
|
||||
preparedStatement.setString(3, resource.getVersion().getCreatedBy());
|
||||
preparedStatement.setTimestamp(4, new Timestamp(resource.getVersion().getCreatedAt().getTime()),
|
||||
preparedStatement.setTimestamp(4, new Timestamp(resource.getVersion().getCreated().getTime()),
|
||||
Calendar.getInstance());
|
||||
preparedStatement.setBoolean(5, resource.getVersion().isDeleted());
|
||||
preparedStatement.setTimestamp(5, new Timestamp(resource.getVersion().getUpdated().getTime()),
|
||||
Calendar.getInstance());
|
||||
preparedStatement.setBoolean(6, resource.getVersion().isDeleted());
|
||||
|
||||
preparedStatement.setBoolean(6, !resource.getVersion().isDeleted());
|
||||
preparedStatement.setBoolean(7, !resource.getVersion().isDeleted());
|
||||
|
||||
// attributes
|
||||
preparedStatement.setString(7, resource.getName());
|
||||
preparedStatement.setString(8, resource.getType());
|
||||
preparedStatement.setString(8, resource.getName());
|
||||
preparedStatement.setString(9, resource.getType());
|
||||
|
||||
SQLXML sqlxml = writeObject(preparedStatement, resource, 9);
|
||||
SQLXML sqlxml = writeObject(preparedStatement, resource, 10);
|
||||
|
||||
try {
|
||||
int modCount = preparedStatement.executeUpdate();
|
||||
|
@ -204,21 +206,23 @@ public class PostgreSqlResourceDao extends PostgresqlDao<Resource> implements Re
|
|||
|
||||
// version
|
||||
preparedStatement.setString(1, resource.getVersion().getCreatedBy());
|
||||
preparedStatement.setTimestamp(2, new Timestamp(resource.getVersion().getCreatedAt().getTime()),
|
||||
preparedStatement.setTimestamp(2, new Timestamp(resource.getVersion().getCreated().getTime()),
|
||||
Calendar.getInstance());
|
||||
preparedStatement.setBoolean(3, resource.getVersion().isDeleted());
|
||||
preparedStatement.setTimestamp(3, new Timestamp(resource.getVersion().getUpdated().getTime()),
|
||||
Calendar.getInstance());
|
||||
preparedStatement.setBoolean(4, resource.getVersion().isDeleted());
|
||||
|
||||
preparedStatement.setBoolean(4, !resource.getVersion().isDeleted());
|
||||
preparedStatement.setBoolean(5, !resource.getVersion().isDeleted());
|
||||
|
||||
// attributes
|
||||
preparedStatement.setString(5, resource.getName());
|
||||
preparedStatement.setString(6, resource.getType());
|
||||
preparedStatement.setString(6, resource.getName());
|
||||
preparedStatement.setString(7, resource.getType());
|
||||
|
||||
SQLXML sqlxml = writeObject(preparedStatement, resource, 7);
|
||||
SQLXML sqlxml = writeObject(preparedStatement, resource, 8);
|
||||
|
||||
// primary key
|
||||
preparedStatement.setString(8, resource.getId());
|
||||
preparedStatement.setInt(9, resource.getVersion().getVersion());
|
||||
preparedStatement.setString(9, resource.getId());
|
||||
preparedStatement.setInt(10, resource.getVersion().getVersion());
|
||||
|
||||
try {
|
||||
int modCount = preparedStatement.executeUpdate();
|
||||
|
|
|
@ -49,14 +49,14 @@ public abstract class PostgresqlDao<T extends StrolchRootElement> implements Str
|
|||
private static final String deleteAllSqlS = "delete from {0}";
|
||||
private static final String deleteAllByTypeSqlS = "delete from {0} where type = ?";
|
||||
|
||||
private static final String queryByVersionAsXmlSqlS = "select id, name, type, version, created_by, created_at, deleted, asxml from {0} where type = ? and id = ? and version = ?";
|
||||
private static final String queryByVersionAsJsonSqlS = "select id, name, type, version, created_by, created_at, deleted, asjson from {0} where type = ? and id = ? and version = ?";
|
||||
private static final String queryVersionsAsXmlForSqlS = "select id, name, type, version, created_by, created_at, deleted, asxml from {0} where type = ? and id = ? order by version";
|
||||
private static final String queryVersionsAsJsonForSqlS = "select id, name, type, version, created_by, created_at, deleted, asjson from {0} where type = ? and id = ? order by version";
|
||||
private static final String queryAllAsXmlSqlS = "select id, name, type, version, created_by, created_at, deleted, asxml from {0} where latest = true";
|
||||
private static final String queryAllAsJsonSqlS = "select id, name, type, version, created_by, created_at, deleted, asjson from {0} where latest = true";
|
||||
private static final String queryAllByTypeAsXmlSqlS = "select id, name, type, version, created_by, created_at, deleted, asxml from {0} where type = ? and latest = true";
|
||||
private static final String queryAllByTypeAsJsonSqlS = "select id, name, type, version, created_by, created_at, deleted, asjson from {0} where type = ? and latest = true";
|
||||
private static final String queryByVersionAsXmlSqlS = "select id, name, type, version, created_by, created_at, updated_at, deleted, asxml from {0} where type = ? and id = ? and version = ?";
|
||||
private static final String queryByVersionAsJsonSqlS = "select id, name, type, version, created_by, created_at, updated_at, deleted, asjson from {0} where type = ? and id = ? and version = ?";
|
||||
private static final String queryVersionsAsXmlForSqlS = "select id, name, type, version, created_by, created_at, updated_at, deleted, asxml from {0} where type = ? and id = ? order by version";
|
||||
private static final String queryVersionsAsJsonForSqlS = "select id, name, type, version, created_by, created_at, updated_at, deleted, asjson from {0} where type = ? and id = ? order by version";
|
||||
private static final String queryAllAsXmlSqlS = "select id, name, type, version, created_by, created_at, updated_at, deleted, asxml from {0} where latest = true";
|
||||
private static final String queryAllAsJsonSqlS = "select id, name, type, version, created_by, created_at, updated_at, deleted, asjson from {0} where latest = true";
|
||||
private static final String queryAllByTypeAsXmlSqlS = "select id, name, type, version, created_by, created_at, updated_at, deleted, asxml from {0} where type = ? and latest = true";
|
||||
private static final String queryAllByTypeAsJsonSqlS = "select id, name, type, version, created_by, created_at, updated_at, deleted, asjson from {0} where type = ? and latest = true";
|
||||
|
||||
protected final DataType dataType;
|
||||
protected Connection connection;
|
||||
|
@ -209,8 +209,9 @@ public abstract class PostgresqlDao<T extends StrolchRootElement> implements Str
|
|||
"Requested version " + versionNr + " != " + v + " for " + t.getLocator());
|
||||
String createdBy = result.getString(5);
|
||||
java.util.Date createdAt = new java.util.Date(result.getDate(6).getTime());
|
||||
boolean deleted = result.getBoolean(7);
|
||||
Version version = new Version(t.getLocator(), v, createdBy, createdAt, deleted);
|
||||
java.util.Date updatedAt = new java.util.Date(result.getDate(7).getTime());
|
||||
boolean deleted = result.getBoolean(8);
|
||||
Version version = new Version(t.getLocator(), v, createdBy, createdAt, updatedAt, deleted);
|
||||
t.setVersion(version);
|
||||
|
||||
if (result.next())
|
||||
|
@ -250,8 +251,9 @@ public abstract class PostgresqlDao<T extends StrolchRootElement> implements Str
|
|||
int v = result.getInt(4);
|
||||
String createdBy = result.getString(5);
|
||||
java.util.Date createdAt = new java.util.Date(result.getDate(6).getTime());
|
||||
boolean deleted = result.getBoolean(7);
|
||||
Version version = new Version(t.getLocator(), v, createdBy, createdAt, deleted);
|
||||
java.util.Date updatedAt = new java.util.Date(result.getDate(7).getTime());
|
||||
boolean deleted = result.getBoolean(8);
|
||||
Version version = new Version(t.getLocator(), v, createdBy, createdAt, updatedAt, deleted);
|
||||
t.setVersion(version);
|
||||
|
||||
list.add(t);
|
||||
|
@ -334,8 +336,9 @@ public abstract class PostgresqlDao<T extends StrolchRootElement> implements Str
|
|||
int v = result.getInt(4);
|
||||
String createdBy = result.getString(5);
|
||||
java.util.Date createdAt = new java.util.Date(result.getDate(6).getTime());
|
||||
boolean deleted = result.getBoolean(7);
|
||||
Version version = new Version(t.getLocator(), v, createdBy, createdAt, deleted);
|
||||
java.util.Date updatedAt = new java.util.Date(result.getDate(7).getTime());
|
||||
boolean deleted = result.getBoolean(8);
|
||||
Version version = new Version(t.getLocator(), v, createdBy, createdAt, updatedAt, deleted);
|
||||
t.setVersion(version);
|
||||
|
||||
list.add(t);
|
||||
|
@ -375,8 +378,9 @@ public abstract class PostgresqlDao<T extends StrolchRootElement> implements Str
|
|||
int v = result.getInt(4);
|
||||
String createdBy = result.getString(5);
|
||||
java.util.Date createdAt = new java.util.Date(result.getDate(6).getTime());
|
||||
boolean deleted = result.getBoolean(7);
|
||||
Version version = new Version(t.getLocator(), v, createdBy, createdAt, deleted);
|
||||
java.util.Date updatedAt = new java.util.Date(result.getDate(7).getTime());
|
||||
boolean deleted = result.getBoolean(8);
|
||||
Version version = new Version(t.getLocator(), v, createdBy, createdAt, updatedAt, deleted);
|
||||
t.setVersion(version);
|
||||
|
||||
list.add(t);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
DROP TABLE IF EXISTS resources;
|
||||
DROP TABLE IF EXISTS orders;
|
||||
DROP TABLE IF EXISTS activities;
|
||||
|
||||
DROP TABLE IF EXISTS audits;
|
||||
|
||||
DROP TABLE IF EXISTS operations_log;
|
||||
DROP TABLE IF EXISTS operations_log_values;
|
||||
|
||||
DROP TABLE IF EXISTS db_version;
|
||||
|
||||
DROP TYPE IF EXISTS order_state;
|
||||
DROP TYPE IF EXISTS access_type;
|
||||
DROP TYPE IF EXISTS log_severity_type;
|
|
@ -0,0 +1,196 @@
|
|||
|
||||
-- DB_VERSION
|
||||
CREATE TABLE IF NOT EXISTS db_version (
|
||||
id serial primary key not null,
|
||||
app varchar(255) not null,
|
||||
version varchar(255) not null,
|
||||
description varchar(255) not null,
|
||||
created timestamp with time zone not null
|
||||
);
|
||||
|
||||
-- RESOURCES
|
||||
CREATE TABLE IF NOT EXISTS resources (
|
||||
id varchar(255) not null,
|
||||
version integer not null,
|
||||
created_by varchar(255) not null,
|
||||
created_at timestamp with time zone not null,
|
||||
updated_at timestamp with time zone not null,
|
||||
deleted boolean not null,
|
||||
latest boolean not null,
|
||||
name varchar(255) not null,
|
||||
type varchar(255) not null,
|
||||
asxml xml,
|
||||
asjson json,
|
||||
|
||||
PRIMARY KEY (id, version)
|
||||
);
|
||||
|
||||
-- ORDERS
|
||||
CREATE TYPE order_state AS ENUM ('CREATED', 'PLANNING', 'PLANNED', 'EXECUTION', 'STOPPED', 'WARNING', 'ERROR', 'EXECUTED', 'CLOSED');
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS orders (
|
||||
id varchar(255) not null,
|
||||
version integer not null,
|
||||
created_by varchar(255) not null,
|
||||
created_at timestamp with time zone not null,
|
||||
updated_at timestamp with time zone not null,
|
||||
deleted boolean,
|
||||
latest boolean not null,
|
||||
name varchar(255),
|
||||
type varchar(255),
|
||||
state order_state,
|
||||
date timestamp with time zone,
|
||||
asxml xml,
|
||||
asjson json,
|
||||
|
||||
PRIMARY KEY (id, version)
|
||||
);
|
||||
|
||||
-- ACTIVITIES
|
||||
CREATE TABLE IF NOT EXISTS activities (
|
||||
id varchar(255) not null,
|
||||
version integer not null,
|
||||
created_by varchar(255) not null,
|
||||
created_at timestamp with time zone not null,
|
||||
updated_at timestamp with time zone not null,
|
||||
deleted boolean not null,
|
||||
latest boolean not null,
|
||||
name varchar(255) not null,
|
||||
type varchar(255) not null,
|
||||
state order_state,
|
||||
asxml xml,
|
||||
asjson json,
|
||||
|
||||
PRIMARY KEY (id, version)
|
||||
);
|
||||
|
||||
-- AUDITS
|
||||
CREATE TYPE access_type AS ENUM ('READ', 'CREATE', 'UPDATE', 'DELETE');
|
||||
CREATE TABLE IF NOT EXISTS audits (
|
||||
id bigint PRIMARY KEY,
|
||||
username varchar(255) NOT NULL,
|
||||
firstname varchar(255) NOT NULL,
|
||||
lastname varchar(255) NOT NULL,
|
||||
date timestamp with time zone NOT NULL,
|
||||
|
||||
element_type varchar(255) NOT NULL,
|
||||
element_sub_type varchar(255) NOT NULL,
|
||||
element_accessed varchar(255) NOT NULL,
|
||||
new_version timestamp with time zone,
|
||||
|
||||
action varchar(255) NOT NULL,
|
||||
access_type access_type NOT NULL
|
||||
);
|
||||
|
||||
-- Operations Log
|
||||
CREATE TYPE log_severity_type AS ENUM ('Info', 'Notification', 'Warning', 'Error', 'Exception');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS operations_log (
|
||||
id varchar(255) PRIMARY KEY,
|
||||
realm varchar(255),
|
||||
dateTime timestamp with time zone,
|
||||
username varchar(255),
|
||||
severity log_severity_type,
|
||||
locator varchar(1024),
|
||||
key varchar(255),
|
||||
message text,
|
||||
stacktrace text
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS operations_log_values (
|
||||
id varchar(255),
|
||||
key varchar(255),
|
||||
value text
|
||||
);
|
||||
|
||||
-- set version
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.1.0',
|
||||
'strolch',
|
||||
'Initial schema version',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.2.0',
|
||||
'strolch',
|
||||
'Added new table for audits',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.2.1',
|
||||
'strolch',
|
||||
'Added new column app to table table version',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.3.0',
|
||||
'strolch',
|
||||
'Added new column element_sub_type to table audits',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.4.0',
|
||||
'strolch',
|
||||
'Added new table activities',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.5.0',
|
||||
'strolch',
|
||||
'Added versioning to root elements',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.5.1',
|
||||
'strolch',
|
||||
'Added state column to activity, and added new states',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.6.0',
|
||||
'strolch',
|
||||
'Added json column to all tables',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.7.0',
|
||||
'strolch',
|
||||
'Added persisting of operations log',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.8.0',
|
||||
'strolch',
|
||||
'Added updated_at column to all tables',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
-- add version columns
|
||||
ALTER TABLE resources ADD COLUMN updated_at timestamp with time zone;
|
||||
ALTER TABLE orders ADD COLUMN updated_at timestamp with time zone;
|
||||
ALTER TABLE activities ADD COLUMN updated_at timestamp with time zone;
|
||||
|
||||
-- set initial values for new columns
|
||||
UPDATE resources SET updated_at = CURRENT_TIMESTAMP where updated_at IS NULL;
|
||||
UPDATE orders SET updated_at = CURRENT_TIMESTAMP where updated_at IS NULL;
|
||||
UPDATE activities SET updated_at = CURRENT_TIMESTAMP where updated_at IS NULL;
|
||||
|
||||
-- make columns not null
|
||||
ALTER TABLE resources ALTER COLUMN updated_at SET NOT NULL;
|
||||
ALTER TABLE orders ALTER COLUMN updated_at SET NOT NULL;
|
||||
ALTER TABLE activities ALTER COLUMN updated_at SET NOT NULL;
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.8.0',
|
||||
'strolch',
|
||||
'Added updated_at column to all tables',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
|
@ -1,2 +1,2 @@
|
|||
# Property file defining what the currently expected version is supposed to be
|
||||
db_version=0.7.0
|
||||
db_version=0.8.0
|
||||
|
|
Loading…
Reference in New Issue