Component versioning using a dedicated table and static data with Visual Studio
Published 20 August 2019
The following example takes the online approach to handling static data.
Create a SQL Change Automation project
Add a new version table containing static data (see below for example SQL)
CREATE TABLE [dbo].[component_versions]( [component] [NVARCHAR](64) NOT NULL, [version] [INT] NOT NULL, CONSTRAINT [PK_component_versions] PRIMARY KEY CLUSTERED ( [component] ASC ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[component_versions] WITH CHECK ADD CONSTRAINT [CK_component] CHECK (([component]<>'')) GO ALTER TABLE [dbo].[component_versions] CHECK CONSTRAINT [CK_component] GO ALTER TABLE [dbo].[component_versions] WITH CHECK ADD CONSTRAINT [CK_version] CHECK (([version]>(0))) GO ALTER TABLE [dbo].[component_versions] CHECK CONSTRAINT [CK_version] GO UPDATE [dbo].[component_versions] SET version = 1 WHERE component = N'customers' GO UPDATE [dbo].[component_versions] SET version = 1 WHERE component = N'regions' GO
- Refresh SQL Change Automation, select the table, and click Import and generate script
- Click Refresh and then right-click on an object and click Include Table Data to include static data for the table
- Click Refresh again, and then Import and generate script to create a migration script containing the static data. It might look like this:
Now everything is set.
When the corresponding database objects next need to change, a new component version will be needed.
Update the record in the database and import a new migration script. It will contain the following logic or equivalent:
UPDATE component_versions SET version = 3 WHERE component = M'customers'