Add Timestamp column to refs table
Change-Id: I6a6ca62527108998968b3a7b7e563fd9c1d9db78
diff --git a/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/DatabaseSchemaCreator.java b/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/DatabaseSchemaCreator.java
index 2990a1b..0bf042e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/DatabaseSchemaCreator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/DatabaseSchemaCreator.java
@@ -60,7 +60,9 @@
+ "token TIMESTAMP OPTIONS (allow_commit_timestamp = true),"
+ "owner STRING(MAX) NOT NULL"
+ ")"
- + "PRIMARY KEY (project, ref)"),
+ + "PRIMARY KEY (project, ref)",
+ "ALTER TABLE refs ADD COLUMN IF NOT EXISTS "
+ + "time TIMESTAMP OPTIONS (allow_commit_timestamp=true)"),
null)
.get();
} catch (Exception e) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/SpannerRefDatabase.java b/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/SpannerRefDatabase.java
index d291831..e8ad5b2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/SpannerRefDatabase.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/SpannerRefDatabase.java
@@ -25,6 +25,7 @@
import com.google.cloud.spanner.ResultSet;
import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.Struct;
+import com.google.cloud.spanner.Value;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.entities.Project;
@@ -133,6 +134,8 @@
if (row == null || row.getString(0).equals(expectedValue)) {
transaction.buffer(
Mutation.newInsertOrUpdateBuilder("refs")
+ .set("time")
+ .to(Value.COMMIT_TIMESTAMP)
.set("project")
.to(project.get())
.set("ref")