Skip to content

Commit

Permalink
Expose coreMigrationVersion saved object field to consumers
Browse files Browse the repository at this point in the history
Consumers can now see this field when retrieving existing objects,
and they can set it when creating new objects.
  • Loading branch information
jportner committed Jan 15, 2021
1 parent c486690 commit 24a90b3
Show file tree
Hide file tree
Showing 35 changed files with 326 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObject](./kibana-plugin-core-public.savedobject.md) &gt; [coreMigrationVersion](./kibana-plugin-core-public.savedobject.coremigrationversion.md)

## SavedObject.coreMigrationVersion property

A semver value that is used when upgrading objects between Kibana versions.

<b>Signature:</b>

```typescript
coreMigrationVersion?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface SavedObject<T = unknown>
| Property | Type | Description |
| --- | --- | --- |
| [attributes](./kibana-plugin-core-public.savedobject.attributes.md) | <code>T</code> | The data for a Saved Object is stored as an object in the <code>attributes</code> property. |
| [coreMigrationVersion](./kibana-plugin-core-public.savedobject.coremigrationversion.md) | <code>string</code> | A semver value that is used when upgrading objects between Kibana versions. |
| [error](./kibana-plugin-core-public.savedobject.error.md) | <code>SavedObjectError</code> | |
| [id](./kibana-plugin-core-public.savedobject.id.md) | <code>string</code> | The ID of this Saved Object, guaranteed to be unique for all objects of the same <code>type</code> |
| [migrationVersion](./kibana-plugin-core-public.savedobject.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsCreateOptions](./kibana-plugin-core-public.savedobjectscreateoptions.md) &gt; [coreMigrationVersion](./kibana-plugin-core-public.savedobjectscreateoptions.coremigrationversion.md)

## SavedObjectsCreateOptions.coreMigrationVersion property

A semver value that is used when upgrading objects between Kibana versions.

<b>Signature:</b>

```typescript
coreMigrationVersion?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface SavedObjectsCreateOptions

| Property | Type | Description |
| --- | --- | --- |
| [coreMigrationVersion](./kibana-plugin-core-public.savedobjectscreateoptions.coremigrationversion.md) | <code>string</code> | A semver value that is used when upgrading objects between Kibana versions. |
| [id](./kibana-plugin-core-public.savedobjectscreateoptions.id.md) | <code>string</code> | (Not recommended) Specify an id instead of having the saved objects service generate one for you. |
| [migrationVersion](./kibana-plugin-core-public.savedobjectscreateoptions.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
| [overwrite](./kibana-plugin-core-public.savedobjectscreateoptions.overwrite.md) | <code>boolean</code> | If a document with the given <code>id</code> already exists, overwrite it's contents (default=false). |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Constructs a new instance of the `SimpleSavedObject` class
<b>Signature:</b>

```typescript
constructor(client: SavedObjectsClientContract, { id, type, version, attributes, error, references, migrationVersion }: SavedObjectType<T>);
constructor(client: SavedObjectsClientContract, { id, type, version, attributes, error, references, migrationVersion, coreMigrationVersion, }: SavedObjectType<T>);
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| client | <code>SavedObjectsClientContract</code> | |
| { id, type, version, attributes, error, references, migrationVersion } | <code>SavedObjectType&lt;T&gt;</code> | |
| { id, type, version, attributes, error, references, migrationVersion, coreMigrationVersion, } | <code>SavedObjectType&lt;T&gt;</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SimpleSavedObject](./kibana-plugin-core-public.simplesavedobject.md) &gt; [coreMigrationVersion](./kibana-plugin-core-public.simplesavedobject.coremigrationversion.md)

## SimpleSavedObject.coreMigrationVersion property

<b>Signature:</b>

```typescript
coreMigrationVersion: SavedObjectType<T>['coreMigrationVersion'];
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ export declare class SimpleSavedObject<T = unknown>

| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(client, { id, type, version, attributes, error, references, migrationVersion })](./kibana-plugin-core-public.simplesavedobject._constructor_.md) | | Constructs a new instance of the <code>SimpleSavedObject</code> class |
| [(constructor)(client, { id, type, version, attributes, error, references, migrationVersion, coreMigrationVersion, })](./kibana-plugin-core-public.simplesavedobject._constructor_.md) | | Constructs a new instance of the <code>SimpleSavedObject</code> class |

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [\_version](./kibana-plugin-core-public.simplesavedobject._version.md) | | <code>SavedObjectType&lt;T&gt;['version']</code> | |
| [attributes](./kibana-plugin-core-public.simplesavedobject.attributes.md) | | <code>T</code> | |
| [coreMigrationVersion](./kibana-plugin-core-public.simplesavedobject.coremigrationversion.md) | | <code>SavedObjectType&lt;T&gt;['coreMigrationVersion']</code> | |
| [error](./kibana-plugin-core-public.simplesavedobject.error.md) | | <code>SavedObjectType&lt;T&gt;['error']</code> | |
| [id](./kibana-plugin-core-public.simplesavedobject.id.md) | | <code>SavedObjectType&lt;T&gt;['id']</code> | |
| [migrationVersion](./kibana-plugin-core-public.simplesavedobject.migrationversion.md) | | <code>SavedObjectType&lt;T&gt;['migrationVersion']</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObject](./kibana-plugin-core-server.savedobject.md) &gt; [coreMigrationVersion](./kibana-plugin-core-server.savedobject.coremigrationversion.md)

## SavedObject.coreMigrationVersion property

A semver value that is used when upgrading objects between Kibana versions.

<b>Signature:</b>

```typescript
coreMigrationVersion?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface SavedObject<T = unknown>
| Property | Type | Description |
| --- | --- | --- |
| [attributes](./kibana-plugin-core-server.savedobject.attributes.md) | <code>T</code> | The data for a Saved Object is stored as an object in the <code>attributes</code> property. |
| [coreMigrationVersion](./kibana-plugin-core-server.savedobject.coremigrationversion.md) | <code>string</code> | A semver value that is used when upgrading objects between Kibana versions. |
| [error](./kibana-plugin-core-server.savedobject.error.md) | <code>SavedObjectError</code> | |
| [id](./kibana-plugin-core-server.savedobject.id.md) | <code>string</code> | The ID of this Saved Object, guaranteed to be unique for all objects of the same <code>type</code> |
| [migrationVersion](./kibana-plugin-core-server.savedobject.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsBulkCreateObject](./kibana-plugin-core-server.savedobjectsbulkcreateobject.md) &gt; [coreMigrationVersion](./kibana-plugin-core-server.savedobjectsbulkcreateobject.coremigrationversion.md)

## SavedObjectsBulkCreateObject.coreMigrationVersion property

A semver value that is used when upgrading objects between Kibana versions. If undefined, this will be automatically set to the current Kibana version when the object is created. If this is set to a non-semver value, or it is set to a semver value greater than the current Kibana version, it will result in an error.

<b>Signature:</b>

```typescript
coreMigrationVersion?: string;
```

## Remarks

Do not attempt to set this manually. It should only be used if you retrieved an existing object that had the `coreMigrationVersion` field set and you want to create it again.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface SavedObjectsBulkCreateObject<T = unknown>
| Property | Type | Description |
| --- | --- | --- |
| [attributes](./kibana-plugin-core-server.savedobjectsbulkcreateobject.attributes.md) | <code>T</code> | |
| [coreMigrationVersion](./kibana-plugin-core-server.savedobjectsbulkcreateobject.coremigrationversion.md) | <code>string</code> | A semver value that is used when upgrading objects between Kibana versions. If undefined, this will be automatically set to the current Kibana version when the object is created. If this is set to a non-semver value, or it is set to a semver value greater than the current Kibana version, it will result in an error. |
| [id](./kibana-plugin-core-server.savedobjectsbulkcreateobject.id.md) | <code>string</code> | |
| [initialNamespaces](./kibana-plugin-core-server.savedobjectsbulkcreateobject.initialnamespaces.md) | <code>string[]</code> | Optional initial namespaces for the object to be created in. If this is defined, it will supersede the namespace ID that is in [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md)<!-- -->.<!-- -->Note: this can only be used for multi-namespace object types. |
| [migrationVersion](./kibana-plugin-core-server.savedobjectsbulkcreateobject.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md) &gt; [coreMigrationVersion](./kibana-plugin-core-server.savedobjectscreateoptions.coremigrationversion.md)

## SavedObjectsCreateOptions.coreMigrationVersion property

A semver value that is used when upgrading objects between Kibana versions. If undefined, this will be automatically set to the current Kibana version when the object is created. If this is set to a non-semver value, or it is set to a semver value greater than the current Kibana version, it will result in an error.

<b>Signature:</b>

```typescript
coreMigrationVersion?: string;
```

## Remarks

Do not attempt to set this manually. It should only be used if you retrieved an existing object that had the `coreMigrationVersion` field set and you want to create it again.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions
| Property | Type | Description |
| --- | --- | --- |
| [coreMigrationVersion](./kibana-plugin-core-server.savedobjectscreateoptions.coremigrationversion.md) | <code>string</code> | A semver value that is used when upgrading objects between Kibana versions. If undefined, this will be automatically set to the current Kibana version when the object is created. If this is set to a non-semver value, or it is set to a semver value greater than the current Kibana version, it will result in an error. |
| [id](./kibana-plugin-core-server.savedobjectscreateoptions.id.md) | <code>string</code> | (not recommended) Specify an id for the document |
| [initialNamespaces](./kibana-plugin-core-server.savedobjectscreateoptions.initialnamespaces.md) | <code>string[]</code> | Optional initial namespaces for the object to be created in. If this is defined, it will supersede the namespace ID that is in [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md)<!-- -->.<!-- -->Note: this can only be used for multi-namespace object types. |
| [migrationVersion](./kibana-plugin-core-server.savedobjectscreateoptions.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
Expand Down
6 changes: 5 additions & 1 deletion src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ export type PublicUiSettingsParams = Omit<UiSettingsParams, 'schema'>;
// @public (undocumented)
export interface SavedObject<T = unknown> {
attributes: T;
coreMigrationVersion?: string;
// (undocumented)
error?: SavedObjectError;
id: string;
Expand Down Expand Up @@ -1197,6 +1198,7 @@ export type SavedObjectsClientContract = PublicMethodsOf<SavedObjectsClient>;

// @public (undocumented)
export interface SavedObjectsCreateOptions {
coreMigrationVersion?: string;
id?: string;
migrationVersion?: SavedObjectsMigrationVersion;
overwrite?: boolean;
Expand Down Expand Up @@ -1409,10 +1411,12 @@ export class ScopedHistory<HistoryLocationState = unknown> implements History<Hi

// @public
export class SimpleSavedObject<T = unknown> {
constructor(client: SavedObjectsClientContract, { id, type, version, attributes, error, references, migrationVersion }: SavedObject<T>);
constructor(client: SavedObjectsClientContract, { id, type, version, attributes, error, references, migrationVersion, coreMigrationVersion, }: SavedObject<T>);
// (undocumented)
attributes: T;
// (undocumented)
coreMigrationVersion: SavedObject<T>['coreMigrationVersion'];
// (undocumented)
delete(): Promise<{}>;
// (undocumented)
error: SavedObject<T>['error'];
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/saved_objects/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface SavedObjectsCreateOptions {
overwrite?: boolean;
/** {@inheritDoc SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
/** A semver value that is used when upgrading objects between Kibana versions. */
coreMigrationVersion?: string;
references?: SavedObjectReference[];
}

Expand Down
14 changes: 13 additions & 1 deletion src/core/public/saved_objects/simple_saved_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,30 @@ export class SimpleSavedObject<T = unknown> {
public id: SavedObjectType<T>['id'];
public type: SavedObjectType<T>['type'];
public migrationVersion: SavedObjectType<T>['migrationVersion'];
public coreMigrationVersion: SavedObjectType<T>['coreMigrationVersion'];
public error: SavedObjectType<T>['error'];
public references: SavedObjectType<T>['references'];

constructor(
private client: SavedObjectsClientContract,
{ id, type, version, attributes, error, references, migrationVersion }: SavedObjectType<T>
{
id,
type,
version,
attributes,
error,
references,
migrationVersion,
coreMigrationVersion,
}: SavedObjectType<T>
) {
this.id = id;
this.type = type;
this.attributes = attributes || ({} as T);
this.references = references || [];
this._version = version;
this.migrationVersion = migrationVersion;
this.coreMigrationVersion = coreMigrationVersion;
if (error) {
this.error = error;
}
Expand All @@ -77,6 +88,7 @@ export class SimpleSavedObject<T = unknown> {
} else {
return this.client.create(this.type, this.attributes, {
migrationVersion: this.migrationVersion,
coreMigrationVersion: this.coreMigrationVersion,
references: this.references,
});
}
Expand Down
1 change: 1 addition & 0 deletions src/core/server/saved_objects/routes/bulk_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const registerBulkCreateRoute = (router: IRouter, { coreUsageData }: Rout
attributes: schema.recordOf(schema.string(), schema.any()),
version: schema.maybe(schema.string()),
migrationVersion: schema.maybe(schema.recordOf(schema.string(), schema.string())),
coreMigrationVersion: schema.maybe(schema.string()),
references: schema.maybe(
schema.arrayOf(
schema.object({
Expand Down
18 changes: 16 additions & 2 deletions src/core/server/saved_objects/routes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const registerCreateRoute = (router: IRouter, { coreUsageData }: RouteDep
body: schema.object({
attributes: schema.recordOf(schema.string(), schema.any()),
migrationVersion: schema.maybe(schema.recordOf(schema.string(), schema.string())),
coreMigrationVersion: schema.maybe(schema.string()),
references: schema.maybe(
schema.arrayOf(
schema.object({
Expand All @@ -56,12 +57,25 @@ export const registerCreateRoute = (router: IRouter, { coreUsageData }: RouteDep
router.handleLegacyErrors(async (context, req, res) => {
const { type, id } = req.params;
const { overwrite } = req.query;
const { attributes, migrationVersion, references, initialNamespaces } = req.body;
const {
attributes,
migrationVersion,
coreMigrationVersion,
references,
initialNamespaces,
} = req.body;

const usageStatsClient = coreUsageData.getClient();
usageStatsClient.incrementSavedObjectsCreate({ request: req }).catch(() => {});

const options = { id, overwrite, migrationVersion, references, initialNamespaces };
const options = {
id,
overwrite,
migrationVersion,
coreMigrationVersion,
references,
initialNamespaces,
};
const result = await context.core.savedObjects.client.create(type, attributes, options);
return res.ok({ body: result });
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { includedFields } from './included_fields';

const BASE_FIELD_COUNT = 9;
const BASE_FIELD_COUNT = 10;

describe('includedFields', () => {
it('returns undefined if fields are not provided', () => {
Expand All @@ -43,6 +43,7 @@ Array [
"type",
"references",
"migrationVersion",
"coreMigrationVersion",
"updated_at",
"originId",
"foo",
Expand Down Expand Up @@ -77,6 +78,7 @@ Array [
"type",
"references",
"migrationVersion",
"coreMigrationVersion",
"updated_at",
"originId",
"foo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function includedFields(type: string | string[] = '*', fields?: string[]
.concat('type')
.concat('references')
.concat('migrationVersion')
.concat('coreMigrationVersion')
.concat('updated_at')
.concat('originId')
.concat(fields); // v5 compatibility
Expand Down
Loading

0 comments on commit 24a90b3

Please sign in to comment.