silverstripe / silverstripe-mssql

Microsoft SQL Server module for SilverStripe CMS. Allows SilverStripe to connect to, and use SQL Server as a database.
http://silverstripe.org/microsoft-sql-server-database/
BSD 3-Clause "New" or "Revised" License
15 stars 25 forks source link

Table columns with default values (i.e. ClassName) are not properly created after dev/build #56

Open bilekt3 opened 5 years ago

bilekt3 commented 5 years ago

On our current project where we trying to upgrade SS3 to SS4 with this library we have realized that some tables are not created correctly (usually missing default values for ClassName etc.), we are able to fix almost everything by manual changes of database structure, but after dev/build task all changes are replaced.

System: PHP7.2, IIS, SQL SErver Express (2012)

Sample table structure with incorrect table structure:

create table ChangeSetItem
(
    ID            int identity
        constraint PK__ChangeSe__3214EC27AF81A266
            primary key,
    ClassName     varchar(36)                      not null,
    LastEdited    datetime,
    Created       datetime,
    VersionBefore int         default 0            not null,
    VersionAfter  int         default 0            not null,
    Added         varchar(10) default 'implicitly' not null
        constraint ChangeSetItem_Added_check
            check ([Added] = 'implicitly' OR [Added] = 'explicitly'),
    ChangeSetID   int         default 0            not null,
    ObjectID      int         default 0            not null,
    ObjectClass   varchar(40) default 'SearchTag'  not null
)
go
t3hn0 commented 3 years ago

I encountered same problem - ClassName constraint didn't update after it was created initially.

Server: PHP 7.2., IIS, MS SQL 2019 Installation:

I found error or should I say incomplete regex in MSSQLSchemaManager which wasn't able to read constraint definition if they contained symbol "\" in it. ClassName contains namespaces which contain a lot of backslashes :)

I added PR #61 which adds support to backslashes, and now it works fine.