Skip to content
Jaxelr edited this page Dec 18, 2016 · 1 revision

Tricky Upgrades

Insight can handle most types of schema upgrades automatically, particularly throughout the development cycle of a project. There are a few situations where it needs some help.

Updating Tables

Insight.Database.Schema 2.0 now supports column-level database changes. So adding/dropping/changing a column or constraint should work automatically.

If you want to rename a column, with v2.2.4 and later, you can use the WAS syntax:

CREATE TABLE MyTable (
    [ID] [int],
    [RenamedColumn] [int] NOT NULL, -- [RenamedColumn] WAS [OldColumnName]
)

When Insight detects that RenamedColumn is not there, and OldColumnName is, it will execute a rename on the column. (Note that it will still rebuild any constraints on the column, because it thinks it has changed.)

If you renamed a column multiple times, you can list multiple old versions and Insight will pick the appropriate one. (Yes, it's possible for you to make a mess of things with this if you go crazy).

CREATE TABLE MyTable (
    [ID] [int],
    [RenamedColumn] [int] NOT NULL,
    -- [RenamedColumn] WAS [OldColumnName1]
    -- [RenamedColumn] WAS [OldColumnName2]
)