Merge pull request #967 from spotify/freben/store-more-meta

Store and retrieve etag and generation
This commit is contained in:
Fredrik Adelöw
2020-05-23 20:44:05 +02:00
committed by GitHub
3 changed files with 24 additions and 5 deletions
@@ -36,8 +36,9 @@ function serializeMetadata(
}
const output = { ...metadata };
// TODO: delete output.uid;
// TODO: delete output.generation;
delete output.uid;
delete output.etag;
delete output.generation;
return JSON.stringify(output);
}
@@ -56,6 +57,8 @@ function entityRequestToDb(request: DbEntityRequest): DbEntitiesRow {
return {
id: '',
location_id: request.locationId || null,
etag: new Buffer(uuidv4()).toString('base64').replace(/[^\w]/g, ''), // TODO(freben): Atomicity isn't checked using these yet
generation: 1, // TODO(freben): These aren't updated yet
api_version: request.entity.apiVersion,
kind: request.entity.kind,
name: request.entity.metadata?.name || null,
@@ -70,8 +73,9 @@ function entityDbToResponse(row: DbEntitiesRow): DbEntityResponse {
apiVersion: row.api_version,
kind: row.kind,
metadata: {
// TODO: uid: row.id,
// TODO: generation: row.generation,
uid: row.id,
etag: row.etag,
generation: row.generation,
},
};
@@ -121,7 +125,7 @@ export class Database {
async entities(): Promise<DbEntityResponse[]> {
const items = await this.database<DbEntitiesRow>('entities')
.orderBy('name')
.orderBy('namespace', 'name')
.select();
return items.map(entityDbToResponse);
}
@@ -45,6 +45,19 @@ export async function up(knex: Knex): Promise<any> {
.inTable('locations')
.nullable()
.comment('The location that originated the entity');
table
.string('etag')
.notNullable()
.comment(
'An opaque string that changes for each update operation to any part of the entity, including metadata.',
);
table
.string('generation')
.notNullable()
.unsigned()
.comment(
'A positive nonzero number that indicates the current generation of data for this entity; the value is incremented each time the spec changes.',
);
table
.string('api_version')
.notNullable()
@@ -24,6 +24,8 @@ export type DbEntitiesRow = {
kind: string;
name: string | null;
namespace: string | null;
etag: string;
generation: number;
metadata: string | null;
spec: string | null;
};