We will start with this schema
CREATE TABLE [dbo].[Label]
(
[Id] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY,
[Prefix] VARCHAR(50) NOT NULL UNIQUE,
[ArtistName] VARCHAR(MAX) NOT NULL
)
We also have a microservice that manages "Labels". http://labels.example.com/v1/all will return all labels in this format:
{ Id = xxx, Prefix = xxx, ArtistName = xxx }
How do we handle a schema change that does not affect consumers of this microservice?
We have to do some refactoring and the artist moves to his own table.
CREATE TABLE [dbo].[Label]
(
[Id] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY,
[Prefix] VARCHAR(50) NOT NULL UNIQUE,
[ArtistId] UNIQUEIDENTIFIER NOT NULL,
CONSTRAINT FK_Label_Artist
FOREIGN KEY (ArtistId) REFERENCES Artist(Id)
)
CREATE TABLE [dbo].[Artist]
(
[Id] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY,
[Name] VARCHAR(MAX) NOT NULL,
[Country] VARCHAR(MAX) NOT NULL
)
Our microservice will need to return the following object
{ Id = xxx, Prefix = xxx, Artist = { Id = xxx, Name = xxx, Country = xxx } }
We will have to create a v2 api call that returns this new structure. We will also have to migrate the data to the new structure. This means v1 needs a change as well to support the new schema, but it will still return the same object.
Is this the way things are done when you version a microservice? Things to keep in mind? Is there a different way to do this?