/* Applies recommended primary keys, foreign keys and indexes to core Umbraco Forms tables. This replicates for SQL Server the migration AddRecordKeysAndIndexes. */-- Adds relationship between UFRecords and UFRecordFields.ALTERTABLE dbo.UFRecordFieldsADDCONSTRAINT FK_UFRecordFields_UFRecords_Record FOREIGN KEY ( Record ) REFERENCES dbo.UFRecords ( Id ) ONUPDATENOACTIONON DELETENOACTIONGO-- Adds primary keys to UFRecordData* tables.ALTERTABLE dbo.UFRecordDataBitADDCONSTRAINT PK_UFRecordDataBit PRIMARY KEYCLUSTERED ( Id ) WITH( STATISTICS_NORECOMPUTE=OFF, IGNORE_DUP_KEY=OFF, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON [PRIMARY]GOALTERTABLE dbo.UFRecordDataDateTimeADDCONSTRAINT PK_UFRecordDataDateTime PRIMARY KEYCLUSTERED ( Id ) WITH( STATISTICS_NORECOMPUTE=OFF, IGNORE_DUP_KEY=OFF, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON [PRIMARY]GOALTERTABLE dbo.UFRecordDataIntegerADDCONSTRAINT PK_UFRecordDataInteger PRIMARY KEYCLUSTERED ( Id ) WITH( STATISTICS_NORECOMPUTE=OFF, IGNORE_DUP_KEY=OFF, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON [PRIMARY]GOALTERTABLE dbo.UFRecordDataLongStringADDCONSTRAINT PK_UFRecordDataLongString PRIMARY KEYCLUSTERED ( Id ) WITH( STATISTICS_NORECOMPUTE=OFF, IGNORE_DUP_KEY=OFF, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON [PRIMARY]GO-- Adds relationship between UFRecordFields and UFREcordData* tables.ALTERTABLE dbo.UFRecordDataBitADDCONSTRAINT FK_UFRecordDataBit_UFRecordFields_Key FOREIGN KEY ( [Key] ) REFERENCES dbo.UFRecordFields ( [Key] ) ONUPDATENOACTIONON DELETENOACTIONGOALTERTABLE dbo.UFRecordDataDateTimeADDCONSTRAINT FK_UFRecordDataDateTime_UFRecordFields_Key FOREIGN KEY ( [Key] ) REFERENCES dbo.UFRecordFields ( [Key] ) ONUPDATENOACTIONON DELETENOACTIONGOALTERTABLE dbo.UFRecordDataIntegerADDCONSTRAINT FK_UFRecordDataInteger_UFRecordFields_Key FOREIGN KEY ( [Key] ) REFERENCES dbo.UFRecordFields ( [Key] ) ONUPDATENOACTIONON DELETENOACTIONGOALTERTABLE dbo.UFRecordDataLongStringADDCONSTRAINT FK_UFRecordDataLongString_UFRecordFields_Key FOREIGN KEY ( [Key] ) REFERENCES dbo.UFRecordFields ( [Key] ) ONUPDATENOACTIONON DELETENOACTIONGO-- Adds index on foreign key fields in UFREcordData* tables.CREATENONCLUSTEREDINDEX IX_UFRecordDataBit_Key ON dbo.UFRecordDataBit( [Key] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GOCREATENONCLUSTEREDINDEX IX_UFRecordDataDateTime_Key ON dbo.UFRecordDataDateTime( [Key] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GOCREATENONCLUSTEREDINDEX IX_UFRecordDataInteger_Key ON dbo.UFRecordDataInteger( [Key] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GOCREATENONCLUSTEREDINDEX IX_UFRecordDataLongString_Key ON dbo.UFRecordDataLongString( [Key] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO-- Adds primary key to UFUserSecurity.ALTERTABLE dbo.UFUserSecurityADDCONSTRAINT PK_UFUserSecurity PRIMARY KEYCLUSTERED ( [User] ) WITH( STATISTICS_NORECOMPUTE=OFF, IGNORE_DUP_KEY=OFF, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON [PRIMARY]GO-- Adds primary key to UFUserFormSecurity.ALTERTABLE dbo.UFUserFormSecurityADDCONSTRAINT PK_UFUserFormSecurity PRIMARY KEYCLUSTERED ( Id ) WITH( STATISTICS_NORECOMPUTE=OFF, IGNORE_DUP_KEY=OFF, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON [PRIMARY]GO-- Adds unique constraint to UFUserFormSecurity across user/form fields.ALTERTABLE dbo.UFUserFormSecurityADDCONSTRAINT UK_UFUserFormSecurity_User_Form UNIQUENONCLUSTERED( [User] ASC, [Form] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/* Reverts application of recommended primary keys, foreign keys and indexes to core Umbraco Forms tables. This reverts for SQL Server the migration AddRecordKeysAndIndexes and can be used for rolling that back in testing. */-- Reverts addition of relationship between UFRecords and UFRecordFields.ALTERTABLE dbo.UFRecordFieldsDROPCONSTRAINTIFEXISTS FK_UFRecordFields_UFRecords_RecordGO-- Reverts addition of primary keys to UFRecordData* tables.ALTERTABLE dbo.UFRecordDataBitDROPCONSTRAINTIFEXISTS PK_UFRecordDataBitGOALTERTABLE dbo.UFRecordDataDateTimeDROPCONSTRAINTIFEXISTS PK_UFRecordDataDateTimeGOALTERTABLE dbo.UFRecordDataIntegerDROPCONSTRAINTIFEXISTS PK_UFRecordDataIntegerGOALTERTABLE dbo.UFRecordDataLongStringDROPCONSTRAINTIFEXISTS PK_UFRecordDataLongStringGO-- Reverts addition of relationship between UFRecordFields and UFREcordData* tables.ALTERTABLE dbo.UFRecordDataBitDROPCONSTRAINTIFEXISTS FK_UFRecordDataBit_UFRecordFields_KeyGOALTERTABLE dbo.UFRecordDataDateTimeDROPCONSTRAINTIFEXISTS FK_UFRecordDataDateTime_UFRecordFields_KeyGOALTERTABLE dbo.UFRecordDataIntegerDROPCONSTRAINTIFEXISTS FK_UFRecordDataInteger_UFRecordFields_KeyGOALTERTABLE dbo.UFRecordDataLongStringDROPCONSTRAINTIFEXISTS FK_UFRecordDataLongString_UFRecordFields_KeyGO-- Reverts addition of index on foreign key fields in UFREcordData* tables.DROPINDEXIFEXISTS IX_UFRecordDataBit_Key ON dbo.UFRecordDataBitGODROPINDEXIFEXISTS IX_UFRecordDataDateTime_Key ON dbo.UFRecordDataDateTimeGODROPINDEXIFEXISTS IX_UFRecordDataInteger_Key ON dbo.UFRecordDataIntegerGODROPINDEXIFEXISTS IX_UFRecordDataLongString_Key ON dbo.UFRecordDataLongStringGO-- Reverts addition of primary key to UFUserSecurityALTERTABLE dbo.UFUserSecurityDROPCONSTRAINTIFEXISTS PK_UFUserSecurityGO-- Reverts addition of primary key to UFUserFormSecurityALTERTABLE dbo.UFUserFormSecurityDROPCONSTRAINTIFEXISTS PK_UFUserFormSecurityGO-- Reverts addition of unique constraint to UFUserFormSecurity across user/form fields.ALTERTABLE dbo.UFUserFormSecurityDROPCONSTRAINTIFEXISTS UK_UFUserFormSecurity_User_FormGO